2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.GraphLine;
24 import jalview.schemes.AnnotationColourGradient;
25 import jalview.schemes.GraduatedColor;
26 import jalview.util.MessageManager;
28 import java.awt.Checkbox;
29 import java.awt.Choice;
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.FlowLayout;
34 import java.awt.Frame;
35 import java.awt.GridLayout;
36 import java.awt.Label;
37 import java.awt.Panel;
38 import java.awt.Scrollbar;
39 import java.awt.TextField;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.AdjustmentEvent;
43 import java.awt.event.AdjustmentListener;
44 import java.awt.event.ItemEvent;
45 import java.awt.event.ItemListener;
46 import java.awt.event.MouseEvent;
47 import java.awt.event.MouseListener;
48 import java.util.Hashtable;
50 public class FeatureColourChooser extends Panel implements ActionListener,
51 AdjustmentListener, ItemListener, MouseListener
59 FeatureSettings fs = null;
67 Hashtable oldgroupColours;
69 boolean adjusting = false;
71 private float min, max;
75 private AlignFrame af = null;
77 public FeatureColourChooser(AlignFrame af, String type)
80 init(af.getSeqcanvas().getFeatureRenderer(), type);
83 public FeatureColourChooser(FeatureSettings fsettings, String type)
86 init(fsettings.fr, type);
87 // this.ap = fsettings.ap;
90 private void init(FeatureRenderer frenderer, String type)
94 float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
97 oldcs = fr.getFeatureColours().get(type);
98 if (oldcs instanceof GraduatedColor)
100 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
104 // promote original color to a graduated color
105 Color bl = Color.black;
106 if (oldcs instanceof Color)
110 // original colour becomes the maximum colour
111 cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
113 minColour.setBackground(cs.getMinColor());
114 maxColour.setBackground(cs.getMaxColor());
115 minColour.setForeground(cs.getMinColor());
116 maxColour.setForeground(cs.getMaxColor());
117 colourFromLabel.setState(cs.isColourByLabel());
123 } catch (Exception ex)
127 .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
128 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
133 colourFromLabel.addItemListener(this);
134 slider.addAdjustmentListener(this);
135 slider.addMouseListener(this);
136 owner = (af != null) ? af : fs.frame;
137 frame = new JVDialog(owner, MessageManager.formatMessage(
138 "label.graduated_color_for_params", new String[] { type }),
140 frame.setMainPanel(this);
142 frame.setVisible(true);
151 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
152 frame.setVisible(false);
156 public FeatureColourChooser()
161 } catch (Exception ex)
163 ex.printStackTrace();
167 private void jbInit() throws Exception
169 Label minLabel = new Label(MessageManager.getString("label.min")), maxLabel = new Label(
170 MessageManager.getString("label.max"));
171 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
172 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
173 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
174 // minColour.setLabel("Min Colour");
176 minColour.setBounds(0, 0, 40, 27);
177 maxColour.setBounds(0, 0, 40, 27);
178 minColour.addMouseListener(this);
180 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
181 maxColour.addMouseListener(this);
183 thresholdIsMin.addItemListener(this);
185 this.setLayout(new GridLayout(4, 1));
186 jPanel1.setLayout(new FlowLayout());
187 jPanel2.setLayout(new FlowLayout());
188 jPanel3.setLayout(new GridLayout(1, 1));
189 jPanel4.setLayout(new FlowLayout());
190 jPanel1.setBackground(Color.white);
191 jPanel2.setBackground(Color.white);
192 jPanel4.setBackground(Color.white);
193 threshold.addItemListener(this);
194 threshold.addItem(MessageManager
195 .getString("label.threshold_feature_no_thereshold"));
196 threshold.addItem(MessageManager
197 .getString("label.threshold_feature_above_thereshold"));
198 threshold.addItem(MessageManager
199 .getString("label.threshold_feature_below_thereshold"));
200 thresholdValue.addActionListener(this);
201 slider.setBackground(Color.white);
202 slider.setEnabled(false);
203 slider.setSize(new Dimension(93, 21));
204 thresholdValue.setEnabled(false);
205 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
206 // Rectangle(248, 2, 79,
208 thresholdValue.setColumns(5);
209 jPanel3.setBackground(Color.white);
211 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
212 colourFromLabel.setLabel(MessageManager
213 .getString("label.colour_by_label"));
214 colourFromLabel.setSize(new Dimension(139, 22));
215 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
216 thresholdIsMin.setBackground(Color.white);
217 thresholdIsMin.setLabel(MessageManager
218 .getString("label.threshold_minmax"));
219 thresholdIsMin.setSize(new Dimension(135, 23));
220 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
221 jPanel1.add(minLabel);
222 jPanel1.add(minColour);
223 jPanel1.add(maxLabel);
224 jPanel1.add(maxColour);
225 jPanel1.add(colourFromLabel);
226 jPanel2.add(threshold);
228 jPanel4.add(thresholdValue);
229 jPanel4.add(thresholdIsMin);
230 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
231 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
232 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
233 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
236 Panel minColour = new Panel();
238 Panel maxColour = new Panel();
240 Panel jPanel1 = new Panel();
242 Panel jPanel2 = new Panel();
244 Choice threshold = new Choice();
246 Panel jPanel3 = new Panel();
248 Panel jPanel4 = new Panel();
250 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
252 TextField thresholdValue = new TextField(20);
254 // BorderLayout borderLayout1 = new BorderLayout();
256 Checkbox thresholdIsMin = new Checkbox();
258 Checkbox colourFromLabel = new Checkbox();
260 private GraphLine threshline;
262 public void actionPerformed(ActionEvent evt)
264 if (evt.getSource() == thresholdValue)
268 float f = new Float(thresholdValue.getText()).floatValue();
269 slider.setValue((int) (f * 1000));
270 adjustmentValueChanged(null);
271 } catch (NumberFormatException ex)
275 else if (evt.getSource() == minColour)
277 minColour_actionPerformed(null);
279 else if (evt.getSource() == maxColour)
281 maxColour_actionPerformed(null);
289 public void itemStateChanged(ItemEvent evt)
291 maxColour.setEnabled(!colourFromLabel.getState());
292 minColour.setEnabled(!colourFromLabel.getState());
296 public void adjustmentValueChanged(AdjustmentEvent evt)
300 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
305 protected void valueChanged()
307 threshline.value = (float) slider.getValue() / 1000f;
308 cs.setThresh(threshline.value);
310 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
311 // ap.paintAlignment(false);
314 public void minColour_actionPerformed(Color newCol)
318 UserDefinedColours udc = new UserDefinedColours(this,
319 minColour.getBackground(), owner,
320 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
324 minColour.setBackground(newCol);
325 minColour.setForeground(newCol);
332 public void maxColour_actionPerformed(Color newCol)
337 // UserDefinedColours udc = new UserDefinedColours(this,
338 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
339 UserDefinedColours udc = new UserDefinedColours(this,
340 maxColour.getBackground(), owner,
341 MessageManager.getString("label.select_colour_maximum_value"));
345 maxColour.setBackground(newCol);
346 maxColour.setForeground(newCol);
354 // Check if combobox is still adjusting
360 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
361 if (threshold.getSelectedIndex() == 1)
363 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
365 else if (threshold.getSelectedIndex() == 2)
367 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
370 slider.setEnabled(true);
371 thresholdValue.setEnabled(true);
372 GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
373 maxColour.getBackground(), min, max);
375 acg.setColourByLabel(colourFromLabel.getState());
376 maxColour.setEnabled(!colourFromLabel.getState());
377 minColour.setEnabled(!colourFromLabel.getState());
378 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
380 slider.setEnabled(false);
381 thresholdValue.setEnabled(false);
382 thresholdValue.setText("");
385 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
386 && threshline == null)
388 // todo visual indication of feature threshold
389 threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
390 "Threshold", Color.black);
393 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
396 acg.setThresh(threshline.value);
398 float range = max * 1000f - min * 1000f;
400 slider.setMinimum((int) (min * 1000));
401 slider.setMaximum((int) (max * 1000));
402 slider.setValue((int) (threshline.value * 1000));
403 thresholdValue.setText(threshline.value + "");
404 slider.setEnabled(true);
405 thresholdValue.setEnabled(true);
409 acg.setThreshType(aboveThreshold);
410 if (thresholdIsMin.getState()
411 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
413 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
415 acg = new GraduatedColor(acg, threshline.value, max);
419 acg = new GraduatedColor(acg, min, threshline.value);
423 fr.setColour(type, acg);
425 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
426 // ap.paintAlignment(false);
431 fr.setColour(type, oldcs);
432 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
433 // ap.paintAlignment(true);
437 public void mouseClicked(MouseEvent evt)
441 public void mousePressed(MouseEvent evt)
445 public void mouseReleased(MouseEvent evt)
447 if (evt.getSource() == minColour || evt.getSource() == maxColour)
450 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
454 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
456 // ap.paintAlignment(true);
459 public void mouseEntered(MouseEvent evt)
463 public void mouseExited(MouseEvent evt)