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 minColour.setForeground(cs.getMinColor());
84 maxColour.setForeground(cs.getMaxColor());
85 colourFromLabel.setState(cs.isColourByLabel());
91 } catch (Exception ex)
94 threshold.select(cs.getThreshType()==AnnotationColourGradient.NO_THRESHOLD ? 0 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1 : 2);
98 colourFromLabel.addItemListener(this);
99 slider.addAdjustmentListener(this);
100 slider.addMouseListener(this);
101 owner = (af!=null) ? af : fs.frame;
102 frame = new JVDialog(owner,"Graduated Feature Colour for "+type,true,480,248);
103 frame.setMainPanel(this);
105 frame.setVisible(true);
111 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
112 frame.setVisible(false);
116 public FeatureColourChooser()
121 } catch (Exception ex)
123 ex.printStackTrace();
127 private void jbInit() throws Exception
129 Label minLabel = new Label("Min:"),maxLabel=new Label("Max:");
130 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
131 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
132 //minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
133 //minColour.setLabel("Min Colour");
135 minColour.setBounds(0,0,40,27);
136 maxColour.setBounds(0,0,40,27);
137 minColour.addMouseListener(this);
139 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
140 maxColour.addMouseListener(this);
142 thresholdIsMin.addItemListener(this);
144 this.setLayout(new GridLayout(4,1));
145 jPanel1.setLayout(new FlowLayout());
146 jPanel2.setLayout(new FlowLayout());
147 jPanel3.setLayout(new GridLayout(1,1));
148 jPanel4.setLayout(new FlowLayout());
149 jPanel1.setBackground(Color.white);
150 jPanel2.setBackground(Color.white);
151 jPanel4.setBackground(Color.white);
152 threshold.addItemListener(this);
153 threshold.addItem("No Threshold");
154 threshold.addItem("Above Threshold");
155 threshold.addItem("Below Threshold");
156 thresholdValue.addActionListener(this);
157 slider.setBackground(Color.white);
158 slider.setEnabled(false);
159 slider.setSize(new Dimension(93, 21));
160 thresholdValue.setEnabled(false);
161 thresholdValue.setSize(new Dimension(79,22)); //setBounds(new Rectangle(248, 2, 79, 22));
162 thresholdValue.setColumns(5);
163 jPanel3.setBackground(Color.white);
165 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
166 colourFromLabel.setLabel("Colour by Label");
167 colourFromLabel.setSize(new Dimension(139,22));
168 //threshold.setBounds(new Rectangle(11, 3, 139, 22));
169 thresholdIsMin.setBackground(Color.white);
170 thresholdIsMin.setLabel("Threshold is min/max");
171 thresholdIsMin.setSize(new Dimension(135,23));
172 //thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
173 jPanel1.add(minLabel);
174 jPanel1.add(minColour);
175 jPanel1.add(maxLabel);
176 jPanel1.add(maxColour);
177 jPanel1.add(colourFromLabel);
178 jPanel2.add(threshold);
180 jPanel4.add(thresholdValue);
181 jPanel4.add(thresholdIsMin);
182 this.add(jPanel1);//, java.awt.BorderLayout.NORTH);
183 this.add(jPanel2);//, java.awt.BorderLayout.NORTH);
184 this.add(jPanel3);//, java.awt.BorderLayout.CENTER);
185 this.add(jPanel4);//, java.awt.BorderLayout.CENTER);
188 Panel minColour = new Panel();
190 Panel maxColour = new Panel();
193 Panel jPanel1 = new Panel();
195 Panel jPanel2 = new Panel();
197 Choice threshold = new Choice();
199 Panel jPanel3 = new Panel();
200 Panel jPanel4 = new Panel();
202 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
204 TextField thresholdValue = new TextField(20);
207 // BorderLayout borderLayout1 = new BorderLayout();
209 Checkbox thresholdIsMin = new Checkbox();
210 Checkbox colourFromLabel = new Checkbox();
212 private GraphLine threshline;
214 public void actionPerformed(ActionEvent evt)
216 if (evt.getSource() == thresholdValue)
220 float f = new Float(thresholdValue.getText()).floatValue();
221 slider.setValue((int) (f * 1000));
222 adjustmentValueChanged(null);
223 } catch (NumberFormatException ex)
227 else if (evt.getSource() == minColour)
229 minColour_actionPerformed(null);
231 else if (evt.getSource() == maxColour)
233 maxColour_actionPerformed(null);
241 public void itemStateChanged(ItemEvent evt)
243 maxColour.setEnabled(!colourFromLabel.getState());
244 minColour.setEnabled(!colourFromLabel.getState());
248 public void adjustmentValueChanged(AdjustmentEvent evt)
252 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
256 protected void valueChanged() {
257 threshline.value = (float) slider.getValue() / 1000f;
258 cs.setThresh(threshline.value);
260 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
261 // ap.paintAlignment(false);
263 public void minColour_actionPerformed(Color newCol)
267 UserDefinedColours udc = new UserDefinedColours(this,minColour.getBackground(),owner, "Select Colour for Minimum Value"); // frame.owner,
269 minColour.setBackground(newCol);
270 minColour.setForeground(newCol);
277 public void maxColour_actionPerformed(Color newCol)
282 // UserDefinedColours udc = new UserDefinedColours(this, "Select Colour for Maximum Value",maxColour.getBackground(),true);
283 UserDefinedColours udc = new UserDefinedColours(this, maxColour.getBackground(), owner, "Select Colour for Maximum Value");
285 maxColour.setBackground(newCol);
286 maxColour.setForeground(newCol);
294 // Check if combobox is still adjusting
300 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
301 if (threshold.getSelectedItem().equals("Above Threshold"))
303 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
305 else if (threshold.getSelectedItem().equals("Below Threshold"))
307 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
310 slider.setEnabled(true);
311 thresholdValue.setEnabled(true);
312 GraduatedColor acg = new GraduatedColor(minColour.getBackground(), maxColour.getBackground(), min, max);
314 acg.setColourByLabel(colourFromLabel.getState());
315 maxColour.setEnabled(!colourFromLabel.getState());
316 minColour.setEnabled(!colourFromLabel.getState());
317 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
319 slider.setEnabled(false);
320 thresholdValue.setEnabled(false);
321 thresholdValue.setText("");
324 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
325 && threshline == null)
327 // todo visual indication of feature threshold
328 threshline = new jalview.datamodel.GraphLine(
330 "Threshold", Color.black);
333 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
336 acg.setThresh(threshline.value);
338 float range = max * 1000f
341 slider.setMinimum((int) (min * 1000));
342 slider.setMaximum((int) (max * 1000));
343 slider.setValue((int) (threshline.value * 1000));
344 thresholdValue.setText(threshline.value + "");
345 slider.setEnabled(true);
346 thresholdValue.setEnabled(true);
350 acg.setThreshType(aboveThreshold);
351 if (thresholdIsMin.getState() && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
353 if (aboveThreshold==AnnotationColourGradient.ABOVE_THRESHOLD)
355 acg = new GraduatedColor(acg, threshline.value, max);
357 acg = new GraduatedColor(acg, min,threshline.value);
361 fr.featureColours.put(type,acg);
363 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
364 // ap.paintAlignment(false);
369 fr.featureColours.put(type, oldcs);
370 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
371 // ap.paintAlignment(true);
375 public void mouseClicked(MouseEvent evt)
379 public void mousePressed(MouseEvent evt)
383 public void mouseReleased(MouseEvent evt)
385 if (evt.getSource()==minColour || evt.getSource()==maxColour)
388 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
390 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
392 // ap.paintAlignment(true);
395 public void mouseEntered(MouseEvent evt)
399 public void mouseExited(MouseEvent evt)