2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
26 import javax.swing.event.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import java.awt.Dimension;
32 public class AnnotationColourChooser
39 Hashtable oldgroupColours;
40 jalview.datamodel.AlignmentAnnotation currentAnnotation;
41 boolean adjusting = false;
43 public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
45 oldcs = av.getGlobalColourScheme();
46 if (av.alignment.getGroups() != null)
48 oldgroupColours = new Hashtable();
49 Vector allGroups = ap.av.alignment.getGroups();
51 for (int g = 0; g < allGroups.size(); g++)
53 sg = (SequenceGroup) allGroups.get(g);
56 oldgroupColours.put(sg, sg.cs);
62 frame = new JInternalFrame();
63 frame.setContentPane(this);
64 frame.setLayer(JLayeredPane.PALETTE_LAYER);
65 Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);
68 slider.addChangeListener(new ChangeListener()
70 public void stateChanged(ChangeEvent evt)
74 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
79 slider.addMouseListener(new MouseAdapter()
81 public void mouseReleased(MouseEvent evt)
83 ap.paintAlignment(true);
87 if (av.alignment.getAlignmentAnnotation() == null)
92 if (oldcs instanceof AnnotationColourGradient)
94 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
95 minColour.setBackground(acg.getMinColour());
96 maxColour.setBackground(acg.getMaxColour());
100 minColour.setBackground(Color.orange);
101 maxColour.setBackground(Color.red);
105 Vector list = new Vector();
107 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
109 String label = av.alignment.getAlignmentAnnotation()[i].label;
110 if (!list.contains(label))
111 list.addElement(label);
113 list.addElement(label+"_"+(index++));
116 annotations = new JComboBox(list);
118 threshold.addItem("No Threshold");
119 threshold.addItem("Above Threshold");
120 threshold.addItem("Below Threshold");
135 public AnnotationColourChooser()
143 ex.printStackTrace();
147 private void jbInit()
150 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
151 minColour.setBorder(BorderFactory.createEtchedBorder());
152 minColour.setPreferredSize(new Dimension(40, 20));
153 minColour.setToolTipText("Minimum Colour");
154 minColour.addMouseListener(new MouseAdapter()
156 public void mousePressed(MouseEvent e)
158 if (minColour.isEnabled())
160 minColour_actionPerformed();
164 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
165 maxColour.setBorder(BorderFactory.createEtchedBorder());
166 maxColour.setPreferredSize(new Dimension(40, 20));
167 maxColour.setToolTipText("Maximum Colour");
168 maxColour.addMouseListener(new MouseAdapter()
170 public void mousePressed(MouseEvent e)
172 if (maxColour.isEnabled())
174 maxColour_actionPerformed();
180 ok.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 ok_actionPerformed(e);
187 cancel.setOpaque(false);
188 cancel.setText("Cancel");
189 cancel.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 cancel_actionPerformed(e);
196 this.setLayout(borderLayout1);
197 jPanel2.setLayout(flowLayout1);
198 annotations.addActionListener(new ActionListener()
200 public void actionPerformed(ActionEvent e)
202 annotations_actionPerformed(e);
205 jPanel1.setBackground(Color.white);
206 jPanel2.setBackground(Color.white);
207 threshold.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 threshold_actionPerformed(e);
214 jPanel3.setLayout(flowLayout2);
215 thresholdValue.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 thresholdValue_actionPerformed(e);
222 slider.setPaintLabels(false);
223 slider.setPaintTicks(true);
224 slider.setBackground(Color.white);
225 slider.setEnabled(false);
226 slider.setOpaque(false);
227 slider.setPreferredSize(new Dimension(100, 32));
228 thresholdValue.setEnabled(false);
229 thresholdValue.setColumns(7);
230 jPanel3.setBackground(Color.white);
231 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
232 currentColours.setOpaque(false);
233 currentColours.setText("Use Original Colours");
234 currentColours.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 currentColours_actionPerformed(e);
241 thresholdIsMin.setBackground(Color.white);
242 thresholdIsMin.setText("Threshold is Min/Max");
243 thresholdIsMin.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent actionEvent)
247 thresholdIsMin_actionPerformed(actionEvent);
252 jPanel2.add(annotations);
253 jPanel2.add(currentColours);
254 jPanel2.add(minColour);
255 jPanel2.add(maxColour);
256 this.add(jPanel3, java.awt.BorderLayout.CENTER);
257 jPanel3.add(threshold);
259 jPanel3.add(thresholdValue);
260 jPanel3.add(thresholdIsMin);
261 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
262 this.add(jPanel2, java.awt.BorderLayout.NORTH);
265 JComboBox annotations;
266 JPanel minColour = new JPanel();
267 JPanel maxColour = new JPanel();
268 JButton ok = new JButton();
269 JButton cancel = new JButton();
270 JPanel jPanel1 = new JPanel();
271 JPanel jPanel2 = new JPanel();
272 BorderLayout borderLayout1 = new BorderLayout();
273 JComboBox threshold = new JComboBox();
274 FlowLayout flowLayout1 = new FlowLayout();
275 JPanel jPanel3 = new JPanel();
276 FlowLayout flowLayout2 = new FlowLayout();
277 JSlider slider = new JSlider();
278 JTextField thresholdValue = new JTextField(20);
279 JCheckBox currentColours = new JCheckBox();
280 JCheckBox thresholdIsMin = new JCheckBox();
282 public void minColour_actionPerformed()
284 Color col = JColorChooser.showDialog(this,
285 "Select Colour for Minimum Value",
286 minColour.getBackground());
289 minColour.setBackground(col);
295 public void maxColour_actionPerformed()
297 Color col = JColorChooser.showDialog(this,
298 "Select Colour for Maximum Value",
299 maxColour.getBackground());
302 maxColour.setBackground(col);
310 // Check if combobox is still adjusting
317 currentAnnotation = av.alignment.getAlignmentAnnotation()[annotations.getSelectedIndex()];
319 int aboveThreshold = -1;
320 if (threshold.getSelectedItem().equals("Above Threshold"))
322 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
324 else if (threshold.getSelectedItem().equals("Below Threshold"))
326 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
329 slider.setEnabled(true);
330 thresholdValue.setEnabled(true);
332 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
334 slider.setEnabled(false);
335 thresholdValue.setEnabled(false);
336 thresholdValue.setText("");
338 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
339 currentAnnotation.threshold == null)
341 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
342 ( (currentAnnotation.graphMax -
343 currentAnnotation.graphMin) / 2f,
348 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
351 float range = currentAnnotation.graphMax * 1000 -
352 currentAnnotation.graphMin * 1000;
354 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
355 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
356 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
357 thresholdValue.setText(currentAnnotation.threshold.value + "");
358 slider.setMajorTickSpacing( (int) (range / 10f));
359 slider.setEnabled(true);
360 thresholdValue.setEnabled(true);
364 AnnotationColourGradient acg = null;
365 if (currentColours.isSelected())
367 acg = new AnnotationColourGradient(
369 av.getGlobalColourScheme(), aboveThreshold);
374 new AnnotationColourGradient(
376 minColour.getBackground(),
377 maxColour.getBackground(),
381 if(currentAnnotation.graphMin==0f&& currentAnnotation.graphMax==0f)
383 acg.predefinedColours = true;
386 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
388 av.setGlobalColourScheme(acg);
390 if (av.alignment.getGroups() != null)
392 Vector allGroups = ap.av.alignment.getGroups();
394 for (int g = 0; g < allGroups.size(); g++)
396 sg = (SequenceGroup) allGroups.get(g);
403 if (currentColours.isSelected())
405 sg.cs = new AnnotationColourGradient(
407 sg.cs, aboveThreshold);
411 sg.cs = new AnnotationColourGradient(
413 minColour.getBackground(),
414 maxColour.getBackground(),
421 ap.paintAlignment(false);
424 public void ok_actionPerformed(ActionEvent e)
429 frame.setClosed(true);
435 public void cancel_actionPerformed(ActionEvent e)
440 frame.setClosed(true);
448 av.setGlobalColourScheme(oldcs);
449 if (av.alignment.getGroups() != null)
451 Vector allGroups = ap.av.alignment.getGroups();
453 for (int g = 0; g < allGroups.size(); g++)
455 sg = (SequenceGroup) allGroups.get(g);
456 sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
461 public void thresholdCheck_actionPerformed(ActionEvent e)
466 public void annotations_actionPerformed(ActionEvent e)
471 public void threshold_actionPerformed(ActionEvent e)
476 public void thresholdValue_actionPerformed(ActionEvent e)
480 float f = Float.parseFloat(thresholdValue.getText());
481 slider.setValue( (int) (f * 1000));
483 catch (NumberFormatException ex)
487 public void valueChanged()
489 if (currentColours.isSelected()
490 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
495 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
496 ap.paintAlignment(false);
499 public void currentColours_actionPerformed(ActionEvent e)
501 if (currentColours.isSelected())
506 maxColour.setEnabled(!currentColours.isSelected());
507 minColour.setEnabled(!currentColours.isSelected());
512 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)