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];
: 0));
adjusting = false;
- changeColour();
+ changeColour(true);
colourFromLabel.addItemListener(this);
slider.addAdjustmentListener(this);
slider.addMouseListener(this);
frame.setVisible(true);
if (frame.accept)
{
- changeColour();
+ changeColour(true);
}
else
{
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);
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)
{
}
else
{
- changeColour();
+ changeColour(true);
}
}
{
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)
{
}
}
+ /**
+ * 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);
}
}
{
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"));
}
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)
fr.setColour(type, acg);
cs = acg;
- fs.selectionChanged();
+ fs.selectionChanged(updateOverview);
}
void reset()
{
fr.setColour(type, oldcs);
- fs.selectionChanged();
+ fs.selectionChanged(true);
}
@Override
@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
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
/**
*/
public class PaintRefresher
{
- static Hashtable components;
+ static Map<String, Vector<Component>> components;
/**
* DOCUMENT ME!
{
if (components == null)
{
- components = new Hashtable();
+ components = new Hashtable<String, Vector<Component>>();
}
if (components.containsKey(seqSetId))
{
- Vector comps = (Vector) components.get(seqSetId);
+ Vector<Component> comps = components.get(seqSetId);
if (!comps.contains(comp))
{
comps.addElement(comp);
}
else
{
- Vector vcoms = new Vector();
+ Vector<Component> vcoms = new Vector<>();
vcoms.addElement(comp);
components.put(seqSetId, vcoms);
}
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<Component> comps = components.get(id);
comps.removeElement(comp);
if (comps.size() == 0)
{
}
Component comp;
- Vector comps = (Vector) components.get(id);
+ Vector<Component> comps = components.get(id);
if (comps == null)
{
return;
}
- Enumeration e = comps.elements();
+ Enumeration<Component> e = comps.elements();
while (e.hasMoreElements())
{
- comp = (Component) e.nextElement();
+ comp = e.nextElement();
if (comp == source)
{
public static AlignmentPanel[] getAssociatedPanels(String id)
{
- Vector comps = (Vector) components.get(id);
- Vector tmp = new Vector();
+ Vector<Component> comps = components.get(id);
+ Vector<Component> tmp = new Vector<>();
int i, iSize = comps.size();
for (i = 0; i < iSize; i++)
{