Skip to content

Commit

Permalink
Allow disabling clear selected file action in JFileChooserPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
hlfernandez committed Aug 16, 2018
1 parent d3ff90d commit 2b186b4
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GC4S [![Build Status](https://travis-ci.org/sing-group/GC4S.svg?branch=master)](https://travis-ci.org/hlfernandez/GC4S) [![license](https://img.shields.io/badge/LICENSE-LGPLv3-blue.svg)]()
GC4S [![Build Status](https://travis-ci.org/sing-group/GC4S.svg?branch=master)](https://travis-ci.org/hlfernandez/GC4S) [![license](https://img.shields.io/badge/LICENSE-LGPLv3-blue.svg)]() [![GitHub release](https://img.shields.io/github/release/sing-group/GC4S.svg)](https://github.com/sing-group/GC4S/releases)
========================

GC4S is an open-source library that provides a bioinformatics-oriented collection of GUI Components for (Java) Swing.
Expand Down Expand Up @@ -38,7 +38,7 @@ Add the following repository and dependency declarations to your `pom.xml` in or
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-genomebrowser-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-genomebrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-genomebrowser</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-genomebrowser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-heatmap-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-heatmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-heatmap</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-heatmap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-jsparklines-factory-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-jsparklines-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-jsparklines-factory</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-jsparklines-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-multiple-sequence-alignment-viewer-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-multiple-sequence-alignment-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-multiple-sequence-alignment-viewer</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-multiple-sequence-alignment-viewer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-statistics-tests-table-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s-statistics-tests-table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-statistics-tests-table</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s-statistics-tests-table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gc4s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add the following repository and dependency declarations to your `pom.xml`:
<dependency>
<groupId>org.sing_group</groupId>
<artifactId>gc4s</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion gc4s/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.sing_group.gc4s.event.DocumentAdapter;
import org.sing_group.gc4s.input.filechooser.event.FileChooserListener;
import org.sing_group.gc4s.ui.icons.Icons;
import org.sing_group.gc4s.ui.menu.JPopupMenuActionsVisibility;
import org.sing_group.gc4s.utilities.FileDrop;
import org.sing_group.gc4s.utilities.FileDropListener;
import org.sing_group.gc4s.utilities.builder.JButtonBuilder;
Expand Down Expand Up @@ -92,6 +93,7 @@ public class JFileChooserPanel extends JPanel {
private JFileChooser filechooser;
private Mode mode;
private AbstractAction browseAction;
private AbstractAction clearSelectionAction;
private JButton btnBrowse;
private JLabel lblFile;
private String lblFileText;
Expand Down Expand Up @@ -339,22 +341,26 @@ public void actionPerformed(ActionEvent e) {

private JPopupMenu getPopupMenu() {
if (this.popupMenu == null) {
this.popupMenu = new JPopupMenu();
this.popupMenu = new JPopupMenuActionsVisibility();
this.popupMenu.add(getClearSelectionAction());
}

return this.popupMenu;
}

private Action getClearSelectionAction() {
return new AbstractAction("Clear selected file", DEFAULT_ICON_CLEAR) {
private static final long serialVersionUID = 1L;
if (this.clearSelectionAction == null) {
this.clearSelectionAction = new AbstractAction(
"Clear selected file", DEFAULT_ICON_CLEAR) {
private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
clearSelectedFile();
}
};
}

@Override
public void actionPerformed(ActionEvent e) {
clearSelectedFile();
}
};
return this.clearSelectionAction;
}

private void fileNameUpdated() {
Expand Down Expand Up @@ -555,6 +561,17 @@ public File getSelectedFile() {
public void setUseSharedLastFileFilter(boolean use) {
this.useSharedLastFileFilter = use;
}

/**
* Establishes whether the clear selected file action should be enabled or
* not.
*
* @param enabled whether the clear selected file action should be enabled
* or not.
*/
public void setClearSelectedFileActionEnabled(boolean enabled) {
this.getClearSelectionAction().setEnabled(enabled);
}

/**
* Clears the last file filter shared with other instances.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* #%L
* GC4S components
* %%
* Copyright (C) 2014 - 2018 Hugo López-Fernández, Daniel Glez-Peña, Miguel Reboiro-Jato,
* Florentino Fdez-Riverola, Rosalía Laza-Fidalgo, Reyes Pavón-Rial
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
package org.sing_group.gc4s.ui.menu;

import java.util.stream.Stream;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

/**
* This component extends {@code JPopupMenu} so that it only becomes visible if
* there is at least one {@code JMenuItem} enabled. Otherwise, it will not
* become visible.
*
* @author hlfernandez
*
*/
public class JPopupMenuActionsVisibility extends JPopupMenu {
private static final long serialVersionUID = 1L;

@Override
public void setVisible(boolean b) {
if(b) {
b = Stream.of(this.getComponents())
.filter(c -> c instanceof JMenuItem)
.filter(c -> {
return ((JMenuItem) c).isEnabled();
}).findAny().isPresent();
}
super.setVisible(b);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.sing_group</groupId>
<artifactId>gc4s-all</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<name>GC4S</name>
<description>GUI Components for Java Swing.</description>
Expand Down

0 comments on commit 2b186b4

Please sign in to comment.