2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
22 import java.awt.event.*;
25 import jalview.schemes.*;
26 import javax.swing.event.*;
28 import jalview.datamodel.SequenceGroup;
30 public class AnnotationColourChooser
37 Hashtable oldgroupColours;
38 jalview.datamodel.AlignmentAnnotation currentAnnotation;
39 boolean adjusting = false;
41 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
43 oldcs = av.getGlobalColourScheme();
44 if (av.alignment.getGroups() != null)
46 oldgroupColours = new Hashtable();
47 Vector allGroups = ap.av.alignment.getGroups();
49 for (int g = 0; g < allGroups.size(); g++)
51 sg = (SequenceGroup) allGroups.get(g);
53 oldgroupColours.put(sg, sg.cs);
58 frame = new JInternalFrame();
59 frame.setContentPane(this);
60 frame.setLayer(JLayeredPane.PALETTE_LAYER);
61 Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);
70 slider.addChangeListener(new ChangeListener()
72 public void stateChanged(ChangeEvent evt)
76 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
82 if (av.alignment.getAlignmentAnnotation() == null)
85 if (oldcs instanceof AnnotationColourGradient)
87 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
88 minColour.setBackground(acg.getMinColour());
89 maxColour.setBackground(acg.getMaxColour());
93 minColour.setBackground(Color.orange);
94 maxColour.setBackground(Color.red);
98 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
100 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
101 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
104 threshold.addItem("No Threshold");
105 threshold.addItem("Above Threshold");
106 threshold.addItem("Below Threshold");
114 public AnnotationColourChooser()
122 ex.printStackTrace();
126 private void jbInit()
129 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
130 minColour.setToolTipText("");
131 minColour.setMargin(new Insets(2, 2, 2, 2));
132 minColour.setText("Min Colour");
133 minColour.addActionListener(new ActionListener()
135 public void actionPerformed(ActionEvent e)
137 minColour_actionPerformed(e);
140 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
141 maxColour.setMargin(new Insets(2, 2, 2, 2));
142 maxColour.setText("Max Colour");
143 maxColour.addActionListener(new ActionListener()
145 public void actionPerformed(ActionEvent e)
147 maxColour_actionPerformed(e);
152 ok.addActionListener(new ActionListener()
154 public void actionPerformed(ActionEvent e)
156 ok_actionPerformed(e);
159 cancel.setOpaque(false);
160 cancel.setText("Cancel");
161 cancel.addActionListener(new ActionListener()
163 public void actionPerformed(ActionEvent e)
165 cancel_actionPerformed(e);
168 this.setLayout(borderLayout1);
169 jPanel2.setLayout(flowLayout1);
170 annotations.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent e)
174 annotations_actionPerformed(e);
177 jPanel1.setBackground(Color.white);
178 jPanel2.setBackground(Color.white);
179 threshold.addActionListener(new ActionListener()
181 public void actionPerformed(ActionEvent e)
183 threshold_actionPerformed(e);
186 jPanel3.setLayout(flowLayout2);
187 thresholdValue.addActionListener(new ActionListener()
189 public void actionPerformed(ActionEvent e)
191 thresholdValue_actionPerformed(e);
194 slider.setPaintLabels(false);
195 slider.setPaintTicks(true);
196 slider.setBackground(Color.white);
197 slider.setEnabled(false);
198 slider.setOpaque(false);
199 slider.setPreferredSize(new Dimension(150, 32));
200 thresholdValue.setEnabled(false);
201 thresholdValue.setColumns(10);
202 jPanel3.setBackground(Color.white);
203 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
204 currentColours.setOpaque(false);
205 currentColours.setText("Use Original Colours");
206 currentColours.addActionListener(new ActionListener()
208 public void actionPerformed(ActionEvent e)
210 currentColours_actionPerformed(e);
215 jPanel2.add(annotations);
216 jPanel2.add(currentColours);
217 jPanel2.add(minColour);
218 jPanel2.add(maxColour);
219 this.add(jPanel3, java.awt.BorderLayout.CENTER);
220 jPanel3.add(threshold);
222 jPanel3.add(thresholdValue);
223 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
224 this.add(jPanel2, java.awt.BorderLayout.NORTH);
227 JComboBox annotations = new JComboBox();
228 JButton minColour = new JButton();
229 JButton maxColour = new JButton();
230 JButton ok = new JButton();
231 JButton cancel = new JButton();
232 JPanel jPanel1 = new JPanel();
233 JPanel jPanel2 = new JPanel();
234 BorderLayout borderLayout1 = new BorderLayout();
235 JComboBox threshold = new JComboBox();
236 FlowLayout flowLayout1 = new FlowLayout();
237 JPanel jPanel3 = new JPanel();
238 FlowLayout flowLayout2 = new FlowLayout();
239 JSlider slider = new JSlider();
240 JTextField thresholdValue = new JTextField(20);
241 JCheckBox currentColours = new JCheckBox();
243 public void minColour_actionPerformed(ActionEvent e)
245 Color col = JColorChooser.showDialog(this,
246 "Select Colour for Minimum Value",
247 minColour.getBackground());
249 minColour.setBackground(col);
254 public void maxColour_actionPerformed(ActionEvent e)
256 Color col = JColorChooser.showDialog(this,
257 "Select Colour for Maximum Value",
258 maxColour.getBackground());
260 maxColour.setBackground(col);
267 // Check if combobox is still adjusting
271 // We removed the non-graph annotations when filling the combobox
272 // so allow for them again here
273 int nograph = 0, graph = -1;
274 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
276 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
281 if (graph == annotations.getSelectedIndex())
285 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
287 int aboveThreshold = -1;
288 if (threshold.getSelectedItem().equals("Above Threshold"))
289 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
290 else if (threshold.getSelectedItem().equals("Below Threshold"))
291 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
293 slider.setEnabled(true);
294 thresholdValue.setEnabled(true);
296 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
298 slider.setEnabled(false);
299 thresholdValue.setEnabled(false);
300 thresholdValue.setText("");
302 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
303 currentAnnotation.threshold == null)
305 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
306 ( (currentAnnotation.graphMax -
307 currentAnnotation.graphMin) / 2f,
312 if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
315 float range = currentAnnotation.graphMax * 1000 -
316 currentAnnotation.graphMin * 1000;
318 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
319 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
320 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
321 thresholdValue.setText(currentAnnotation.threshold.value + "");
322 slider.setMajorTickSpacing( (int) (range / 10f));
323 slider.setEnabled(true);
324 thresholdValue.setEnabled(true);
328 AnnotationColourGradient acg = null;
329 if (currentColours.isSelected())
330 acg = new AnnotationColourGradient(
332 av.getGlobalColourScheme(), aboveThreshold);
335 new AnnotationColourGradient(
337 minColour.getBackground(),
338 maxColour.getBackground(),
341 av.setGlobalColourScheme(acg);
343 if (av.alignment.getGroups() != null)
345 Vector allGroups = ap.av.alignment.getGroups();
347 for (int g = 0; g < allGroups.size(); g++)
349 sg = (SequenceGroup) allGroups.get(g);
356 if (currentColours.isSelected())
357 sg.cs = new AnnotationColourGradient(
359 sg.cs, aboveThreshold);
361 sg.cs = new AnnotationColourGradient(
363 minColour.getBackground(),
364 maxColour.getBackground(),
373 public void ok_actionPerformed(ActionEvent e)
378 frame.setClosed(true);
384 public void cancel_actionPerformed(ActionEvent e)
389 frame.setClosed(true);
398 av.setGlobalColourScheme(oldcs);
399 if (av.alignment.getGroups() != null)
401 Vector allGroups = ap.av.alignment.getGroups();
403 for (int g = 0; g < allGroups.size(); g++)
405 sg = (SequenceGroup) allGroups.get(g);
406 sg.cs = (ColourSchemeI)oldgroupColours.get(sg);
411 public void thresholdCheck_actionPerformed(ActionEvent e)
416 public void annotations_actionPerformed(ActionEvent e)
421 public void threshold_actionPerformed(ActionEvent e)
426 public void thresholdValue_actionPerformed(ActionEvent e)
430 float f = Float.parseFloat(thresholdValue.getText());
431 slider.setValue( (int) (f * 1000));
433 catch (NumberFormatException ex)
437 public void valueChanged()
439 if (currentColours.isSelected()
440 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
445 currentAnnotation.threshold.value = (float)slider.getValue()/1000f;
449 public void currentColours_actionPerformed(ActionEvent e)
451 if(currentColours.isSelected())
456 maxColour.setEnabled(!currentColours.isSelected());
457 minColour.setEnabled(!currentColours.isSelected());