From 93a90c5084d1e81afd65bf2e3063cde96d6b3b48 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 31 Jul 2017 10:10:24 +0200 Subject: [PATCH] JAL-2630 applet update overview on release of threshold slider --- src/jalview/appletgui/FeatureColourChooser.java | 151 ++++++++++++----------- src/jalview/appletgui/FeatureSettings.java | 8 +- src/jalview/appletgui/PaintRefresher.java | 25 ++-- 3 files changed, 98 insertions(+), 86 deletions(-) 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 diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 9d2f601..7d00afd 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -544,7 +544,7 @@ public class FeatureSettings extends Panel implements ItemListener, Checkbox check = (Checkbox) featurePanel.getComponent(i); check.setState(!check.getState()); } - selectionChanged(); + selectionChanged(true); } private ItemListener groupItemListener = new ItemListener() @@ -567,10 +567,10 @@ public class FeatureSettings extends Panel implements ItemListener, @Override public void itemStateChanged(ItemEvent evt) { - selectionChanged(); + selectionChanged(true); } - void selectionChanged() + void selectionChanged(boolean updateOverview) { Component[] comps = featurePanel.getComponents(); int cSize = comps.length; @@ -591,7 +591,7 @@ public class FeatureSettings extends Panel implements ItemListener, fr.setFeaturePriority(data); - ap.paintAlignment(true); + ap.paintAlignment(updateOverview); } MyCheckbox selectedCheck; diff --git a/src/jalview/appletgui/PaintRefresher.java b/src/jalview/appletgui/PaintRefresher.java index 7c6fad0..32507fe 100755 --- a/src/jalview/appletgui/PaintRefresher.java +++ b/src/jalview/appletgui/PaintRefresher.java @@ -27,6 +27,7 @@ import java.awt.Component; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Vector; /** @@ -37,7 +38,7 @@ import java.util.Vector; */ public class PaintRefresher { - static Hashtable components; + static Map> components; /** * DOCUMENT ME! @@ -51,12 +52,12 @@ public class PaintRefresher { if (components == null) { - components = new Hashtable(); + components = new Hashtable>(); } if (components.containsKey(seqSetId)) { - Vector comps = (Vector) components.get(seqSetId); + Vector comps = components.get(seqSetId); if (!comps.contains(comp)) { comps.addElement(comp); @@ -64,7 +65,7 @@ public class PaintRefresher } else { - Vector vcoms = new Vector(); + Vector vcoms = new Vector<>(); vcoms.addElement(comp); components.put(seqSetId, vcoms); } @@ -77,11 +78,9 @@ public class PaintRefresher return; } - Enumeration en = components.keys(); - while (en.hasMoreElements()) + for (String id : components.keySet()) { - String id = en.nextElement().toString(); - Vector comps = (Vector) components.get(id); + Vector comps = components.get(id); comps.removeElement(comp); if (comps.size() == 0) { @@ -104,17 +103,17 @@ public class PaintRefresher } Component comp; - Vector comps = (Vector) components.get(id); + Vector comps = components.get(id); if (comps == null) { return; } - Enumeration e = comps.elements(); + Enumeration e = comps.elements(); while (e.hasMoreElements()) { - comp = (Component) e.nextElement(); + comp = e.nextElement(); if (comp == source) { @@ -240,8 +239,8 @@ public class PaintRefresher public static AlignmentPanel[] getAssociatedPanels(String id) { - Vector comps = (Vector) components.get(id); - Vector tmp = new Vector(); + Vector comps = components.get(id); + Vector tmp = new Vector<>(); int i, iSize = comps.size(); for (i = 0; i < iSize; i++) { -- 1.7.10.2