2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import jalview.util.MessageManager;
30 public class FeatureColourChooser extends Panel implements ActionListener,
31 AdjustmentListener, ItemListener, MouseListener
39 FeatureSettings fs = null;
47 Hashtable oldgroupColours;
49 boolean adjusting = false;
51 private float min, max;
55 private AlignFrame af = null;
57 public FeatureColourChooser(AlignFrame af, String type)
60 init(af.getSeqcanvas().getFeatureRenderer(), type);
63 public FeatureColourChooser(FeatureSettings fsettings, String type)
66 init(fsettings.fr, type);
67 // this.ap = fsettings.ap;
70 private void init(FeatureRenderer frenderer, String type)
74 float mm[] = ((float[][]) fr.minmax.get(type))[0];
77 oldcs = fr.featureColours.get(type);
78 if (oldcs instanceof GraduatedColor)
80 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
84 // promote original color to a graduated color
85 Color bl = Color.black;
86 if (oldcs instanceof Color)
90 // original colour becomes the maximum colour
91 cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
93 minColour.setBackground(cs.getMinColor());
94 maxColour.setBackground(cs.getMaxColor());
95 minColour.setForeground(cs.getMinColor());
96 maxColour.setForeground(cs.getMaxColor());
97 colourFromLabel.setState(cs.isColourByLabel());
103 } catch (Exception ex)
107 .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
108 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
113 colourFromLabel.addItemListener(this);
114 slider.addAdjustmentListener(this);
115 slider.addMouseListener(this);
116 owner = (af != null) ? af : fs.frame;
117 frame = new JVDialog(owner, MessageManager.formatMessage("label.graduated_color_for_params", new String[]{type}),
119 frame.setMainPanel(this);
121 frame.setVisible(true);
130 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
131 frame.setVisible(false);
135 public FeatureColourChooser()
140 } catch (Exception ex)
142 ex.printStackTrace();
146 private void jbInit() throws Exception
148 Label minLabel = new Label(MessageManager.getString("label.min")), maxLabel = new Label(MessageManager.getString("label.max"));
149 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
150 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
151 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
152 // minColour.setLabel("Min Colour");
154 minColour.setBounds(0, 0, 40, 27);
155 maxColour.setBounds(0, 0, 40, 27);
156 minColour.addMouseListener(this);
158 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
159 maxColour.addMouseListener(this);
161 thresholdIsMin.addItemListener(this);
163 this.setLayout(new GridLayout(4, 1));
164 jPanel1.setLayout(new FlowLayout());
165 jPanel2.setLayout(new FlowLayout());
166 jPanel3.setLayout(new GridLayout(1, 1));
167 jPanel4.setLayout(new FlowLayout());
168 jPanel1.setBackground(Color.white);
169 jPanel2.setBackground(Color.white);
170 jPanel4.setBackground(Color.white);
171 threshold.addItemListener(this);
172 threshold.addItem(MessageManager.getString("label.threshold_feature_no_thereshold"));
173 threshold.addItem(MessageManager.getString("label.threshold_feature_above_thereshold"));
174 threshold.addItem(MessageManager.getString("label.threshold_feature_below_thereshold"));
175 thresholdValue.addActionListener(this);
176 slider.setBackground(Color.white);
177 slider.setEnabled(false);
178 slider.setSize(new Dimension(93, 21));
179 thresholdValue.setEnabled(false);
180 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
181 // Rectangle(248, 2, 79,
183 thresholdValue.setColumns(5);
184 jPanel3.setBackground(Color.white);
186 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
187 colourFromLabel.setLabel(MessageManager.getString("label.colour_by_label"));
188 colourFromLabel.setSize(new Dimension(139, 22));
189 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
190 thresholdIsMin.setBackground(Color.white);
191 thresholdIsMin.setLabel(MessageManager.getString("label.threshold_minmax"));
192 thresholdIsMin.setSize(new Dimension(135, 23));
193 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
194 jPanel1.add(minLabel);
195 jPanel1.add(minColour);
196 jPanel1.add(maxLabel);
197 jPanel1.add(maxColour);
198 jPanel1.add(colourFromLabel);
199 jPanel2.add(threshold);
201 jPanel4.add(thresholdValue);
202 jPanel4.add(thresholdIsMin);
203 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
204 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
205 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
206 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
209 Panel minColour = new Panel();
211 Panel maxColour = new Panel();
213 Panel jPanel1 = new Panel();
215 Panel jPanel2 = new Panel();
217 Choice threshold = new Choice();
219 Panel jPanel3 = new Panel();
221 Panel jPanel4 = new Panel();
223 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
225 TextField thresholdValue = new TextField(20);
227 // BorderLayout borderLayout1 = new BorderLayout();
229 Checkbox thresholdIsMin = new Checkbox();
231 Checkbox colourFromLabel = new Checkbox();
233 private GraphLine threshline;
235 public void actionPerformed(ActionEvent evt)
237 if (evt.getSource() == thresholdValue)
241 float f = new Float(thresholdValue.getText()).floatValue();
242 slider.setValue((int) (f * 1000));
243 adjustmentValueChanged(null);
244 } catch (NumberFormatException ex)
248 else if (evt.getSource() == minColour)
250 minColour_actionPerformed(null);
252 else if (evt.getSource() == maxColour)
254 maxColour_actionPerformed(null);
262 public void itemStateChanged(ItemEvent evt)
264 maxColour.setEnabled(!colourFromLabel.getState());
265 minColour.setEnabled(!colourFromLabel.getState());
269 public void adjustmentValueChanged(AdjustmentEvent evt)
273 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
278 protected void valueChanged()
280 threshline.value = (float) slider.getValue() / 1000f;
281 cs.setThresh(threshline.value);
283 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
284 // ap.paintAlignment(false);
287 public void minColour_actionPerformed(Color newCol)
291 UserDefinedColours udc = new UserDefinedColours(this,
292 minColour.getBackground(), owner,
293 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
297 minColour.setBackground(newCol);
298 minColour.setForeground(newCol);
305 public void maxColour_actionPerformed(Color newCol)
310 // UserDefinedColours udc = new UserDefinedColours(this,
311 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
312 UserDefinedColours udc = new UserDefinedColours(this,
313 maxColour.getBackground(), owner,
314 MessageManager.getString("label.select_colour_maximum_value"));
318 maxColour.setBackground(newCol);
319 maxColour.setForeground(newCol);
327 // Check if combobox is still adjusting
333 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
334 if (threshold.getSelectedIndex()==1)
336 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
338 else if (threshold.getSelectedIndex()==2)
340 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
343 slider.setEnabled(true);
344 thresholdValue.setEnabled(true);
345 GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
346 maxColour.getBackground(), min, max);
348 acg.setColourByLabel(colourFromLabel.getState());
349 maxColour.setEnabled(!colourFromLabel.getState());
350 minColour.setEnabled(!colourFromLabel.getState());
351 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
353 slider.setEnabled(false);
354 thresholdValue.setEnabled(false);
355 thresholdValue.setText("");
358 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
359 && threshline == null)
361 // todo visual indication of feature threshold
362 threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
363 "Threshold", Color.black);
366 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
369 acg.setThresh(threshline.value);
371 float range = max * 1000f - min * 1000f;
373 slider.setMinimum((int) (min * 1000));
374 slider.setMaximum((int) (max * 1000));
375 slider.setValue((int) (threshline.value * 1000));
376 thresholdValue.setText(threshline.value + "");
377 slider.setEnabled(true);
378 thresholdValue.setEnabled(true);
382 acg.setThreshType(aboveThreshold);
383 if (thresholdIsMin.getState()
384 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
386 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
388 acg = new GraduatedColor(acg, threshline.value, max);
392 acg = new GraduatedColor(acg, min, threshline.value);
396 fr.featureColours.put(type, acg);
398 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
399 // ap.paintAlignment(false);
404 fr.featureColours.put(type, oldcs);
405 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
406 // ap.paintAlignment(true);
410 public void mouseClicked(MouseEvent evt)
414 public void mousePressed(MouseEvent evt)
418 public void mouseReleased(MouseEvent evt)
420 if (evt.getSource() == minColour || evt.getSource() == maxColour)
423 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
427 PaintRefresher.Refresh(this, fr.av.getSequenceSetId());
429 // ap.paintAlignment(true);
432 public void mouseEntered(MouseEvent evt)
436 public void mouseExited(MouseEvent evt)