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.api.FeatureColourI;
24 import jalview.datamodel.GraphLine;
25 import jalview.schemes.AnnotationColourGradient;
26 import jalview.schemes.Colour;
27 import jalview.schemes.FeatureColour;
28 import jalview.util.ColorUtils;
29 import jalview.util.MessageManager;
31 import java.awt.Checkbox;
32 import java.awt.Choice;
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.FlowLayout;
37 import java.awt.Frame;
38 import java.awt.GridLayout;
39 import java.awt.Label;
40 import java.awt.Panel;
41 import java.awt.Scrollbar;
42 import java.awt.TextField;
43 import java.awt.event.ActionEvent;
44 import java.awt.event.ActionListener;
45 import java.awt.event.AdjustmentEvent;
46 import java.awt.event.AdjustmentListener;
47 import java.awt.event.ItemEvent;
48 import java.awt.event.ItemListener;
49 import java.awt.event.MouseEvent;
50 import java.awt.event.MouseListener;
51 import java.util.Hashtable;
53 public class FeatureColourChooser extends Panel implements ActionListener,
54 AdjustmentListener, ItemListener, MouseListener
62 FeatureSettings fs = null;
70 Hashtable oldgroupColours;
72 boolean adjusting = false;
74 private float min, max;
78 private AlignFrame af = null;
80 public FeatureColourChooser(AlignFrame af, String type)
83 init(af.getSeqcanvas().getFeatureRenderer(), type);
86 public FeatureColourChooser(FeatureSettings fsettings, String type)
89 init(fsettings.fr, type);
90 // this.ap = fsettings.ap;
93 private void init(FeatureRenderer frenderer, String type)
97 float mm[] = fr.getMinMax().get(type)[0];
100 oldcs = fr.getFeatureColours().get(type);
101 if (oldcs.isGraduatedColour())
103 cs = new FeatureColour((FeatureColour) oldcs, min, max);
107 // promote original color to a graduated color
108 Color bl = Color.black;
109 if (oldcs.isSimpleColour())
111 bl = ColorUtils.getColor(oldcs.getColour());
113 // original colour becomes the maximum colour
114 cs = new FeatureColour(new Colour(Color.white), new Colour(bl),
117 minColour.setBackground(ColorUtils.getColor(cs.getMinColour()));
118 maxColour.setBackground(ColorUtils.getColor(cs.getMaxColour()));
119 minColour.setForeground(ColorUtils.getColor(cs.getMinColour()));
120 maxColour.setForeground(ColorUtils.getColor(cs.getMaxColour()));
121 colourFromLabel.setState(cs.isColourByLabel());
127 } catch (Exception ex)
130 threshold.select(cs.isAboveThreshold() ? 1 : (cs.isBelowThreshold() ? 2
135 colourFromLabel.addItemListener(this);
136 slider.addAdjustmentListener(this);
137 slider.addMouseListener(this);
138 owner = (af != null) ? af : fs.frame;
139 frame = new JVDialog(owner, MessageManager.formatMessage(
140 "label.graduated_color_for_params", new String[] { type }),
142 frame.setMainPanel(this);
144 frame.setVisible(true);
153 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
154 frame.setVisible(false);
158 public FeatureColourChooser()
163 } catch (Exception ex)
165 ex.printStackTrace();
169 private void jbInit() throws Exception
171 Label minLabel = new Label(MessageManager.getString("label.min")), maxLabel = new Label(
172 MessageManager.getString("label.max"));
173 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
174 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
175 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
176 // minColour.setLabel("Min Colour");
178 minColour.setBounds(0, 0, 40, 27);
179 maxColour.setBounds(0, 0, 40, 27);
180 minColour.addMouseListener(this);
182 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
183 maxColour.addMouseListener(this);
185 thresholdIsMin.addItemListener(this);
187 this.setLayout(new GridLayout(4, 1));
188 jPanel1.setLayout(new FlowLayout());
189 jPanel2.setLayout(new FlowLayout());
190 jPanel3.setLayout(new GridLayout(1, 1));
191 jPanel4.setLayout(new FlowLayout());
192 jPanel1.setBackground(Color.white);
193 jPanel2.setBackground(Color.white);
194 jPanel4.setBackground(Color.white);
195 threshold.addItemListener(this);
196 threshold.addItem(MessageManager
197 .getString("label.threshold_feature_no_thereshold"));
198 threshold.addItem(MessageManager
199 .getString("label.threshold_feature_above_thereshold"));
200 threshold.addItem(MessageManager
201 .getString("label.threshold_feature_below_thereshold"));
202 thresholdValue.addActionListener(this);
203 slider.setBackground(Color.white);
204 slider.setEnabled(false);
205 slider.setSize(new Dimension(93, 21));
206 thresholdValue.setEnabled(false);
207 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
208 // Rectangle(248, 2, 79,
210 thresholdValue.setColumns(5);
211 jPanel3.setBackground(Color.white);
213 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
214 colourFromLabel.setLabel(MessageManager
215 .getString("label.colour_by_label"));
216 colourFromLabel.setSize(new Dimension(139, 22));
217 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
218 thresholdIsMin.setBackground(Color.white);
219 thresholdIsMin.setLabel(MessageManager
220 .getString("label.threshold_minmax"));
221 thresholdIsMin.setSize(new Dimension(135, 23));
222 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
223 jPanel1.add(minLabel);
224 jPanel1.add(minColour);
225 jPanel1.add(maxLabel);
226 jPanel1.add(maxColour);
227 jPanel1.add(colourFromLabel);
228 jPanel2.add(threshold);
230 jPanel4.add(thresholdValue);
231 jPanel4.add(thresholdIsMin);
232 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
233 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
234 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
235 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
238 Panel minColour = new Panel();
240 Panel maxColour = new Panel();
242 Panel jPanel1 = new Panel();
244 Panel jPanel2 = new Panel();
246 Choice threshold = new Choice();
248 Panel jPanel3 = new Panel();
250 Panel jPanel4 = new Panel();
252 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
254 TextField thresholdValue = new TextField(20);
256 // BorderLayout borderLayout1 = new BorderLayout();
258 Checkbox thresholdIsMin = new Checkbox();
260 Checkbox colourFromLabel = new Checkbox();
262 private GraphLine threshline;
265 public void actionPerformed(ActionEvent evt)
267 if (evt.getSource() == thresholdValue)
271 float f = new Float(thresholdValue.getText()).floatValue();
272 slider.setValue((int) (f * 1000));
273 adjustmentValueChanged(null);
274 } catch (NumberFormatException ex)
278 else if (evt.getSource() == minColour)
280 minColour_actionPerformed(null);
282 else if (evt.getSource() == maxColour)
284 maxColour_actionPerformed(null);
293 public void itemStateChanged(ItemEvent evt)
295 maxColour.setEnabled(!colourFromLabel.getState());
296 minColour.setEnabled(!colourFromLabel.getState());
301 public void adjustmentValueChanged(AdjustmentEvent evt)
305 thresholdValue.setText((slider.getValue() / 1000f) + "");
310 protected void valueChanged()
312 threshline.value = slider.getValue() / 1000f;
313 cs.setThreshold(threshline.value);
315 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
316 // ap.paintAlignment(false);
319 public void minColour_actionPerformed(Color c)
323 UserDefinedColours udc = new UserDefinedColours(this,
324 minColour.getBackground(), owner,
325 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
329 minColour.setBackground(c);
330 minColour.setForeground(c);
337 public void maxColour_actionPerformed(Color newCol)
342 // UserDefinedColours udc = new UserDefinedColours(this,
343 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
344 UserDefinedColours udc = new UserDefinedColours(this,
345 maxColour.getBackground(), owner,
346 MessageManager.getString("label.select_colour_maximum_value"));
350 maxColour.setBackground(newCol);
351 maxColour.setForeground(newCol);
359 // Check if combobox is still adjusting
365 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
366 if (threshold.getSelectedIndex() == 1)
368 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
370 else if (threshold.getSelectedIndex() == 2)
372 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
375 slider.setEnabled(true);
376 thresholdValue.setEnabled(true);
377 FeatureColour acg = new FeatureColour(new Colour(
378 minColour.getBackground()), new Colour(
379 maxColour.getBackground()), min, max);
381 acg.setColourByLabel(colourFromLabel.getState());
382 maxColour.setEnabled(!colourFromLabel.getState());
383 minColour.setEnabled(!colourFromLabel.getState());
384 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
386 slider.setEnabled(false);
387 thresholdValue.setEnabled(false);
388 thresholdValue.setText("");
391 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
392 && threshline == null)
394 // todo visual indication of feature threshold
395 threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
396 "Threshold", Color.black);
399 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
402 acg.setThreshold(threshline.value);
404 float range = max * 1000f - min * 1000f;
406 slider.setMinimum((int) (min * 1000));
407 slider.setMaximum((int) (max * 1000));
408 slider.setValue((int) (threshline.value * 1000));
409 thresholdValue.setText(threshline.value + "");
410 slider.setEnabled(true);
411 thresholdValue.setEnabled(true);
415 acg.setAboveThreshold(true);
416 if (thresholdIsMin.getState()
417 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
419 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
421 acg = new FeatureColour(acg, threshline.value, max);
425 acg = new FeatureColour(acg, min, threshline.value);
429 fr.setColour(type, acg);
431 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
432 // ap.paintAlignment(false);
437 fr.setColour(type, oldcs);
438 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
439 // ap.paintAlignment(true);
444 public void mouseClicked(MouseEvent evt)
449 public void mousePressed(MouseEvent evt)
454 public void mouseReleased(MouseEvent evt)
456 if (evt.getSource() == minColour || evt.getSource() == maxColour)
459 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
463 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
465 // ap.paintAlignment(true);
469 public void mouseEntered(MouseEvent evt)
474 public void mouseExited(MouseEvent evt)