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 javax.swing.JCheckBox;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.FlowLayout;
33 import javax.swing.JFrame;
34 import java.awt.GridLayout;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.JScrollBar;
38 import javax.swing.JTextField;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.AdjustmentEvent;
42 import java.awt.event.AdjustmentListener;
43 import java.awt.event.ItemEvent;
44 import java.awt.event.ItemListener;
45 import java.awt.event.MouseEvent;
46 import java.awt.event.MouseListener;
47 import java.util.Hashtable;
49 public class FeatureColourChooser extends JPanel implements ActionListener,
50 AdjustmentListener, ItemListener, MouseListener
58 FeatureSettings fs = null;
66 Hashtable oldgroupColours;
68 boolean adjusting = false;
70 private float min, max;
74 private AlignFrame af = null;
76 public FeatureColourChooser(AlignFrame af, String type)
79 init(af.getSeqcanvas().getFeatureRenderer(), type);
82 public FeatureColourChooser(FeatureSettings fsettings, String type)
85 init(fsettings.fr, type);
86 // this.ap = fsettings.ap;
89 private void init(FeatureRenderer frenderer, String type)
93 float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
96 oldcs = fr.getFeatureColours().get(type);
97 if (oldcs instanceof GraduatedColor)
99 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
103 // promote original color to a graduated color
104 Color bl = Color.black;
105 if (oldcs instanceof Color)
109 // original colour becomes the maximum colour
110 cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
112 minColour.setBackground(cs.getMinColor());
113 maxColour.setBackground(cs.getMaxColor());
114 minColour.setForeground(cs.getMinColor());
115 maxColour.setForeground(cs.getMaxColor());
116 colourFromLabel.setSelected(cs.isColourByLabel());
122 } catch (Exception ex)
126 .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
127 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
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[]
138 { type }), true, 480, 248);
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 JLabel minLabel = new JLabel(MessageManager.getString("label.min")), maxLabel = new JLabel(
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_thereshold"));
195 threshold.addItem(MessageManager
196 .getString("label.threshold_feature_above_thereshold"));
197 threshold.addItem(MessageManager
198 .getString("label.threshold_feature_below_thereshold"));
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 JPanel minColour = new JPanel();
237 JPanel maxColour = new JPanel();
239 JPanel jPanel1 = new JPanel();
241 JPanel jPanel2 = new JPanel();
243 Choice threshold = new Choice();
245 JPanel jPanel3 = new JPanel();
247 JPanel jPanel4 = new JPanel();
249 JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL);
251 JTextField thresholdValue = new JTextField(20);
253 // BorderLayout borderLayout1 = new BorderLayout();
255 JCheckBox thresholdIsMin = new JCheckBox();
257 JCheckBox colourFromLabel = new JCheckBox();
259 private GraphLine threshline;
261 public void actionPerformed(ActionEvent evt)
263 if (evt.getSource() == thresholdValue)
267 float f = new Float(thresholdValue.getText()).floatValue();
268 slider.setValue((int) (f * 1000));
269 adjustmentValueChanged(null);
270 } catch (NumberFormatException ex)
274 else if (evt.getSource() == minColour)
276 minColour_actionPerformed(null);
278 else if (evt.getSource() == maxColour)
280 maxColour_actionPerformed(null);
288 public void itemStateChanged(ItemEvent evt)
290 maxColour.setEnabled(!colourFromLabel.isSelected());
291 minColour.setEnabled(!colourFromLabel.isSelected());
295 public void adjustmentValueChanged(AdjustmentEvent evt)
299 thresholdValue.setText((slider.getValue() / 1000f) + "");
304 protected void valueChanged()
306 threshline.value = slider.getValue() / 1000f;
307 cs.setThresh(threshline.value);
309 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
310 // ap.paintAlignment(false);
313 public void minColour_actionPerformed(Color newCol)
317 UserDefinedColours udc = new UserDefinedColours(this,
318 minColour.getBackground(), owner,
319 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
323 minColour.setBackground(newCol);
324 minColour.setForeground(newCol);
331 public void maxColour_actionPerformed(Color newCol)
336 // UserDefinedColours udc = new UserDefinedColours(this,
337 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
338 UserDefinedColours udc = new UserDefinedColours(this,
339 maxColour.getBackground(), owner,
340 MessageManager.getString("label.select_colour_maximum_value"));
344 maxColour.setBackground(newCol);
345 maxColour.setForeground(newCol);
353 // Check if combobox is still adjusting
359 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
360 if (threshold.getSelectedIndex() == 1)
362 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
364 else if (threshold.getSelectedIndex() == 2)
366 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
369 slider.setEnabled(true);
370 thresholdValue.setEnabled(true);
371 GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
372 maxColour.getBackground(), min, max);
374 acg.setColourByLabel(colourFromLabel.isSelected());
375 maxColour.setEnabled(!colourFromLabel.isSelected());
376 minColour.setEnabled(!colourFromLabel.isSelected());
377 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
379 slider.setEnabled(false);
380 thresholdValue.setEnabled(false);
381 thresholdValue.setText("");
384 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
385 && threshline == null)
387 // todo visual indication of feature threshold
388 threshline = new GraphLine((max - min) / 2f,
389 "Threshold", Color.black);
392 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
395 acg.setThresh(threshline.value);
397 float range = max * 1000f - min * 1000f;
399 slider.setMinimum((int) (min * 1000));
400 slider.setMaximum((int) (max * 1000));
401 slider.setValue((int) (threshline.value * 1000));
402 thresholdValue.setText(threshline.value + "");
403 slider.setEnabled(true);
404 thresholdValue.setEnabled(true);
408 acg.setThreshType(aboveThreshold);
409 if (thresholdIsMin.isSelected()
410 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
412 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
414 acg = new GraduatedColor(acg, threshline.value, max);
418 acg = new GraduatedColor(acg, min, threshline.value);
422 fr.setColour(type, acg);
424 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
425 // ap.paintAlignment(false);
430 fr.setColour(type, oldcs);
431 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
432 // ap.paintAlignment(true);
436 public void mouseClicked(MouseEvent evt)
440 public void mousePressed(MouseEvent evt)
444 public void mouseReleased(MouseEvent evt)
446 if (evt.getSource() == minColour || evt.getSource() == maxColour)
449 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
453 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
455 // ap.paintAlignment(true);
458 public void mouseEntered(MouseEvent evt)
462 public void mouseExited(MouseEvent evt)