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> 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
+ */
+ 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()
{
sg.setColourScheme(oldgroupColours.get(sg));
}
}
+ for (Entry<AlignmentAnnotation, GraphLine> entry : oldThresholds
+ .entrySet())
+ {
+ entry.getKey().setThreshold(entry.getValue());
+ }
}
@Override
return annotationLabels.get(ann);
}
+ /**
+ * Configures controls for
+ * <ul>
+ * <li>OK and Cancel buttons</li>
+ * <li>annotations drop-down list</li>
+ * <li>choice of No/Above/Below threshold</li>
+ * <li>threshold</li>
+ * <ul>
+ * <li>slider</li>
+ * <li>input text field</li>
+ * <li>'As Percentage' checkbox</li>
+ * </ul>
+ * </ul>
+ * 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);