Skip to content

Commit 70031a0

Browse files
committed
Fix cutoff field rounding in PA dialog.
Refs #491
1 parent 53a116a commit 70031a0

File tree

1 file changed

+30
-16
lines changed
  • EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/postanalysis

1 file changed

+30
-16
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/postanalysis/PAWeightPanel.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import javax.swing.JTextField;
3636
import javax.swing.LayoutStyle.ComponentPlacement;
3737
import javax.swing.SwingUtilities;
38+
import javax.swing.event.DocumentEvent;
39+
import javax.swing.event.DocumentListener;
3840

3941
import org.baderlab.csplugins.enrichmentmap.AfterInjection;
4042
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
@@ -44,6 +46,7 @@
4446
import org.baderlab.csplugins.enrichmentmap.model.UniverseType;
4547
import org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterMetric;
4648
import org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterMetricSet;
49+
import org.baderlab.csplugins.enrichmentmap.util.CoalesceTimer;
4750
import org.baderlab.csplugins.enrichmentmap.view.EnablementComboBoxRenderer;
4851
import org.baderlab.csplugins.enrichmentmap.view.util.GBCFactory;
4952
import org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil;
@@ -77,7 +80,7 @@ public class PAWeightPanel extends JPanel {
7780

7881
private JComboBox<String> datasetCombo;
7982
private JComboBox<PostAnalysisFilterType> rankTestCombo;
80-
private JFormattedTextField rankTestTextField;
83+
private JTextField rankTestTextField;
8184

8285
private JRadioButton gmtRadioButton;
8386
private JRadioButton intersectionRadioButton;
@@ -100,6 +103,7 @@ public class PAWeightPanel extends JPanel {
100103

101104
private boolean rankTestUpdating = false;
102105

106+
private CoalesceTimer debouncer = new CoalesceTimer(1000, 1);
103107

104108
public interface Factory {
105109
PAWeightPanel create(EnrichmentMap map);
@@ -209,21 +213,12 @@ private void showWarning(String message) {
209213
warnLabel.setVisible(message != null);
210214
}
211215

212-
213-
@SuppressWarnings("unchecked")
214-
private JPanel createRankTestSelectPanel() {
215-
JLabel testLabel = new JLabel(LABEL_TEST);
216-
JLabel cuttofLabel = new JLabel(LABEL_CUTOFF);
217-
JLabel dataSetLabel = new JLabel("Data Set:");
218-
219-
DECIMAL_FORMAT.setParseIntegerOnly(false);
220-
rankTestTextField = new JFormattedTextField(DECIMAL_FORMAT);
221-
rankTestTextField.setColumns(6);
222-
rankTestTextField.setHorizontalAlignment(JTextField.RIGHT);
223-
rankTestTextField.addPropertyChangeListener("value", e -> {
216+
private void updateRankTestValue() {
217+
debouncer.coalesce(() -> {
224218
String text = rankTestTextField.getText();
225219
try {
226220
double val = DECIMAL_FORMAT.parse(text).doubleValue();
221+
System.out.println("val: " + val);
227222
PostAnalysisFilterType filterType = getFilterType();
228223
savedFilterValues.put(filterType, val);
229224
showWarning(filterType.isValid(val) ? null : filterType.getErrorMessage());
@@ -234,6 +229,25 @@ private JPanel createRankTestSelectPanel() {
234229
if(!rankTestUpdating)
235230
firePropertyChange(PROPERTY_PARAMETERS, false, true);
236231
});
232+
}
233+
234+
235+
private JPanel createRankTestSelectPanel() {
236+
JLabel testLabel = new JLabel(LABEL_TEST);
237+
JLabel cuttofLabel = new JLabel(LABEL_CUTOFF);
238+
JLabel dataSetLabel = new JLabel("Data Set:");
239+
240+
DECIMAL_FORMAT.setParseIntegerOnly(false);
241+
rankTestTextField = new JTextField();
242+
rankTestTextField.setColumns(15);
243+
rankTestTextField.setHorizontalAlignment(JTextField.RIGHT);
244+
245+
rankTestTextField.addActionListener(e -> { updateRankTestValue(); });
246+
rankTestTextField.getDocument().addDocumentListener(new DocumentListener() {
247+
@Override public void removeUpdate(DocumentEvent e) { updateRankTestValue(); }
248+
@Override public void insertUpdate(DocumentEvent e) { updateRankTestValue(); }
249+
@Override public void changedUpdate(DocumentEvent e) { }
250+
});
237251

238252
rankingEnablementRenderer = new EnablementComboBoxRenderer<>();
239253
rankTestCombo = new JComboBox<>();
@@ -250,7 +264,7 @@ private JPanel createRankTestSelectPanel() {
250264
rankTestCombo.addActionListener(e -> {
251265
rankTestUpdating = true;
252266
PostAnalysisFilterType filterType = (PostAnalysisFilterType) rankTestCombo.getSelectedItem();
253-
rankTestTextField.setValue(savedFilterValues.get(filterType));
267+
rankTestTextField.setText(DECIMAL_FORMAT.format(savedFilterValues.get(filterType)));
254268
CardLayout cardLayout = (CardLayout) cardPanel.getLayout();
255269

256270
if(filterType.isMannWhitney() && map.getAllRanks().isEmpty())
@@ -422,7 +436,7 @@ private JPanel createHypergeomUniversePanel() {
422436
universeSelectionTextField.addPropertyChangeListener("value", e -> {
423437
Number val = (Number) universeSelectionTextField.getValue();
424438
if (val == null || val.intValue() < 0) {
425-
universeSelectionTextField.setValue(1);
439+
universeSelectionTextField.setText("1");
426440
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this), "Universe value must be greater than zero",
427441
"Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
428442
}
@@ -547,7 +561,7 @@ private void initialize() {
547561

548562
PostAnalysisFilterType typeToUse = rankingArray.length == 0 ? PostAnalysisFilterType.HYPERGEOM : PostAnalysisFilterType.MANN_WHIT_TWO_SIDED;
549563
rankTestCombo.setSelectedItem(typeToUse);
550-
rankTestTextField.setValue(typeToUse.defaultValue);
564+
rankTestTextField.setText(DECIMAL_FORMAT.format(typeToUse.defaultValue));
551565

552566
rankingEnablementRenderer.enableAll();
553567
if (rankingArray.length == 0) {

0 commit comments

Comments
 (0)