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;
26 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.util.MessageManager;
32 public class FeatureColourChooser extends Panel implements ActionListener,
33 AdjustmentListener, ItemListener, MouseListener
41 FeatureSettings fs = null;
49 Hashtable oldgroupColours;
51 boolean adjusting = false;
53 private float min, max;
57 private AlignFrame af = null;
59 public FeatureColourChooser(AlignFrame af, String type)
62 init(af.getSeqcanvas().getFeatureRenderer(), type);
65 public FeatureColourChooser(FeatureSettings fsettings, String type)
68 init(fsettings.fr, type);
69 // this.ap = fsettings.ap;
72 private void init(FeatureRenderer frenderer, String type)
76 float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
79 oldcs = fr.getFeatureColours().get(type);
80 if (oldcs instanceof GraduatedColor)
82 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
86 // promote original color to a graduated color
87 Color bl = Color.black;
88 if (oldcs instanceof Color)
92 // original colour becomes the maximum colour
93 cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
95 minColour.setBackground(cs.getMinColor());
96 maxColour.setBackground(cs.getMaxColor());
97 minColour.setForeground(cs.getMinColor());
98 maxColour.setForeground(cs.getMaxColor());
99 colourFromLabel.setState(cs.isColourByLabel());
105 } catch (Exception ex)
109 .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
110 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
115 colourFromLabel.addItemListener(this);
116 slider.addAdjustmentListener(this);
117 slider.addMouseListener(this);
118 owner = (af != null) ? af : fs.frame;
119 frame = new JVDialog(owner, MessageManager.formatMessage(
120 "label.graduated_color_for_params", new String[]
121 { type }), true, 480, 248);
122 frame.setMainPanel(this);
124 frame.setVisible(true);
133 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
134 frame.setVisible(false);
138 public FeatureColourChooser()
143 } catch (Exception ex)
145 ex.printStackTrace();
149 private void jbInit() throws Exception
151 Label minLabel = new Label(MessageManager.getString("label.min")), maxLabel = new Label(
152 MessageManager.getString("label.max"));
153 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
154 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
155 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
156 // minColour.setLabel("Min Colour");
158 minColour.setBounds(0, 0, 40, 27);
159 maxColour.setBounds(0, 0, 40, 27);
160 minColour.addMouseListener(this);
162 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
163 maxColour.addMouseListener(this);
165 thresholdIsMin.addItemListener(this);
167 this.setLayout(new GridLayout(4, 1));
168 jPanel1.setLayout(new FlowLayout());
169 jPanel2.setLayout(new FlowLayout());
170 jPanel3.setLayout(new GridLayout(1, 1));
171 jPanel4.setLayout(new FlowLayout());
172 jPanel1.setBackground(Color.white);
173 jPanel2.setBackground(Color.white);
174 jPanel4.setBackground(Color.white);
175 threshold.addItemListener(this);
176 threshold.addItem(MessageManager
177 .getString("label.threshold_feature_no_thereshold"));
178 threshold.addItem(MessageManager
179 .getString("label.threshold_feature_above_thereshold"));
180 threshold.addItem(MessageManager
181 .getString("label.threshold_feature_below_thereshold"));
182 thresholdValue.addActionListener(this);
183 slider.setBackground(Color.white);
184 slider.setEnabled(false);
185 slider.setSize(new Dimension(93, 21));
186 thresholdValue.setEnabled(false);
187 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
188 // Rectangle(248, 2, 79,
190 thresholdValue.setColumns(5);
191 jPanel3.setBackground(Color.white);
193 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
194 colourFromLabel.setLabel(MessageManager
195 .getString("label.colour_by_label"));
196 colourFromLabel.setSize(new Dimension(139, 22));
197 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
198 thresholdIsMin.setBackground(Color.white);
199 thresholdIsMin.setLabel(MessageManager
200 .getString("label.threshold_minmax"));
201 thresholdIsMin.setSize(new Dimension(135, 23));
202 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
203 jPanel1.add(minLabel);
204 jPanel1.add(minColour);
205 jPanel1.add(maxLabel);
206 jPanel1.add(maxColour);
207 jPanel1.add(colourFromLabel);
208 jPanel2.add(threshold);
210 jPanel4.add(thresholdValue);
211 jPanel4.add(thresholdIsMin);
212 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
213 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
214 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
215 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
218 Panel minColour = new Panel();
220 Panel maxColour = new Panel();
222 Panel jPanel1 = new Panel();
224 Panel jPanel2 = new Panel();
226 Choice threshold = new Choice();
228 Panel jPanel3 = new Panel();
230 Panel jPanel4 = new Panel();
232 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
234 TextField thresholdValue = new TextField(20);
236 // BorderLayout borderLayout1 = new BorderLayout();
238 Checkbox thresholdIsMin = new Checkbox();
240 Checkbox colourFromLabel = new Checkbox();
242 private GraphLine threshline;
244 public void actionPerformed(ActionEvent evt)
246 if (evt.getSource() == thresholdValue)
250 float f = new Float(thresholdValue.getText()).floatValue();
251 slider.setValue((int) (f * 1000));
252 adjustmentValueChanged(null);
253 } catch (NumberFormatException ex)
257 else if (evt.getSource() == minColour)
259 minColour_actionPerformed(null);
261 else if (evt.getSource() == maxColour)
263 maxColour_actionPerformed(null);
271 public void itemStateChanged(ItemEvent evt)
273 maxColour.setEnabled(!colourFromLabel.getState());
274 minColour.setEnabled(!colourFromLabel.getState());
278 public void adjustmentValueChanged(AdjustmentEvent evt)
282 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
287 protected void valueChanged()
289 threshline.value = (float) slider.getValue() / 1000f;
290 cs.setThresh(threshline.value);
292 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
293 // ap.paintAlignment(false);
296 public void minColour_actionPerformed(Color newCol)
300 UserDefinedColours udc = new UserDefinedColours(this,
301 minColour.getBackground(), owner,
302 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
306 minColour.setBackground(newCol);
307 minColour.setForeground(newCol);
314 public void maxColour_actionPerformed(Color newCol)
319 // UserDefinedColours udc = new UserDefinedColours(this,
320 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
321 UserDefinedColours udc = new UserDefinedColours(this,
322 maxColour.getBackground(), owner,
323 MessageManager.getString("label.select_colour_maximum_value"));
327 maxColour.setBackground(newCol);
328 maxColour.setForeground(newCol);
336 // Check if combobox is still adjusting
342 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
343 if (threshold.getSelectedIndex() == 1)
345 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
347 else if (threshold.getSelectedIndex() == 2)
349 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
352 slider.setEnabled(true);
353 thresholdValue.setEnabled(true);
354 GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
355 maxColour.getBackground(), min, max);
357 acg.setColourByLabel(colourFromLabel.getState());
358 maxColour.setEnabled(!colourFromLabel.getState());
359 minColour.setEnabled(!colourFromLabel.getState());
360 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
362 slider.setEnabled(false);
363 thresholdValue.setEnabled(false);
364 thresholdValue.setText("");
367 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
368 && threshline == null)
370 // todo visual indication of feature threshold
371 threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
372 "Threshold", Color.black);
375 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
378 acg.setThresh(threshline.value);
380 float range = max * 1000f - min * 1000f;
382 slider.setMinimum((int) (min * 1000));
383 slider.setMaximum((int) (max * 1000));
384 slider.setValue((int) (threshline.value * 1000));
385 thresholdValue.setText(threshline.value + "");
386 slider.setEnabled(true);
387 thresholdValue.setEnabled(true);
391 acg.setThreshType(aboveThreshold);
392 if (thresholdIsMin.getState()
393 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
395 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
397 acg = new GraduatedColor(acg, threshline.value, max);
401 acg = new GraduatedColor(acg, min, threshline.value);
405 fr.setColour(type, acg);
407 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
408 // ap.paintAlignment(false);
413 fr.setColour(type, oldcs);
414 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
415 // ap.paintAlignment(true);
419 public void mouseClicked(MouseEvent evt)
423 public void mousePressed(MouseEvent evt)
427 public void mouseReleased(MouseEvent evt)
429 if (evt.getSource() == minColour || evt.getSource() == maxColour)
432 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
436 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
438 // ap.paintAlignment(true);
441 public void mouseEntered(MouseEvent evt)
445 public void mouseExited(MouseEvent evt)