2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import java.awt.Rectangle;
30 public class FeatureColourChooser extends Panel implements
31 ActionListener, AdjustmentListener, ItemListener, MouseListener
36 FeatureSettings fs = null;
42 Hashtable oldgroupColours;
45 boolean adjusting = false;
46 private float min,max;
49 private AlignFrame af=null;
50 public FeatureColourChooser(AlignFrame af, String type)
53 init(af.getSeqcanvas().getFeatureRenderer(), type);
55 public FeatureColourChooser(FeatureSettings fsettings, String type)
58 init(fsettings.fr, type);
59 // this.ap = fsettings.ap;
61 private void init(FeatureRenderer frenderer,String type) {
64 float mm[] = ((float[][]) fr.minmax.get(type))[0];
67 oldcs = fr.featureColours.get(type);
68 if (oldcs instanceof GraduatedColor)
70 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
72 // promote original color to a graduated color
73 Color bl = Color.black;
74 if (oldcs instanceof Color)
78 // original colour becomes the maximum colour
79 cs = new GraduatedColor(Color.white,bl,mm[0],mm[1]);
81 minColour.setBackground(cs.getMinColor());
82 maxColour.setBackground(cs.getMaxColor());
83 colourFromLabel.setState(cs.isColourByLabel());
89 } catch (Exception ex)
92 threshold.select(cs.getThreshType()==AnnotationColourGradient.NO_THRESHOLD ? 0 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1 : 2);
96 colourFromLabel.addItemListener(this);
97 slider.addAdjustmentListener(this);
98 slider.addMouseListener(this);
99 Frame owner = (af!=null) ? af : fs.frame;
100 frame = new JVDialog(owner,"Graduated Feature Colour for "+type,true,480,248);
101 frame.setMainPanel(this);
103 frame.setVisible(true);
109 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
110 frame.setVisible(false);
114 public FeatureColourChooser()
119 } catch (Exception ex)
121 ex.printStackTrace();
125 private void jbInit() throws Exception
127 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
128 minColour.setLabel("Min Colour");
129 minColour.addActionListener(this);
131 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
132 maxColour.setLabel("Max Colour");
133 maxColour.addActionListener(this);
135 thresholdIsMin.addItemListener(this);
137 this.setLayout(new GridLayout(4,1));
138 jPanel1.setLayout(new FlowLayout());
139 jPanel2.setLayout(new FlowLayout());
140 jPanel3.setLayout(new GridLayout(1,1));
141 jPanel4.setLayout(new FlowLayout());
142 jPanel1.setBackground(Color.white);
143 jPanel2.setBackground(Color.white);
144 jPanel4.setBackground(Color.white);
145 threshold.addItemListener(this);
146 threshold.addItem("No Threshold");
147 threshold.addItem("Above Threshold");
148 threshold.addItem("Below Threshold");
149 thresholdValue.addActionListener(this);
150 slider.setBackground(Color.white);
151 slider.setEnabled(false);
152 slider.setSize(new Dimension(93, 21));
153 thresholdValue.setEnabled(false);
154 thresholdValue.setSize(new Dimension(79,22)); //setBounds(new Rectangle(248, 2, 79, 22));
155 thresholdValue.setColumns(5);
156 jPanel3.setBackground(Color.white);
158 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
159 colourFromLabel.setLabel("Colour by Label");
160 colourFromLabel.setSize(new Dimension(139,22));
161 //threshold.setBounds(new Rectangle(11, 3, 139, 22));
162 thresholdIsMin.setBackground(Color.white);
163 thresholdIsMin.setLabel("Threshold is min/max");
164 thresholdIsMin.setSize(new Dimension(135,23));
165 //thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
166 jPanel1.add(minColour);
167 jPanel1.add(maxColour);
168 jPanel1.add(colourFromLabel);
169 jPanel2.add(threshold);
171 jPanel4.add(thresholdValue);
172 jPanel4.add(thresholdIsMin);
173 this.add(jPanel1);//, java.awt.BorderLayout.NORTH);
174 this.add(jPanel2);//, java.awt.BorderLayout.NORTH);
175 this.add(jPanel3);//, java.awt.BorderLayout.CENTER);
176 this.add(jPanel4);//, java.awt.BorderLayout.CENTER);
179 Button minColour = new Button();
181 Button maxColour = new Button();
184 Panel jPanel1 = new Panel();
186 Panel jPanel2 = new Panel();
188 Choice threshold = new Choice();
190 Panel jPanel3 = new Panel();
191 Panel jPanel4 = new Panel();
193 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
195 TextField thresholdValue = new TextField(20);
198 // BorderLayout borderLayout1 = new BorderLayout();
200 Checkbox thresholdIsMin = new Checkbox();
201 Checkbox colourFromLabel = new Checkbox();
203 private GraphLine threshline;
205 public void actionPerformed(ActionEvent evt)
207 if (evt.getSource() == thresholdValue)
211 float f = new Float(thresholdValue.getText()).floatValue();
212 slider.setValue((int) (f * 1000));
213 adjustmentValueChanged(null);
214 } catch (NumberFormatException ex)
218 else if (evt.getSource() == minColour)
220 minColour_actionPerformed(null);
222 else if (evt.getSource() == maxColour)
224 maxColour_actionPerformed(null);
232 public void itemStateChanged(ItemEvent evt)
234 maxColour.setEnabled(!colourFromLabel.getState());
235 minColour.setEnabled(!colourFromLabel.getState());
239 public void adjustmentValueChanged(AdjustmentEvent evt)
243 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
247 protected void valueChanged() {
248 threshline.value = (float) slider.getValue() / 1000f;
249 cs.setThresh(threshline.value);
251 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
252 // ap.paintAlignment(false);
254 public void minColour_actionPerformed(Color newCol)
258 UserDefinedColours udc = new UserDefinedColours(this,minColour.getBackground(), frame, "Select Colour for Minimum Value");
260 minColour.setBackground(newCol);
267 public void maxColour_actionPerformed(Color newCol)
271 UserDefinedColours udc = new UserDefinedColours(this,maxColour.getBackground(), frame, "Select Colour for Maximum Value");// this, "Select Colour for Maximum Value", maxColour.getBackground());
273 maxColour.setBackground(newCol);
281 // Check if combobox is still adjusting
287 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
288 if (threshold.getSelectedItem().equals("Above Threshold"))
290 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
292 else if (threshold.getSelectedItem().equals("Below Threshold"))
294 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
297 slider.setEnabled(true);
298 thresholdValue.setEnabled(true);
299 GraduatedColor acg = new GraduatedColor(minColour.getBackground(), maxColour.getBackground(), min, max);
301 acg.setColourByLabel(colourFromLabel.getState());
302 maxColour.setEnabled(!colourFromLabel.getState());
303 minColour.setEnabled(!colourFromLabel.getState());
304 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
306 slider.setEnabled(false);
307 thresholdValue.setEnabled(false);
308 thresholdValue.setText("");
311 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
312 && threshline == null)
314 // todo visual indication of feature threshold
315 threshline = new jalview.datamodel.GraphLine(
317 "Threshold", Color.black);
320 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
323 acg.setThresh(threshline.value);
325 float range = max * 1000f
328 slider.setMinimum((int) (min * 1000));
329 slider.setMaximum((int) (max * 1000));
330 slider.setValue((int) (threshline.value * 1000));
331 thresholdValue.setText(threshline.value + "");
332 slider.setEnabled(true);
333 thresholdValue.setEnabled(true);
337 acg.setThreshType(aboveThreshold);
338 if (thresholdIsMin.getState() && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
340 if (aboveThreshold==AnnotationColourGradient.ABOVE_THRESHOLD)
342 acg = new GraduatedColor(acg, threshline.value, max);
344 acg = new GraduatedColor(acg, min,threshline.value);
348 fr.featureColours.put(type,acg);
350 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
351 // ap.paintAlignment(false);
356 fr.featureColours.put(type, oldcs);
357 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
358 // ap.paintAlignment(true);
362 public void mouseClicked(MouseEvent evt)
366 public void mousePressed(MouseEvent evt)
370 public void mouseReleased(MouseEvent evt)
372 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
373 // ap.paintAlignment(true);
376 public void mouseEntered(MouseEvent evt)
380 public void mouseExited(MouseEvent evt)