From 067038905ed3a04bbdb7e8f96dfc738d1735b41b Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 17 Aug 2018 10:10:12 +0100 Subject: [PATCH] JAL-3083 reset threshold on Cancel; Javadoc --- src/jalview/gui/AnnotationColourChooser.java | 71 +++++++++++++++++++++----- src/jalview/gui/AnnotationRowFilter.java | 16 ++++++ 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 384635b..b29a1dd 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -36,7 +36,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.Vector; import javax.swing.BorderFactory; @@ -59,7 +61,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter private JButton defColours; - private Hashtable oldgroupColours; + private Map oldgroupColours; + + private Map oldThresholds; private JCheckBox useOriginalColours = new JCheckBox(); @@ -73,21 +77,18 @@ public class AnnotationColourChooser extends AnnotationRowFilter protected static final int MIN_HEIGHT = 240; + /** + * Constructor + * + * @param av + * @param ap + */ public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { super(av, ap); - oldcs = av.getGlobalColourScheme(); - if (av.getAlignment().getGroups() != null) - { - oldgroupColours = new Hashtable<>(); - for (SequenceGroup sg : ap.av.getAlignment().getGroups()) - { - if (sg.getColourScheme() != null) - { - oldgroupColours.put(sg, sg.getColourScheme()); - } - } - } + + saveInitialState(); + frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); @@ -158,6 +159,43 @@ public class AnnotationColourChooser extends AnnotationRowFilter frame.pack(); } + /** + * Saves the global and group colour schemes as they are when the dialog is + * opened, so they can be restored on Cancel. Note we also save the threshold + * value for each annotation, in case this gets modified. + */ + void saveInitialState() + { + oldcs = av.getGlobalColourScheme(); + if (av.getAlignment().getGroups() != null) + { + oldgroupColours = new HashMap<>(); + for (SequenceGroup sg : ap.av.getAlignment().getGroups()) + { + if (sg.getColourScheme() != null) + { + oldgroupColours.put(sg, sg.getColourScheme()); + } + } + } + + /* + * save any existing annotation threshold settings; note we make a copy + * of each in case the current threshold value gets amended + */ + oldThresholds = new HashMap<>(); + AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation(); + if (anns != null) + { + for (AlignmentAnnotation ann : anns) + { + GraphLine thresh = ann.getThreshold(); + oldThresholds.put(ann, + thresh == null ? null : new GraphLine(thresh)); + } + } + } + @Override protected void jbInit() { @@ -326,6 +364,11 @@ public class AnnotationColourChooser extends AnnotationRowFilter sg.setColourScheme(oldgroupColours.get(sg)); } } + for (Entry entry : oldThresholds + .entrySet()) + { + entry.getKey().setThreshold(entry.getValue()); + } } @Override diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java index f13cb10..25f6b8e 100644 --- a/src/jalview/gui/AnnotationRowFilter.java +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -424,6 +424,22 @@ public abstract class AnnotationRowFilter extends JPanel return annotationLabels.get(ann); } + /** + * Configures controls for + *
    + *
  • OK and Cancel buttons
  • + *
  • annotations drop-down list
  • + *
  • choice of No/Above/Below threshold
  • + *
  • threshold
  • + *
      + *
    • slider
    • + *
    • input text field
    • + *
    • 'As Percentage' checkbox
    • + *
    + *
+ * Sub-classes are responsible for where (and whether) to place these fields, + * and for creation and population of the annotations combobox. + */ protected void jbInit() { ok.setOpaque(false); -- 1.7.10.2