2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.datamodel.GraphLine;
\r
24 import jalview.schemes.AnnotationColourGradient;
\r
25 import jalview.schemes.GraduatedColor;
\r
26 import jalview.util.MessageManager;
\r
28 import javax.swing.JCheckBox;
\r
29 import java.awt.Color;
\r
30 import java.awt.Dimension;
\r
31 import java.awt.FlowLayout;
\r
32 import java.awt.Font;
\r
33 import javax.swing.JFrame;
\r
34 import java.awt.GridLayout;
\r
35 import javax.swing.JLabel;
\r
36 import javax.swing.JPanel;
\r
37 import javax.swing.JScrollBar;
\r
38 import javax.swing.JTextField;
\r
39 import java.awt.event.ActionEvent;
\r
40 import java.awt.event.ActionListener;
\r
41 import java.awt.event.AdjustmentEvent;
\r
42 import java.awt.event.AdjustmentListener;
\r
43 import java.awt.event.ItemEvent;
\r
44 import java.awt.event.ItemListener;
\r
45 import java.awt.event.MouseEvent;
\r
46 import java.awt.event.MouseListener;
\r
47 import java.util.Hashtable;
\r
49 public class FeatureColourChooser extends JPanel implements ActionListener,
\r
50 AdjustmentListener, ItemListener, MouseListener
\r
58 FeatureSettings fs = null;
\r
60 // AlignmentPanel ap;
\r
66 Hashtable oldgroupColours;
\r
68 boolean adjusting = false;
\r
70 private float min, max;
\r
74 private AlignFrame af = null;
\r
76 public FeatureColourChooser(AlignFrame af, String type)
\r
79 init(af.getSeqcanvas().getFeatureRenderer(), type);
\r
82 public FeatureColourChooser(FeatureSettings fsettings, String type)
\r
84 this.fs = fsettings;
\r
85 init(fsettings.fr, type);
\r
86 // this.ap = fsettings.ap;
\r
89 private void init(FeatureRenderer frenderer, String type)
\r
93 float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
\r
96 oldcs = fr.getFeatureColours().get(type);
\r
97 if (oldcs instanceof GraduatedColor)
\r
99 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
\r
103 // promote original color to a graduated color
\r
104 Color bl = Color.black;
\r
105 if (oldcs instanceof Color)
\r
107 bl = (Color) oldcs;
\r
109 // original colour becomes the maximum colour
\r
110 cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
\r
112 minColour.setBackground(cs.getMinColor());
\r
113 maxColour.setBackground(cs.getMaxColor());
\r
114 minColour.setForeground(cs.getMinColor());
\r
115 maxColour.setForeground(cs.getMaxColor());
\r
116 colourFromLabel.setSelected(cs.isColourByLabel());
\r
122 } catch (Exception ex)
\r
126 .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
\r
127 : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
\r
132 colourFromLabel.addItemListener(this);
\r
133 slider.addAdjustmentListener(this);
\r
134 slider.addMouseListener(this);
\r
135 owner = (af != null) ? af : fs.frame;
\r
136 frame = new JVDialog(owner, MessageManager.formatMessage(
\r
137 "label.graduated_color_for_params", new String[]
\r
138 { type }), true, 480, 248);
\r
139 frame.setMainPanel(this);
\r
141 frame.setVisible(true);
\r
150 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
\r
151 frame.setVisible(false);
\r
155 public FeatureColourChooser()
\r
160 } catch (Exception ex)
\r
162 ex.printStackTrace();
\r
166 private void jbInit() throws Exception
\r
168 JLabel minLabel = new JLabel(MessageManager.getString("label.min")), maxLabel = new JLabel(
\r
169 MessageManager.getString("label.max"));
\r
170 minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
171 maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
172 // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
173 // minColour.setLabel("Min Colour");
\r
175 minColour.setBounds(0, 0, 40, 27);
\r
176 maxColour.setBounds(0, 0, 40, 27);
\r
177 minColour.addMouseListener(this);
\r
179 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
180 maxColour.addMouseListener(this);
\r
182 thresholdIsMin.addItemListener(this);
\r
184 this.setLayout(new GridLayout(4, 1));
\r
185 jPanel1.setLayout(new FlowLayout());
\r
186 jPanel2.setLayout(new FlowLayout());
\r
187 jPanel3.setLayout(new GridLayout(1, 1));
\r
188 jPanel4.setLayout(new FlowLayout());
\r
189 jPanel1.setBackground(Color.white);
\r
190 jPanel2.setBackground(Color.white);
\r
191 jPanel4.setBackground(Color.white);
\r
192 threshold.addItemListener(this);
\r
193 threshold.addItem(MessageManager
\r
194 .getString("label.threshold_feature_no_thereshold"));
\r
195 threshold.addItem(MessageManager
\r
196 .getString("label.threshold_feature_above_thereshold"));
\r
197 threshold.addItem(MessageManager
\r
198 .getString("label.threshold_feature_below_thereshold"));
\r
199 thresholdValue.addActionListener(this);
\r
200 slider.setBackground(Color.white);
\r
201 slider.setEnabled(false);
\r
202 slider.setSize(new Dimension(93, 21));
\r
203 thresholdValue.setEnabled(false);
\r
204 thresholdValue.setSize(new Dimension(79, 22)); // setBounds(new
\r
205 // Rectangle(248, 2, 79,
\r
207 thresholdValue.setColumns(5);
\r
208 jPanel3.setBackground(Color.white);
\r
210 colourFromLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
211 colourFromLabel.setLabel(MessageManager
\r
212 .getString("label.colour_by_label"));
\r
213 colourFromLabel.setSize(new Dimension(139, 22));
\r
214 // threshold.setBounds(new Rectangle(11, 3, 139, 22));
\r
215 thresholdIsMin.setBackground(Color.white);
\r
216 thresholdIsMin.setLabel(MessageManager
\r
217 .getString("label.threshold_minmax"));
\r
218 thresholdIsMin.setSize(new Dimension(135, 23));
\r
219 // thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
\r
220 jPanel1.add(minLabel);
\r
221 jPanel1.add(minColour);
\r
222 jPanel1.add(maxLabel);
\r
223 jPanel1.add(maxColour);
\r
224 jPanel1.add(colourFromLabel);
\r
225 jPanel2.add(threshold);
\r
226 jPanel3.add(slider);
\r
227 jPanel4.add(thresholdValue);
\r
228 jPanel4.add(thresholdIsMin);
\r
229 this.add(jPanel1);// , java.awt.BorderLayout.NORTH);
\r
230 this.add(jPanel2);// , java.awt.BorderLayout.NORTH);
\r
231 this.add(jPanel3);// , java.awt.BorderLayout.CENTER);
\r
232 this.add(jPanel4);// , java.awt.BorderLayout.CENTER);
\r
235 JPanel minColour = new JPanel();
\r
237 JPanel maxColour = new JPanel();
\r
239 JPanel jPanel1 = new JPanel();
\r
241 JPanel jPanel2 = new JPanel();
\r
243 Choice threshold = new Choice();
\r
245 JPanel jPanel3 = new JPanel();
\r
247 JPanel jPanel4 = new JPanel();
\r
249 JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL);
\r
251 JTextField thresholdValue = new JTextField(20);
\r
253 // BorderLayout borderLayout1 = new BorderLayout();
\r
255 JCheckBox thresholdIsMin = new JCheckBox();
\r
257 JCheckBox colourFromLabel = new JCheckBox();
\r
259 private GraphLine threshline;
\r
261 public void actionPerformed(ActionEvent evt)
\r
263 if (evt.getSource() == thresholdValue)
\r
267 float f = new Float(thresholdValue.getText()).floatValue();
\r
268 slider.setValue((int) (f * 1000));
\r
269 adjustmentValueChanged(null);
\r
270 } catch (NumberFormatException ex)
\r
274 else if (evt.getSource() == minColour)
\r
276 minColour_actionPerformed(null);
\r
278 else if (evt.getSource() == maxColour)
\r
280 maxColour_actionPerformed(null);
\r
288 public void itemStateChanged(ItemEvent evt)
\r
290 maxColour.setEnabled(!colourFromLabel.isSelected());
\r
291 minColour.setEnabled(!colourFromLabel.isSelected());
\r
295 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
299 thresholdValue.setText((slider.getValue() / 1000f) + "");
\r
304 protected void valueChanged()
\r
306 threshline.value = slider.getValue() / 1000f;
\r
307 cs.setThresh(threshline.value);
\r
309 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
\r
310 // ap.paintAlignment(false);
\r
313 public void minColour_actionPerformed(Color newCol)
\r
315 if (newCol == null)
\r
317 UserDefinedColours udc = new UserDefinedColours(this,
\r
318 minColour.getBackground(), owner,
\r
319 MessageManager.getString("label.select_colour_minimum_value")); // frame.owner,
\r
323 minColour.setBackground(newCol);
\r
324 minColour.setForeground(newCol);
\r
325 minColour.repaint();
\r
331 public void maxColour_actionPerformed(Color newCol)
\r
333 if (newCol == null)
\r
336 // UserDefinedColours udc = new UserDefinedColours(this,
\r
337 // "Select Colour for Maximum Value",maxColour.getBackground(),true);
\r
338 UserDefinedColours udc = new UserDefinedColours(this,
\r
339 maxColour.getBackground(), owner,
\r
340 MessageManager.getString("label.select_colour_maximum_value"));
\r
344 maxColour.setBackground(newCol);
\r
345 maxColour.setForeground(newCol);
\r
346 maxColour.repaint();
\r
351 void changeColour()
\r
353 // Check if combobox is still adjusting
\r
359 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
\r
360 if (threshold.getSelectedIndex() == 1)
\r
362 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
364 else if (threshold.getSelectedIndex() == 2)
\r
366 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
369 slider.setEnabled(true);
\r
370 thresholdValue.setEnabled(true);
\r
371 GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
\r
372 maxColour.getBackground(), min, max);
\r
374 acg.setColourByLabel(colourFromLabel.isSelected());
\r
375 maxColour.setEnabled(!colourFromLabel.isSelected());
\r
376 minColour.setEnabled(!colourFromLabel.isSelected());
\r
377 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
379 slider.setEnabled(false);
\r
380 thresholdValue.setEnabled(false);
\r
381 thresholdValue.setText("");
\r
384 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
\r
385 && threshline == null)
\r
387 // todo visual indication of feature threshold
\r
388 threshline = new GraphLine((max - min) / 2f,
\r
389 "Threshold", Color.black);
\r
392 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
395 acg.setThresh(threshline.value);
\r
397 float range = max * 1000f - min * 1000f;
\r
399 slider.setMinimum((int) (min * 1000));
\r
400 slider.setMaximum((int) (max * 1000));
\r
401 slider.setValue((int) (threshline.value * 1000));
\r
402 thresholdValue.setText(threshline.value + "");
\r
403 slider.setEnabled(true);
\r
404 thresholdValue.setEnabled(true);
\r
408 acg.setThreshType(aboveThreshold);
\r
409 if (thresholdIsMin.isSelected()
\r
410 && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
412 if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
\r
414 acg = new GraduatedColor(acg, threshline.value, max);
\r
418 acg = new GraduatedColor(acg, min, threshline.value);
\r
422 fr.setColour(type, acg);
\r
424 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
\r
425 // ap.paintAlignment(false);
\r
430 fr.setColour(type, oldcs);
\r
431 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
\r
432 // ap.paintAlignment(true);
\r
436 public void mouseClicked(MouseEvent evt)
\r
440 public void mousePressed(MouseEvent evt)
\r
444 public void mouseReleased(MouseEvent evt)
\r
446 if (evt.getSource() == minColour || evt.getSource() == maxColour)
\r
449 actionPerformed(new ActionEvent(evt.getSource(), 1, "Clicked"));
\r
453 PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
\r
455 // ap.paintAlignment(true);
\r
458 public void mouseEntered(MouseEvent evt)
\r
462 public void mouseExited(MouseEvent evt)
\r