2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
24 import java.awt.event.*;
\r
25 import javax.swing.*;
\r
26 import javax.swing.event.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.schemes.*;
\r
31 public class AnnotationColourChooser
\r
34 JInternalFrame frame;
\r
37 ColourSchemeI oldcs;
\r
38 Hashtable oldgroupColours;
\r
39 jalview.datamodel.AlignmentAnnotation currentAnnotation;
\r
40 boolean adjusting = false;
\r
42 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
44 oldcs = av.getGlobalColourScheme();
\r
45 if (av.alignment.getGroups() != null)
\r
47 oldgroupColours = new Hashtable();
\r
48 Vector allGroups = ap.av.alignment.getGroups();
\r
50 for (int g = 0; g < allGroups.size(); g++)
\r
52 sg = (SequenceGroup) allGroups.get(g);
\r
55 oldgroupColours.put(sg, sg.cs);
\r
61 frame = new JInternalFrame();
\r
62 frame.setContentPane(this);
\r
63 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
64 Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);
\r
70 catch (Exception ex)
\r
73 slider.addChangeListener(new ChangeListener()
\r
75 public void stateChanged(ChangeEvent evt)
\r
79 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
85 if (av.alignment.getAlignmentAnnotation() == null)
\r
90 if (oldcs instanceof AnnotationColourGradient)
\r
92 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
93 minColour.setBackground(acg.getMinColour());
\r
94 maxColour.setBackground(acg.getMaxColour());
\r
98 minColour.setBackground(Color.orange);
\r
99 maxColour.setBackground(Color.red);
\r
103 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
105 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
\r
107 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
111 threshold.addItem("No Threshold");
\r
112 threshold.addItem("Above Threshold");
\r
113 threshold.addItem("Below Threshold");
\r
121 public AnnotationColourChooser()
\r
127 catch (Exception ex)
\r
129 ex.printStackTrace();
\r
133 private void jbInit()
\r
136 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
137 minColour.setBorder(BorderFactory.createEtchedBorder());
\r
138 minColour.setPreferredSize(new Dimension(40, 20));
\r
139 minColour.setToolTipText("Minimum Colour");
\r
140 minColour.addMouseListener(new MouseAdapter()
\r
142 public void mousePressed(MouseEvent e)
\r
144 if (minColour.isEnabled())
\r
146 minColour_actionPerformed();
\r
150 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
151 maxColour.setBorder(BorderFactory.createEtchedBorder());
\r
152 maxColour.setPreferredSize(new Dimension(40, 20));
\r
153 maxColour.setToolTipText("Maximum Colour");
\r
154 maxColour.addMouseListener(new MouseAdapter()
\r
156 public void mousePressed(MouseEvent e)
\r
158 if (maxColour.isEnabled())
\r
160 maxColour_actionPerformed();
\r
164 ok.setOpaque(false);
\r
166 ok.addActionListener(new ActionListener()
\r
168 public void actionPerformed(ActionEvent e)
\r
170 ok_actionPerformed(e);
\r
173 cancel.setOpaque(false);
\r
174 cancel.setText("Cancel");
\r
175 cancel.addActionListener(new ActionListener()
\r
177 public void actionPerformed(ActionEvent e)
\r
179 cancel_actionPerformed(e);
\r
182 this.setLayout(borderLayout1);
\r
183 jPanel2.setLayout(flowLayout1);
\r
184 annotations.addActionListener(new ActionListener()
\r
186 public void actionPerformed(ActionEvent e)
\r
188 annotations_actionPerformed(e);
\r
191 jPanel1.setBackground(Color.white);
\r
192 jPanel2.setBackground(Color.white);
\r
193 threshold.addActionListener(new ActionListener()
\r
195 public void actionPerformed(ActionEvent e)
\r
197 threshold_actionPerformed(e);
\r
200 jPanel3.setLayout(flowLayout2);
\r
201 thresholdValue.addActionListener(new ActionListener()
\r
203 public void actionPerformed(ActionEvent e)
\r
205 thresholdValue_actionPerformed(e);
\r
208 slider.setPaintLabels(false);
\r
209 slider.setPaintTicks(true);
\r
210 slider.setBackground(Color.white);
\r
211 slider.setEnabled(false);
\r
212 slider.setOpaque(false);
\r
213 slider.setPreferredSize(new Dimension(150, 32));
\r
214 thresholdValue.setEnabled(false);
\r
215 thresholdValue.setColumns(10);
\r
216 jPanel3.setBackground(Color.white);
\r
217 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
218 currentColours.setOpaque(false);
\r
219 currentColours.setText("Use Original Colours");
\r
220 currentColours.addActionListener(new ActionListener()
\r
222 public void actionPerformed(ActionEvent e)
\r
224 currentColours_actionPerformed(e);
\r
228 jPanel1.add(cancel);
\r
229 jPanel2.add(annotations);
\r
230 jPanel2.add(currentColours);
\r
231 jPanel2.add(minColour);
\r
232 jPanel2.add(maxColour);
\r
233 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
234 jPanel3.add(threshold);
\r
235 jPanel3.add(slider);
\r
236 jPanel3.add(thresholdValue);
\r
237 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
238 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
241 JComboBox annotations = new JComboBox();
\r
242 JPanel minColour = new JPanel();
\r
243 JPanel maxColour = new JPanel();
\r
244 JButton ok = new JButton();
\r
245 JButton cancel = new JButton();
\r
246 JPanel jPanel1 = new JPanel();
\r
247 JPanel jPanel2 = new JPanel();
\r
248 BorderLayout borderLayout1 = new BorderLayout();
\r
249 JComboBox threshold = new JComboBox();
\r
250 FlowLayout flowLayout1 = new FlowLayout();
\r
251 JPanel jPanel3 = new JPanel();
\r
252 FlowLayout flowLayout2 = new FlowLayout();
\r
253 JSlider slider = new JSlider();
\r
254 JTextField thresholdValue = new JTextField(20);
\r
255 JCheckBox currentColours = new JCheckBox();
\r
257 public void minColour_actionPerformed()
\r
259 Color col = JColorChooser.showDialog(this,
\r
260 "Select Colour for Minimum Value",
\r
261 minColour.getBackground());
\r
264 minColour.setBackground(col);
\r
266 minColour.repaint();
\r
270 public void maxColour_actionPerformed()
\r
272 Color col = JColorChooser.showDialog(this,
\r
273 "Select Colour for Maximum Value",
\r
274 maxColour.getBackground());
\r
277 maxColour.setBackground(col);
\r
279 maxColour.repaint();
\r
283 void changeColour()
\r
285 // Check if combobox is still adjusting
\r
291 // We removed the non-graph annotations when filling the combobox
\r
292 // so allow for them again here
\r
293 int nograph = 0, graph = -1;
\r
294 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
296 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
305 if (graph == annotations.getSelectedIndex())
\r
311 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
\r
313 int aboveThreshold = -1;
\r
314 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
316 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
318 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
320 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
323 slider.setEnabled(true);
\r
324 thresholdValue.setEnabled(true);
\r
326 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
328 slider.setEnabled(false);
\r
329 thresholdValue.setEnabled(false);
\r
330 thresholdValue.setText("");
\r
332 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
333 currentAnnotation.threshold == null)
\r
335 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
336 ( (currentAnnotation.graphMax -
\r
337 currentAnnotation.graphMin) / 2f,
\r
342 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
345 float range = currentAnnotation.graphMax * 1000 -
\r
346 currentAnnotation.graphMin * 1000;
\r
348 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
349 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
350 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
351 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
352 slider.setMajorTickSpacing( (int) (range / 10f));
\r
353 slider.setEnabled(true);
\r
354 thresholdValue.setEnabled(true);
\r
358 AnnotationColourGradient acg = null;
\r
359 if (currentColours.isSelected())
\r
361 acg = new AnnotationColourGradient(
\r
363 av.getGlobalColourScheme(), aboveThreshold);
\r
368 new AnnotationColourGradient(
\r
370 minColour.getBackground(),
\r
371 maxColour.getBackground(),
\r
375 av.setGlobalColourScheme(acg);
\r
377 if (av.alignment.getGroups() != null)
\r
379 Vector allGroups = ap.av.alignment.getGroups();
\r
381 for (int g = 0; g < allGroups.size(); g++)
\r
383 sg = (SequenceGroup) allGroups.get(g);
\r
390 if (currentColours.isSelected())
\r
392 sg.cs = new AnnotationColourGradient(
\r
394 sg.cs, aboveThreshold);
\r
398 sg.cs = new AnnotationColourGradient(
\r
400 minColour.getBackground(),
\r
401 maxColour.getBackground(),
\r
411 public void ok_actionPerformed(ActionEvent e)
\r
416 frame.setClosed(true);
\r
418 catch (Exception ex)
\r
422 public void cancel_actionPerformed(ActionEvent e)
\r
427 frame.setClosed(true);
\r
429 catch (Exception ex)
\r
435 av.setGlobalColourScheme(oldcs);
\r
436 if (av.alignment.getGroups() != null)
\r
438 Vector allGroups = ap.av.alignment.getGroups();
\r
440 for (int g = 0; g < allGroups.size(); g++)
\r
442 sg = (SequenceGroup) allGroups.get(g);
\r
443 sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
\r
448 public void thresholdCheck_actionPerformed(ActionEvent e)
\r
453 public void annotations_actionPerformed(ActionEvent e)
\r
458 public void threshold_actionPerformed(ActionEvent e)
\r
463 public void thresholdValue_actionPerformed(ActionEvent e)
\r
467 float f = Float.parseFloat(thresholdValue.getText());
\r
468 slider.setValue( (int) (f * 1000));
\r
470 catch (NumberFormatException ex)
\r
474 public void valueChanged()
\r
476 if (currentColours.isSelected()
\r
477 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
482 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
\r
486 public void currentColours_actionPerformed(ActionEvent e)
\r
488 if (currentColours.isSelected())
\r
493 maxColour.setEnabled(!currentColours.isSelected());
\r
494 minColour.setEnabled(!currentColours.isSelected());
\r