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.FeatureColour;
27 import jalview.util.MessageManager;
29 import java.awt.Checkbox;
30 import java.awt.Choice;
31 import java.awt.Color;
32 import java.awt.Dimension;
33 import java.awt.FlowLayout;
35 import java.awt.Frame;
36 import java.awt.GridLayout;
37 import java.awt.Label;
38 import java.awt.Panel;
39 import java.awt.Scrollbar;
40 import java.awt.TextField;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.AdjustmentEvent;
44 import java.awt.event.AdjustmentListener;
45 import java.awt.event.ItemEvent;
46 import java.awt.event.ItemListener;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseListener;
49 import java.util.Hashtable;
51 public class FeatureColourChooser extends Panel implements ActionListener,
52 AdjustmentListener, ItemListener, MouseListener
60 FeatureSettings fs = null;
68 Hashtable oldgroupColours;
70 boolean adjusting = false;
72 private float min, max;
76 private AlignFrame af = null;
78 public FeatureColourChooser(AlignFrame af, String type)
81 init(af.getSeqcanvas().getFeatureRenderer(), type);
84 public FeatureColourChooser(FeatureSettings fsettings, String type)
87 init(fsettings.fr, type);
88 // this.ap = fsettings.ap;
91 private void init(FeatureRenderer frenderer, String type)
95 float mm[] = fr.getMinMax().get(type)[0];
98 oldcs = fr.getFeatureColours().get(type);
99 if (oldcs.isGraduatedColour())
101 cs = new FeatureColour((FeatureColour) oldcs, min, max);
105 // promote original color to a graduated color
106 Color bl = Color.black;
107 if (oldcs.isSimpleColour())
109 bl = oldcs.getColour();
111 // original colour becomes the maximum colour
112 cs = new FeatureColour(Color.white, bl, mm[0], mm[1]);
114 minColour.setBackground(cs.getMinColour());
115 maxColour.setBackground(cs.getMaxColour());
116 minColour.setForeground(cs.getMinColour());
117 maxColour.setForeground(cs.getMaxColour());
118 colourFromLabel.setState(cs.isColourByLabel());
124 } catch (Exception ex)
127 threshold.select(cs.isAboveThreshold() ? 1 : (cs.isBelowThreshold() ? 2
132 colourFromLabel.addItemListener(this);
133 slider.addAdjustmentListener(this);
134 slider.addMouseListener(this);
135 owner = (af != null) ? af : fs.frame;
136 frame = new JVDialog(owner, MessageManager.formatMessage(
137 "label.graduated_color_for_params", new String[] { type }),
139 frame.setMainPanel(this);
141 frame.setVisible(true);
150 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
151 frame.setVisible(false);
155 public FeatureColourChooser()
160 } catch (Exception ex)
162 ex.printStackTrace();
166 private void jbInit() throws Exception
168 Label minLabel = new Label(MessageManager.getString("label.min")), maxLabel = new Label(
169 MessageManager.getString("label.max"));
170 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
171 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
172 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
173 // minColour.setLabel("Min Colour");
175 minColour.setBounds(0, 0, 40, 27);
176 maxColour.setBounds(0, 0, 40, 27);
177 minColour.addMouseListener(this);
179 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
180 maxColour.addMouseListener(this);
182 thresholdIsMin.addItemListener(this);
184 this.setLayout(new GridLayout(4, 1));
185 jPanel1.setLayout(new FlowLayout());
186 jPanel2.setLayout(new FlowLayout());
187 jPanel3.setLayout(new GridLayout(1, 1));
188 jPanel4.setLayout(new FlowLayout());
189 jPanel1.setBackground(Color.white);
190 jPanel2.setBackground(Color.white);
191 jPanel4.setBackground(Color.white);
192 threshold.addItemListener(this);
193 threshold.addItem(MessageManager
194 .getString("label.threshold_feature_no_threshold"));
195 threshold.addItem(MessageManager
196 .getString("label.threshold_feature_above_threshold"));
197 threshold.addItem(MessageManager
198 .getString("label.threshold_feature_below_threshold"));
199 thresholdValue.addActionListener(this);
200 slider.setBackground(Color.white);
201 slider.setEnabled(false);
202 slider.setSize(new Dimension(93, 21));
203 thresholdValue.setEnabled(false);
204 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
205 // Rectangle(248, 2, 79,
207 thresholdValue.setColumns(5);
208 jPanel3.setBackground(Color.white);
210 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
211 colourFromLabel.setLabel(MessageManager
212 .getString("label.colour_by_label"));
213 colourFromLabel.setSize(new Dimension(139, 22));
214 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
215 thresholdIsMin.setBackground(Color.white);
216 thresholdIsMin.setLabel(MessageManager
217 .getString("label.threshold_minmax"));
218 thresholdIsMin.setSize(new Dimension(135, 23));
219 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
220 jPanel1.add(minLabel);
221 jPanel1.add(minColour);
222 jPanel1.add(maxLabel);
223 jPanel1.add(maxColour);
224 jPanel1.add(colourFromLabel);
225 jPanel2.add(threshold);
227 jPanel4.add(thresholdValue);
228 jPanel4.add(thresholdIsMin);
229 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
230 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
231 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
232 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
235 Panel minColour = new Panel();
237 Panel maxColour = new Panel();
239 Panel jPanel1 = new Panel();
241 Panel jPanel2 = new Panel();
243 Choice threshold = new Choice();
245 Panel jPanel3 = new Panel();
247 Panel jPanel4 = new Panel();
249 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
251 TextField thresholdValue = new TextField(20);
253 // BorderLayout borderLayout1 = new BorderLayout();
255 Checkbox thresholdIsMin = new Checkbox();
257 Checkbox colourFromLabel = new Checkbox();
259 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);
290 public void itemStateChanged(ItemEvent evt)
292 maxColour.setEnabled(!colourFromLabel.getState());
293 minColour.setEnabled(!colourFromLabel.getState());
298 public void adjustmentValueChanged(AdjustmentEvent evt)
302 thresholdValue.setText((slider.getValue() / 1000f) + "");
307 protected void valueChanged()
309 threshline.value = slider.getValue() / 1000f;
310 cs.setThreshold(threshline.value);
312 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
313 // ap.paintAlignment(false);
316 public void minColour_actionPerformed(Color newCol)
320 UserDefinedColours udc = new UserDefinedColours(this,
321 minColour.getBackground(), owner,
322 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
326 minColour.setBackground(newCol);
327 minColour.setForeground(newCol);
334 public void maxColour_actionPerformed(Color newCol)
339 // UserDefinedColours udc = new UserDefinedColours(this,
340 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
341 UserDefinedColours udc = new UserDefinedColours(this,
342 maxColour.getBackground(), owner,
343 MessageManager.getString("label.select_colour_maximum_value"));
347 maxColour.setBackground(newCol);
348 maxColour.setForeground(newCol);
356 // Check if combobox is still adjusting
362 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
363 if (threshold.getSelectedIndex() == 1)
365 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
367 else if (threshold.getSelectedIndex() == 2)
369 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
372 slider.setEnabled(true);
373 thresholdValue.setEnabled(true);
374 FeatureColour acg = new FeatureColour(minColour.getBackground(),
375 maxColour.getBackground(), min, max);
377 acg.setColourByLabel(colourFromLabel.getState());
378 maxColour.setEnabled(!colourFromLabel.getState());
379 minColour.setEnabled(!colourFromLabel.getState());
380 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
382 slider.setEnabled(false);
383 thresholdValue.setEnabled(false);
384 thresholdValue.setText("");
387 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
388 && threshline == null)
390 // todo visual indication of feature threshold
391 threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
392 "Threshold", Color.black);
395 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
398 acg.setThreshold(threshline.value);
400 float range = max * 1000f - min * 1000f;
402 slider.setMinimum((int) (min * 1000));
403 slider.setMaximum((int) (max * 1000));
404 slider.setValue((int) (threshline.value * 1000));
405 thresholdValue.setText(threshline.value + "");
406 slider.setEnabled(true);
407 thresholdValue.setEnabled(true);
411 acg.setAboveThreshold(true);
412 if (thresholdIsMin.getState()
413 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
415 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
417 acg = new FeatureColour(acg, threshline.value, max);
421 acg = new FeatureColour(acg, min, threshline.value);
425 fr.setColour(type, acg);
427 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
428 // ap.paintAlignment(false);
433 fr.setColour(type, oldcs);
434 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
435 // ap.paintAlignment(true);
440 public void mouseClicked(MouseEvent evt)
445 public void mousePressed(MouseEvent evt)
450 public void mouseReleased(MouseEvent evt)
452 if (evt.getSource() == minColour || evt.getSource() == maxColour)
455 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
459 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
461 // ap.paintAlignment(true);
465 public void mouseEntered(MouseEvent evt)
470 public void mouseExited(MouseEvent evt)