X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureColourChooser.java;fp=src%2Fjalview%2Fappletgui%2FFeatureColourChooser.java;h=f4603895dc6539265f2aa213c34d2779e9f7697b;hb=93a90c5084d1e81afd65bf2e3063cde96d6b3b48;hp=6c162e1835e0340eebf4476b77cd5552faf742c5;hpb=98f6651899fa88eed326ef6684b22e06e7a49c1a;p=jalview.git diff --git a/src/jalview/appletgui/FeatureColourChooser.java b/src/jalview/appletgui/FeatureColourChooser.java index 6c162e1..f460389 100644 --- a/src/jalview/appletgui/FeatureColourChooser.java +++ b/src/jalview/appletgui/FeatureColourChooser.java @@ -46,53 +46,81 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.Hashtable; public class FeatureColourChooser extends Panel implements ActionListener, AdjustmentListener, ItemListener, MouseListener { + /* + * the absolute min-max range of a feature score is scaled to + * 1000 positions on the colour threshold slider + */ private static final int SCALE_FACTOR_1K = 1000; - JVDialog frame; + private JVDialog frame; - Frame owner; + private Frame owner; - FeatureRenderer fr; + private FeatureRenderer fr; - FeatureSettings fs = null; + private FeatureSettings fs = null; - // AlignmentPanel ap; + private FeatureColourI cs; - FeatureColourI cs; + private FeatureColourI oldcs; - FeatureColourI oldcs; - - Hashtable oldgroupColours; - - boolean adjusting = false; + private boolean adjusting = false; private float min, max; - String type = null; + private String type = null; private AlignFrame af = null; - public FeatureColourChooser(AlignFrame af, String type) + private Panel minColour = new Panel(); + + private Panel maxColour = new Panel(); + + private Choice threshold = new Choice(); + + private Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL); + + private TextField thresholdValue = new TextField(20); + + private Checkbox thresholdIsMin = new Checkbox(); + + private Checkbox colourFromLabel = new Checkbox(); + + private GraphLine threshline; + + /** + * Constructor given a context AlignFrame and a feature type. This is used + * when opening the graduated colour dialog from the Amend Feature dialog. + * + * @param alignFrame + * @param featureType + */ + public FeatureColourChooser(AlignFrame alignFrame, String featureType) { - this.af = af; - init(af.getSeqcanvas().getFeatureRenderer(), type); + this.af = alignFrame; + init(alignFrame.getSeqcanvas().getFeatureRenderer(), featureType); } - public FeatureColourChooser(FeatureSettings fsettings, String type) + /** + * Constructor given a context FeatureSettings and a feature type. This is + * used when opening the graduated colour dialog from Feature Settings. + * + * @param fsettings + * @param featureType + */ + public FeatureColourChooser(FeatureSettings fsettings, String featureType) { this.fs = fsettings; - init(fsettings.fr, type); - // this.ap = fsettings.ap; + init(fsettings.fr, featureType); } - private void init(FeatureRenderer frenderer, String type) + private void init(FeatureRenderer frenderer, String featureType) { - this.type = type; + this.type = featureType; fr = frenderer; float mm[] = fr.getMinMax().get(type)[0]; min = mm[0]; @@ -132,7 +160,7 @@ public class FeatureColourChooser extends Panel implements ActionListener, : 0)); adjusting = false; - changeColour(); + changeColour(true); colourFromLabel.addItemListener(this); slider.addAdjustmentListener(this); slider.addMouseListener(this); @@ -145,7 +173,7 @@ public class FeatureColourChooser extends Panel implements ActionListener, frame.setVisible(true); if (frame.accept) { - changeColour(); + changeColour(true); } else { @@ -185,9 +213,13 @@ public class FeatureColourChooser extends Panel implements ActionListener, thresholdIsMin.addItemListener(this); this.setLayout(new GridLayout(4, 1)); + Panel jPanel1 = new Panel(); jPanel1.setLayout(new FlowLayout()); + Panel jPanel2 = new Panel(); jPanel2.setLayout(new FlowLayout()); + Panel jPanel3 = new Panel(); jPanel3.setLayout(new GridLayout(1, 1)); + Panel jPanel4 = new Panel(); jPanel4.setLayout(new FlowLayout()); jPanel1.setBackground(Color.white); jPanel2.setBackground(Color.white); @@ -235,32 +267,6 @@ public class FeatureColourChooser extends Panel implements ActionListener, this.add(jPanel4);// , java.awt.BorderLayout.CENTER); } - Panel minColour = new Panel(); - - Panel maxColour = new Panel(); - - Panel jPanel1 = new Panel(); - - Panel jPanel2 = new Panel(); - - Choice threshold = new Choice(); - - Panel jPanel3 = new Panel(); - - Panel jPanel4 = new Panel(); - - Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL); - - TextField thresholdValue = new TextField(20); - - // BorderLayout borderLayout1 = new BorderLayout(); - - Checkbox thresholdIsMin = new Checkbox(); - - Checkbox colourFromLabel = new Checkbox(); - - private GraphLine threshline; - @Override public void actionPerformed(ActionEvent evt) { @@ -285,7 +291,7 @@ public class FeatureColourChooser extends Panel implements ActionListener, } else { - changeColour(); + changeColour(true); } } @@ -294,9 +300,13 @@ public class FeatureColourChooser extends Panel implements ActionListener, { maxColour.setEnabled(!colourFromLabel.getState()); minColour.setEnabled(!colourFromLabel.getState()); - changeColour(); + changeColour(true); } + /** + * Handler called when the value of the threshold slider changes, either by + * user action or programmatically + */ @Override public void adjustmentValueChanged(AdjustmentEvent evt) { @@ -307,29 +317,32 @@ public class FeatureColourChooser extends Panel implements ActionListener, } } + /** + * Responds to a change of colour threshold by computing the absolute value + * and refreshing the alignment. + */ protected void valueChanged() { threshline.value = slider.getValue() / 1000f; cs.setThreshold(threshline.value); - changeColour(); + changeColour(false); PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId()); - // ap.paintAlignment(false); } public void minColour_actionPerformed(Color newCol) { if (newCol == null) { - UserDefinedColours udc = new UserDefinedColours(this, + new UserDefinedColours(this, minColour.getBackground(), owner, - MessageManager.getString("label.select_colour_minimum_value")); // frame.owner, + MessageManager.getString("label.select_colour_minimum_value")); } else { minColour.setBackground(newCol); minColour.setForeground(newCol); minColour.repaint(); - changeColour(); + changeColour(true); } } @@ -338,10 +351,7 @@ public class FeatureColourChooser extends Panel implements ActionListener, { if (newCol == null) { - - // UserDefinedColours udc = new UserDefinedColours(this, - // "Select Colour for Maximum Value",maxColour.getBackground(),true); - UserDefinedColours udc = new UserDefinedColours(this, + new UserDefinedColours(this, maxColour.getBackground(), owner, MessageManager.getString("label.select_colour_maximum_value")); } @@ -350,11 +360,11 @@ public class FeatureColourChooser extends Panel implements ActionListener, maxColour.setBackground(newCol); maxColour.setForeground(newCol); maxColour.repaint(); - changeColour(); + changeColour(true); } } - void changeColour() + void changeColour(boolean updateOverview) { // Check if combobox is still adjusting if (adjusting) @@ -417,13 +427,13 @@ public class FeatureColourChooser extends Panel implements ActionListener, fr.setColour(type, acg); cs = acg; - fs.selectionChanged(); + fs.selectionChanged(updateOverview); } void reset() { fr.setColour(type, oldcs); - fs.selectionChanged(); + fs.selectionChanged(true); } @Override @@ -439,16 +449,19 @@ public class FeatureColourChooser extends Panel implements ActionListener, @Override public void mouseReleased(MouseEvent evt) { - if (evt.getSource() == minColour || evt.getSource() == maxColour) + if (evt.getSource() == minColour) { - // relay the event - actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked")); + minColour_actionPerformed(null); + } + else if (evt.getSource() == maxColour) + { + maxColour_actionPerformed(null); } else { - PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId()); + changeColour(true); + // PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId()); } - // ap.paintAlignment(true); } @Override