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;
private JButton defColours;
- private Hashtable<SequenceGroup, ColourSchemeI> oldgroupColours;
+ private Map<SequenceGroup, ColourSchemeI> oldgroupColours;
+
+ private Map<AlignmentAnnotation, GraphLine> oldGraphLines;
+
+ private Map<GraphLine, Float> oldThresholds;
private JCheckBox useOriginalColours = new JCheckBox();
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);
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
+ */
+ oldGraphLines = new HashMap<>();
+ oldThresholds = new HashMap<>();
+ AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
+ if (anns != null)
+ {
+ for (AlignmentAnnotation ann : anns)
+ {
+ GraphLine thresh = ann.getThreshold();
+ oldGraphLines.put(ann, thresh);
+ if (thresh != null)
+ {
+ oldThresholds.put(thresh, thresh.value);
+ }
+ }
+ }
+ }
+
@Override
protected void jbInit()
{
sg.setColourScheme(oldgroupColours.get(sg));
}
}
+ for (Entry<AlignmentAnnotation, GraphLine> entry : oldGraphLines
+ .entrySet())
+ {
+ GraphLine graphLine = entry.getValue();
+ entry.getKey().setThreshold(graphLine);
+ if (graphLine != null)
+ {
+ graphLine.value = oldThresholds.get(graphLine).floatValue();
+ }
+ }
}
@Override