2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
21 import javax.swing.*;
\r
22 import java.awt.event.*;
\r
25 import jalview.schemes.*;
\r
26 import javax.swing.event.*;
\r
28 import jalview.datamodel.SequenceGroup;
\r
29 import java.awt.Dimension;
\r
30 import javax.swing.BorderFactory;
\r
32 public class AnnotationColourChooser
\r
35 JInternalFrame frame;
\r
38 ColourSchemeI oldcs;
\r
39 Hashtable oldgroupColours;
\r
40 jalview.datamodel.AlignmentAnnotation currentAnnotation;
\r
41 boolean adjusting = false;
\r
43 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
45 oldcs = av.getGlobalColourScheme();
\r
46 if (av.alignment.getGroups() != null)
\r
48 oldgroupColours = new Hashtable();
\r
49 Vector allGroups = ap.av.alignment.getGroups();
\r
51 for (int g = 0; g < allGroups.size(); g++)
\r
53 sg = (SequenceGroup) allGroups.get(g);
\r
55 oldgroupColours.put(sg, sg.cs);
\r
60 frame = new JInternalFrame();
\r
61 frame.setContentPane(this);
\r
62 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
63 Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);
\r
69 catch (Exception ex)
\r
72 slider.addChangeListener(new ChangeListener()
\r
74 public void stateChanged(ChangeEvent evt)
\r
78 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
84 if (av.alignment.getAlignmentAnnotation() == null)
\r
87 if (oldcs instanceof AnnotationColourGradient)
\r
89 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
90 minColour.setBackground(acg.getMinColour());
\r
91 maxColour.setBackground(acg.getMaxColour());
\r
95 minColour.setBackground(Color.orange);
\r
96 maxColour.setBackground(Color.red);
\r
100 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
102 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
\r
103 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
106 threshold.addItem("No Threshold");
\r
107 threshold.addItem("Above Threshold");
\r
108 threshold.addItem("Below Threshold");
\r
116 public AnnotationColourChooser()
\r
122 catch (Exception ex)
\r
124 ex.printStackTrace();
\r
128 private void jbInit()
\r
131 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
132 minColour.setBorder(BorderFactory.createEtchedBorder());
\r
133 minColour.setPreferredSize(new Dimension(40, 20));
\r
134 minColour.setToolTipText("Minimum Colour");
\r
135 minColour.addMouseListener(new MouseAdapter()
\r
137 public void mousePressed(MouseEvent e)
\r
139 if (minColour.isEnabled())
\r
140 minColour_actionPerformed();
\r
143 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
144 maxColour.setBorder(BorderFactory.createEtchedBorder());
\r
145 maxColour.setPreferredSize(new Dimension(40, 20));
\r
146 maxColour.setToolTipText("Maximum Colour");
\r
147 maxColour.addMouseListener(new MouseAdapter()
\r
149 public void mousePressed(MouseEvent e)
\r
151 if (maxColour.isEnabled())
\r
152 maxColour_actionPerformed();
\r
155 ok.setOpaque(false);
\r
157 ok.addActionListener(new ActionListener()
\r
159 public void actionPerformed(ActionEvent e)
\r
161 ok_actionPerformed(e);
\r
164 cancel.setOpaque(false);
\r
165 cancel.setText("Cancel");
\r
166 cancel.addActionListener(new ActionListener()
\r
168 public void actionPerformed(ActionEvent e)
\r
170 cancel_actionPerformed(e);
\r
173 this.setLayout(borderLayout1);
\r
174 jPanel2.setLayout(flowLayout1);
\r
175 annotations.addActionListener(new ActionListener()
\r
177 public void actionPerformed(ActionEvent e)
\r
179 annotations_actionPerformed(e);
\r
182 jPanel1.setBackground(Color.white);
\r
183 jPanel2.setBackground(Color.white);
\r
184 threshold.addActionListener(new ActionListener()
\r
186 public void actionPerformed(ActionEvent e)
\r
188 threshold_actionPerformed(e);
\r
191 jPanel3.setLayout(flowLayout2);
\r
192 thresholdValue.addActionListener(new ActionListener()
\r
194 public void actionPerformed(ActionEvent e)
\r
196 thresholdValue_actionPerformed(e);
\r
199 slider.setPaintLabels(false);
\r
200 slider.setPaintTicks(true);
\r
201 slider.setBackground(Color.white);
\r
202 slider.setEnabled(false);
\r
203 slider.setOpaque(false);
\r
204 slider.setPreferredSize(new Dimension(150, 32));
\r
205 thresholdValue.setEnabled(false);
\r
206 thresholdValue.setColumns(10);
\r
207 jPanel3.setBackground(Color.white);
\r
208 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
209 currentColours.setOpaque(false);
\r
210 currentColours.setText("Use Original Colours");
\r
211 currentColours.addActionListener(new ActionListener()
\r
213 public void actionPerformed(ActionEvent e)
\r
215 currentColours_actionPerformed(e);
\r
219 jPanel1.add(cancel);
\r
220 jPanel2.add(annotations);
\r
221 jPanel2.add(currentColours);
\r
222 jPanel2.add(minColour);
\r
223 jPanel2.add(maxColour);
\r
224 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
225 jPanel3.add(threshold);
\r
226 jPanel3.add(slider);
\r
227 jPanel3.add(thresholdValue);
\r
228 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
229 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
232 JComboBox annotations = new JComboBox();
\r
233 JPanel minColour = new JPanel();
\r
234 JPanel maxColour = new JPanel();
\r
235 JButton ok = new JButton();
\r
236 JButton cancel = new JButton();
\r
237 JPanel jPanel1 = new JPanel();
\r
238 JPanel jPanel2 = new JPanel();
\r
239 BorderLayout borderLayout1 = new BorderLayout();
\r
240 JComboBox threshold = new JComboBox();
\r
241 FlowLayout flowLayout1 = new FlowLayout();
\r
242 JPanel jPanel3 = new JPanel();
\r
243 FlowLayout flowLayout2 = new FlowLayout();
\r
244 JSlider slider = new JSlider();
\r
245 JTextField thresholdValue = new JTextField(20);
\r
246 JCheckBox currentColours = new JCheckBox();
\r
248 public void minColour_actionPerformed()
\r
250 Color col = JColorChooser.showDialog(this,
\r
251 "Select Colour for Minimum Value",
\r
252 minColour.getBackground());
\r
254 minColour.setBackground(col);
\r
255 minColour.repaint();
\r
259 public void maxColour_actionPerformed()
\r
261 Color col = JColorChooser.showDialog(this,
\r
262 "Select Colour for Maximum Value",
\r
263 maxColour.getBackground());
\r
265 maxColour.setBackground(col);
\r
266 maxColour.repaint();
\r
270 void changeColour()
\r
272 // Check if combobox is still adjusting
\r
276 // We removed the non-graph annotations when filling the combobox
\r
277 // so allow for them again here
\r
278 int nograph = 0, graph = -1;
\r
279 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
281 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
286 if (graph == annotations.getSelectedIndex())
\r
290 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
\r
292 int aboveThreshold = -1;
\r
293 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
294 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
295 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
296 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
298 slider.setEnabled(true);
\r
299 thresholdValue.setEnabled(true);
\r
301 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
303 slider.setEnabled(false);
\r
304 thresholdValue.setEnabled(false);
\r
305 thresholdValue.setText("");
\r
307 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
308 currentAnnotation.threshold == null)
\r
310 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
311 ( (currentAnnotation.graphMax -
\r
312 currentAnnotation.graphMin) / 2f,
\r
317 if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
320 float range = currentAnnotation.graphMax * 1000 -
\r
321 currentAnnotation.graphMin * 1000;
\r
323 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
324 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
325 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
326 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
327 slider.setMajorTickSpacing( (int) (range / 10f));
\r
328 slider.setEnabled(true);
\r
329 thresholdValue.setEnabled(true);
\r
333 AnnotationColourGradient acg = null;
\r
334 if (currentColours.isSelected())
\r
335 acg = new AnnotationColourGradient(
\r
337 av.getGlobalColourScheme(), aboveThreshold);
\r
340 new AnnotationColourGradient(
\r
342 minColour.getBackground(),
\r
343 maxColour.getBackground(),
\r
346 av.setGlobalColourScheme(acg);
\r
348 if (av.alignment.getGroups() != null)
\r
350 Vector allGroups = ap.av.alignment.getGroups();
\r
352 for (int g = 0; g < allGroups.size(); g++)
\r
354 sg = (SequenceGroup) allGroups.get(g);
\r
361 if (currentColours.isSelected())
\r
362 sg.cs = new AnnotationColourGradient(
\r
364 sg.cs, aboveThreshold);
\r
366 sg.cs = new AnnotationColourGradient(
\r
368 minColour.getBackground(),
\r
369 maxColour.getBackground(),
\r
378 public void ok_actionPerformed(ActionEvent e)
\r
383 frame.setClosed(true);
\r
385 catch (Exception ex)
\r
389 public void cancel_actionPerformed(ActionEvent e)
\r
394 frame.setClosed(true);
\r
396 catch (Exception ex)
\r
403 av.setGlobalColourScheme(oldcs);
\r
404 if (av.alignment.getGroups() != null)
\r
406 Vector allGroups = ap.av.alignment.getGroups();
\r
408 for (int g = 0; g < allGroups.size(); g++)
\r
410 sg = (SequenceGroup) allGroups.get(g);
\r
411 sg.cs = (ColourSchemeI)oldgroupColours.get(sg);
\r
416 public void thresholdCheck_actionPerformed(ActionEvent e)
\r
421 public void annotations_actionPerformed(ActionEvent e)
\r
426 public void threshold_actionPerformed(ActionEvent e)
\r
431 public void thresholdValue_actionPerformed(ActionEvent e)
\r
435 float f = Float.parseFloat(thresholdValue.getText());
\r
436 slider.setValue( (int) (f * 1000));
\r
438 catch (NumberFormatException ex)
\r
442 public void valueChanged()
\r
444 if (currentColours.isSelected()
\r
445 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
450 currentAnnotation.threshold.value = (float)slider.getValue()/1000f;
\r
454 public void currentColours_actionPerformed(ActionEvent e)
\r
456 if(currentColours.isSelected())
\r
461 maxColour.setEnabled(!currentColours.isSelected());
\r
462 minColour.setEnabled(!currentColours.isSelected());
\r