Skip to content

Commit 460c222

Browse files
committed
Add Reset button to mastermap dialog.
1 parent 6475733 commit 460c222

File tree

10 files changed

+126
-95
lines changed

10 files changed

+126
-95
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/actions/ShowEnrichmentMapDialogAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.baderlab.csplugins.enrichmentmap.view.mastermap.MasterMapDialogParameters;
88
import org.baderlab.csplugins.enrichmentmap.view.util.CardDialog;
99
import org.cytoscape.application.swing.CySwingApplication;
10-
import org.cytoscape.util.swing.IconManager;
1110

1211
import com.google.inject.Inject;
1312
import com.google.inject.Provider;
@@ -16,7 +15,6 @@
1615
public class ShowEnrichmentMapDialogAction extends AbstractAction {
1716

1817
@Inject private Provider<MasterMapDialogParameters> dialogParametersProvider;
19-
@Inject private IconManager iconManager;
2018
@Inject private CySwingApplication application;
2119

2220
private CardDialog masterMapDialog;
@@ -29,7 +27,7 @@ public ShowEnrichmentMapDialogAction() {
2927
public void actionPerformed(ActionEvent e) {
3028
if (masterMapDialog == null) {
3129
MasterMapDialogParameters params = dialogParametersProvider.get();
32-
masterMapDialog = new CardDialog(application.getJFrame(), iconManager, params);
30+
masterMapDialog = new CardDialog(application.getJFrame(), params);
3331
}
3432

3533
masterMapDialog.open();

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/mastermap/CombinedConstantSlider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
public class CombinedConstantSlider extends JPanel {
1111

1212
private JSlider slider;
13+
private final int defaultValue;
1314

1415
public CombinedConstantSlider(int defaultValue) {
1516
if(defaultValue < 0)
1617
defaultValue = 0;
1718
if(defaultValue > 100)
1819
defaultValue = 100;
20+
this.defaultValue = defaultValue;
1921

2022
JLabel jaccardLabel = new JLabel(mkLabel("Jaccard", 100-defaultValue));
2123
JLabel overlapLabel = new JLabel(mkLabel("Overlap", defaultValue));
@@ -46,6 +48,9 @@ public int getValue() {
4648
return slider.getValue();
4749
}
4850

51+
public void reset() {
52+
slider.setValue(defaultValue);
53+
}
4954

5055
private static String mkLabel(String name, int percent) {
5156
return name + " (" + percent + "%)";

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/mastermap/CutoffPropertiesPanel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void createContents() {
114114
);
115115
}
116116

117+
117118
private JPanel createFilterNodesPanel() {
118119
JPanel panel = new JPanel();
119120
panel.setBorder(LookAndFeelUtil.createTitledBorder("Gene-Set Filtering (Nodes)"));
@@ -294,6 +295,24 @@ private JPanel createFilterEdgesPanel() {
294295
}
295296

296297

298+
public void reset() {
299+
pvalueText.setValue(propertyManager.getDefaultPvalue());
300+
qvalueText.setValue(propertyManager.getDefaultQvalue());
301+
nesFilterCombo.setSelectedItem(ComboItem.of(NESFilter.ALL));
302+
shouldFilterMinCheckbox.setSelected(false);
303+
minExperimentsText.setValue(3);
304+
minExperimentsLabel.setEnabled(false);
305+
minExperimentsText.setEnabled(false);
306+
307+
cutoffValues = new EnumMap<>(SimilarityMetric.class);
308+
cutoffValues.put(SimilarityMetric.JACCARD, propertyManager.getDefaultCutOff(SimilarityMetric.JACCARD));
309+
cutoffValues.put(SimilarityMetric.OVERLAP, propertyManager.getDefaultCutOff(SimilarityMetric.OVERLAP));
310+
cutoffValues.put(SimilarityMetric.COMBINED, propertyManager.getDefaultCutOff(SimilarityMetric.COMBINED));
311+
cutoffMetricCombo.setSelectedItem(ComboItem.of(SimilarityMetric.JACCARD));
312+
combinedConstantSlider.reset();
313+
}
314+
315+
297316
private void showAdvancedOptions(boolean show) {
298317
pvalueLabel.setVisible(show);
299318
pvalueText.setVisible(show);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/mastermap/EditCommonPanel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,10 @@ public String getGmtFile() {
104104
public String getExpressionFile() {
105105
return expressionsText.getText();
106106
}
107+
108+
public void reset() {
109+
gmtText.setText("");
110+
expressionsText.setText("");
111+
}
107112

108113
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/mastermap/MasterDetailDialogPage.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.swing.JCheckBox;
2222
import javax.swing.JLabel;
2323
import javax.swing.JList;
24+
import javax.swing.JOptionPane;
2425
import javax.swing.JPanel;
2526
import javax.swing.JScrollPane;
2627
import javax.swing.ListCellRenderer;
@@ -236,9 +237,9 @@ private JPanel createTitlePanel() {
236237
JLabel label = new JLabel("Data Sets:");
237238
SwingUtil.makeSmall(label);
238239

239-
JButton addButton = SwingUtil.createIconButton(iconManager, IconManager.ICON_PLUS, "Add Data Set");
240+
JButton addButton = SwingUtil.createIconButton(iconManager, IconManager.ICON_PLUS, "Add Data Set");
240241
scanButton = SwingUtil.createIconButton(iconManager, IconManager.ICON_FOLDER_O, "Scan Folder for Data Sets");
241-
deleteButton = SwingUtil.createIconButton(iconManager, IconManager.ICON_TRASH_O, "Delete Data Set");
242+
deleteButton = SwingUtil.createIconButton(iconManager, IconManager.ICON_TRASH_O, "Delete Data Set");
242243

243244
addButton.addActionListener(e -> addNewDataSetToList());
244245
deleteButton.addActionListener(e -> deleteSelectedItems());
@@ -307,6 +308,30 @@ private void updateButtonEnablement() {
307308
}
308309

309310

311+
@Override
312+
public void extraButtonClicked(String actionCommand) {
313+
if(MasterMapDialogParameters.RESET_BUTTON_ACTION_COMMAND.equals(actionCommand)) {
314+
reset();
315+
}
316+
}
317+
318+
private void reset() {
319+
int result = JOptionPane.showConfirmDialog(callback.getDialogFrame(),
320+
"Clear inputs and restore default values?", "EnrichmentMap: Reset", JOptionPane.OK_CANCEL_OPTION);
321+
if(result == JOptionPane.OK_OPTION) {
322+
distinctEdgesCheckbox.setSelected(false);
323+
cutoffPanel.reset();
324+
commonPanel.reset();
325+
for(DataSetListItem item : dataSetListModel.toList()) {
326+
if(item != commonParams) {
327+
dataSetListModel.removeElement(item);
328+
dataSetDetailPanel.remove(item.getDetailPanel().getPanel());
329+
}
330+
}
331+
callback.setFinishButtonEnabled(false);
332+
}
333+
}
334+
310335
private void scan() {
311336
Optional<File> rootFolder = FileBrowser.browseForRootFolder(callback.getDialogFrame());
312337
if(rootFolder.isPresent()) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/mastermap/MasterMapDialogParameters.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import java.util.Arrays;
77
import java.util.List;
88

9+
import javax.swing.AbstractButton;
910
import javax.swing.Icon;
1011
import javax.swing.ImageIcon;
12+
import javax.swing.JButton;
1113

1214
import org.baderlab.csplugins.enrichmentmap.view.AboutDialog;
1315
import org.baderlab.csplugins.enrichmentmap.view.util.CardDialogPage;
@@ -18,8 +20,11 @@
1820

1921
public class MasterMapDialogParameters implements CardDialogParameters {
2022

23+
static final String RESET_BUTTON_ACTION_COMMAND = "reset";
24+
2125
@Inject private Provider<MasterDetailDialogPage> masterDetailDialogPage;
2226

27+
2328
@Override
2429
public List<CardDialogPage> getPages() {
2530
return Arrays.asList(
@@ -54,4 +59,11 @@ public Icon getIcon() {
5459
Image scaled = original.getImage().getScaledInstance(80, 49, Image.SCALE_SMOOTH);
5560
return new ImageIcon(scaled);
5661
}
62+
63+
@Override
64+
public AbstractButton[] getAdditionalButtons() {
65+
JButton resetButton = new JButton("Reset");
66+
resetButton.setActionCommand(RESET_BUTTON_ACTION_COMMAND);
67+
return new JButton[] { resetButton };
68+
}
5769
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/CardDialog.java

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import java.awt.BorderLayout;
77
import java.awt.CardLayout;
8-
import java.awt.Color;
9-
import java.awt.FlowLayout;
8+
import java.awt.event.ActionEvent;
109
import java.util.List;
1110

11+
import javax.swing.AbstractAction;
12+
import javax.swing.AbstractButton;
1213
import javax.swing.BorderFactory;
1314
import javax.swing.GroupLayout;
1415
import javax.swing.GroupLayout.Alignment;
@@ -18,14 +19,13 @@
1819
import javax.swing.JFrame;
1920
import javax.swing.JLabel;
2021
import javax.swing.JPanel;
22+
import javax.swing.UIManager;
23+
import javax.swing.border.Border;
2124

22-
import org.baderlab.csplugins.enrichmentmap.view.util.CardDialogCallback.Message;
23-
import org.cytoscape.util.swing.IconManager;
2425
import org.cytoscape.util.swing.LookAndFeelUtil;
2526

2627
public class CardDialog {
2728

28-
private JPanel message;
2929
private JDialog dialog;
3030

3131
private JComboBox<ComboItem<CardDialogPage>> pageChooserCombo;
@@ -34,17 +34,13 @@ public class CardDialog {
3434
private JButton finishButton;
3535

3636
private final CardDialogParameters params;
37-
private final IconManager iconManager;
3837

3938

40-
public CardDialog(JFrame parent, IconManager iconManager, CardDialogParameters params) {
41-
if (iconManager == null)
42-
throw new IllegalArgumentException("'iconManager' must not be null.");
39+
public CardDialog(JFrame parent, CardDialogParameters params) {
4340
if (params == null)
4441
throw new IllegalArgumentException("'params' must not be null.");
4542

4643
this.params = params;
47-
this.iconManager = iconManager;
4844

4945
dialog = new JDialog(parent);
5046
createComponents();
@@ -66,12 +62,14 @@ private void createComponents() {
6662
dialog.setPreferredSize(params.getPreferredSize());
6763
dialog.setTitle(params.getTitle());
6864

69-
// Create message and button panel first because
70-
// the controller can call callbacks from inside createBodyPanel()
71-
JPanel buttonPanel = createButtonPanel();
72-
JPanel bodyPanel = createBodyPanel();
65+
// Create message and button panel first because the controller can call callbacks from inside createBodyPanel()
66+
JPanel buttonPanel = createButtonPanel();
67+
JPanel bodyPanel = createBodyPanel();
7368

74-
buttonPanel .setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
69+
Border padding = BorderFactory.createEmptyBorder(5,5,5,5);
70+
Border separator = BorderFactory.createMatteBorder(1,0,0,0,UIManager.getColor("Separator.foreground"));
71+
Border border = BorderFactory.createCompoundBorder(separator, padding);
72+
buttonPanel.setBorder(border);
7573

7674
dialog.add(bodyPanel, BorderLayout.CENTER);
7775
dialog.add(buttonPanel, BorderLayout.SOUTH);
@@ -162,74 +160,37 @@ private JPanel createChooserPanel(List<CardDialogPage> pages) {
162160
return panel;
163161
}
164162

165-
166-
private JPanel createMessage(Message severity, String message) {
167-
JPanel panel = new JPanel(new BorderLayout());
168-
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
169-
JLabel icon = getMessageIcon(severity);
170-
JLabel messageLabel = new JLabel(message + " ");
171-
panel.add(icon, BorderLayout.WEST);
172-
panel.add(messageLabel, BorderLayout.CENTER);
173-
panel.setOpaque(false);
174-
return panel;
175-
}
176-
177-
private JLabel getMessageIcon(Message severity) {
178-
JLabel icon = new JLabel();
179-
switch(severity) {
180-
default:
181-
case INFO:
182-
icon.setText("");
183-
break;
184-
case WARN:
185-
icon.setText(IconManager.ICON_EXCLAMATION_CIRCLE);
186-
icon.setForeground(Color.YELLOW.darker());
187-
break;
188-
case ERROR:
189-
icon.setText(IconManager.ICON_TIMES_CIRCLE);
190-
icon.setForeground(Color.RED.darker());
191-
break;
192-
}
193-
194-
icon.setFont(iconManager.getIconFont(16));
195-
icon.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
196-
icon.setOpaque(false);
197-
return icon;
198-
}
199-
163+
@SuppressWarnings("serial")
200164
private JPanel createButtonPanel() {
201-
JPanel panel = new JPanel(new BorderLayout());
202-
203-
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
204-
205-
JButton cancelButton = new JButton("Cancel");
206-
buttonPanel.add(cancelButton);
207-
cancelButton.addActionListener(e -> dialog.setVisible(false));
208-
209-
finishButton = new JButton(params.getFinishButtonText());
210-
buttonPanel.add(finishButton);
211-
finishButton.addActionListener(e -> currentPage.finish());
212-
213-
message = new JPanel(new BorderLayout());
214-
message.setOpaque(false);
215-
216-
panel.add(buttonPanel, BorderLayout.EAST);
217-
panel.add(message, BorderLayout.WEST);
165+
finishButton = new JButton(new AbstractAction(params.getFinishButtonText()) {
166+
public void actionPerformed(ActionEvent e) {
167+
currentPage.finish();
168+
}
169+
});
170+
JButton cancelButton = new JButton(new AbstractAction("Cancel") {
171+
public void actionPerformed(ActionEvent e) {
172+
dialog.setVisible(false);
173+
}
174+
});
175+
176+
AbstractButton[] additional = params.getAdditionalButtons();
177+
if(additional != null) {
178+
for(AbstractButton button : additional) {
179+
button.addActionListener(e -> {
180+
currentPage.extraButtonClicked(e.getActionCommand());
181+
});
182+
}
183+
}
218184

219-
return panel;
185+
JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(finishButton, cancelButton, additional);
186+
LookAndFeelUtil.setDefaultOkCancelKeyStrokes(dialog.getRootPane(), finishButton.getAction(), cancelButton.getAction());
187+
dialog.getRootPane().setDefaultButton(finishButton);
188+
return buttonPanel;
220189
}
221190

222191

223192
public class Callback implements CardDialogCallback {
224193

225-
@Override
226-
public void setMessage(Message severity, String text) {
227-
JPanel messageContent = createMessage(severity, text);
228-
message.removeAll();
229-
message.add(messageContent, BorderLayout.CENTER);
230-
dialog.revalidate();
231-
}
232-
233194
@Override
234195
public void setFinishButtonEnabled(boolean enabled) {
235196
finishButton.setEnabled(enabled);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/CardDialogCallback.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@
44

55
public interface CardDialogCallback {
66

7-
public static enum Message {
8-
INFO, WARN, ERROR
9-
}
10-
11-
void setMessage(Message severity, String message);
12-
13-
default void clearMessage() {
14-
setMessage(Message.INFO, "");
15-
}
16-
17-
default void setMessage(String message) {
18-
setMessage(Message.INFO, message);
19-
}
20-
217
void setFinishButtonEnabled(boolean enabled);
228

239
JDialog getDialogFrame();

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/CardDialogPage.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.baderlab.csplugins.enrichmentmap.view.util;
22

3+
import javax.swing.AbstractButton;
34
import javax.swing.JPanel;
45

56
public interface CardDialogPage {
@@ -16,4 +17,11 @@ default String getPageComboText() {
1617

1718
void finish();
1819

20+
/**
21+
* Called when one of the buttons returned by
22+
* {@link CardDialogParameters#getAdditionalButtons()} is clicked.
23+
*
24+
* @see AbstractButton#setActionCommand(String)
25+
*/
26+
default void extraButtonClicked(String actionCommand) { }
1927
}

0 commit comments

Comments
 (0)