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.appletgui;
\r
24 import java.awt.event.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.schemes.*;
\r
29 public class AnnotationColourChooser
\r
30 extends Panel implements ActionListener,
\r
31 AdjustmentListener, ItemListener, MouseListener
\r
36 ColourSchemeI oldcs;
\r
37 Hashtable oldgroupColours;
\r
38 jalview.datamodel.AlignmentAnnotation currentAnnotation;
\r
39 boolean adjusting = false;
\r
41 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
47 catch (Exception ex)
\r
50 oldcs = av.getGlobalColourScheme();
\r
51 if (av.alignment.getGroups() != null)
\r
53 oldgroupColours = new Hashtable();
\r
54 Vector allGroups = ap.av.alignment.getGroups();
\r
56 for (int g = 0; g < allGroups.size(); g++)
\r
58 sg = (SequenceGroup) allGroups.elementAt(g);
\r
59 oldgroupColours.put(sg, sg.cs);
\r
65 slider.addAdjustmentListener(this);
\r
66 slider.addMouseListener(this);
\r
68 if (av.alignment.getAlignmentAnnotation() == null)
\r
73 if (oldcs instanceof AnnotationColourGradient)
\r
75 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
76 minColour.setBackground(acg.getMinColour());
\r
77 maxColour.setBackground(acg.getMaxColour());
\r
81 minColour.setBackground(Color.orange);
\r
82 maxColour.setBackground(Color.red);
\r
86 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
88 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
\r
90 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
94 threshold.addItem("No Threshold");
\r
95 threshold.addItem("Above Threshold");
\r
96 threshold.addItem("Below Threshold");
\r
102 frame = new Frame();
\r
104 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
\r
108 public AnnotationColourChooser()
\r
114 catch (Exception ex)
\r
116 ex.printStackTrace();
\r
120 private void jbInit()
\r
123 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
124 minColour.setLabel("Min Colour");
\r
125 minColour.addActionListener(this);
\r
127 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
128 maxColour.setLabel("Max Colour");
\r
129 maxColour.addActionListener(this);
\r
132 ok.addActionListener(this);
\r
134 cancel.setLabel("Cancel");
\r
135 cancel.addActionListener(this);
\r
137 this.setLayout(borderLayout1);
\r
138 jPanel2.setLayout(flowLayout1);
\r
139 annotations.addItemListener(this);
\r
141 jPanel1.setBackground(Color.white);
\r
142 jPanel2.setBackground(Color.white);
\r
143 threshold.addItemListener(this);
\r
144 jPanel3.setLayout(null);
\r
145 thresholdValue.addActionListener(this);
\r
147 slider.setBackground(Color.white);
\r
148 slider.setEnabled(false);
\r
149 slider.setBounds(new Rectangle(172, 7, 120, 16));
\r
150 thresholdValue.setEnabled(false);
\r
151 thresholdValue.setBounds(new Rectangle(295, 4, 83, 22));
\r
152 thresholdValue.setColumns(10);
\r
153 jPanel3.setBackground(Color.white);
\r
154 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
155 currentColours.setLabel("Use Original Colours");
\r
156 currentColours.addItemListener(this);
\r
158 threshold.setBounds(new Rectangle(19, 4, 141, 22));
\r
160 jPanel1.add(cancel);
\r
161 jPanel2.add(annotations);
\r
162 jPanel2.add(currentColours);
\r
163 jPanel2.add(minColour);
\r
164 jPanel2.add(maxColour);
\r
165 jPanel3.add(threshold);
\r
166 jPanel3.add(slider);
\r
167 jPanel3.add(thresholdValue);
\r
168 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
169 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
170 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
173 Choice annotations = new Choice();
\r
174 Button minColour = new Button();
\r
175 Button maxColour = new Button();
\r
176 Button ok = new Button();
\r
177 Button cancel = new Button();
\r
178 Panel jPanel1 = new Panel();
\r
179 Panel jPanel2 = new Panel();
\r
180 Choice threshold = new Choice();
\r
181 FlowLayout flowLayout1 = new FlowLayout();
\r
182 Panel jPanel3 = new Panel();
\r
183 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
\r
184 TextField thresholdValue = new TextField(20);
\r
185 Checkbox currentColours = new Checkbox();
\r
186 BorderLayout borderLayout1 = new BorderLayout();
\r
188 public void actionPerformed(ActionEvent evt)
\r
190 if (evt.getSource() == thresholdValue)
\r
194 float f = new Float(thresholdValue.getText()).floatValue();
\r
195 slider.setValue( (int) (f * 1000));
\r
196 adjustmentValueChanged(null);
\r
198 catch (NumberFormatException ex)
\r
201 else if (evt.getSource() == minColour)
\r
203 minColour_actionPerformed(null);
\r
205 else if (evt.getSource() == maxColour)
\r
207 maxColour_actionPerformed(null);
\r
210 else if (evt.getSource() == ok)
\r
213 frame.setVisible(false);
\r
215 else if (evt.getSource() == cancel)
\r
218 ap.paintAlignment(true);
\r
219 frame.setVisible(false);
\r
228 public void itemStateChanged(ItemEvent evt)
\r
230 if (evt.getSource() == currentColours)
\r
232 if (currentColours.getState())
\r
237 maxColour.setEnabled(!currentColours.getState());
\r
238 minColour.setEnabled(!currentColours.getState());
\r
245 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
249 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
250 if (currentColours.getState()
\r
251 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
256 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
\r
257 ap.paintAlignment(false);
\r
261 public void minColour_actionPerformed(Color newCol)
\r
263 if (newCol != null)
\r
265 minColour.setBackground(newCol);
\r
266 minColour.repaint();
\r
271 new UserDefinedColours(this, "Min Colour",
\r
272 minColour.getBackground());
\r
277 public void maxColour_actionPerformed(Color newCol)
\r
279 if (newCol != null)
\r
281 maxColour.setBackground(newCol);
\r
282 maxColour.repaint();
\r
287 new UserDefinedColours(this, "Max Colour",
\r
288 maxColour.getBackground());
\r
292 void changeColour()
\r
294 // Check if combobox is still adjusting
\r
300 // We removed the non-graph annotations when filling the combobox
\r
301 // so allow for them again here
\r
302 int nograph = 0, graph = -1;
\r
303 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
305 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
314 if (graph == annotations.getSelectedIndex())
\r
320 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
\r
322 int aboveThreshold = -1;
\r
323 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
325 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
327 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
329 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
332 slider.setEnabled(true);
\r
333 thresholdValue.setEnabled(true);
\r
335 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
337 slider.setEnabled(false);
\r
338 thresholdValue.setEnabled(false);
\r
339 thresholdValue.setText("");
\r
341 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
342 currentAnnotation.threshold == null)
\r
344 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
345 ( (currentAnnotation.graphMax -
\r
346 currentAnnotation.graphMin) / 2f,
\r
351 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
355 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
356 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
357 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
358 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
359 slider.setEnabled(true);
\r
360 thresholdValue.setEnabled(true);
\r
364 AnnotationColourGradient acg = null;
\r
365 if (currentColours.getState())
\r
367 acg = new AnnotationColourGradient(
\r
369 av.getGlobalColourScheme(), aboveThreshold);
\r
374 new AnnotationColourGradient(
\r
376 minColour.getBackground(),
\r
377 maxColour.getBackground(),
\r
381 av.setGlobalColourScheme(acg);
\r
383 if (av.alignment.getGroups() != null)
\r
385 Vector allGroups = ap.av.alignment.getGroups();
\r
387 for (int g = 0; g < allGroups.size(); g++)
\r
389 sg = (SequenceGroup) allGroups.elementAt(g);
\r
396 if (currentColours.getState())
\r
398 sg.cs = new AnnotationColourGradient(
\r
400 sg.cs, aboveThreshold);
\r
404 sg.cs = new AnnotationColourGradient(
\r
406 minColour.getBackground(),
\r
407 maxColour.getBackground(),
\r
414 ap.paintAlignment(false);
\r
419 av.setGlobalColourScheme(oldcs);
\r
420 if (av.alignment.getGroups() != null)
\r
422 Vector allGroups = ap.av.alignment.getGroups();
\r
424 for (int g = 0; g < allGroups.size(); g++)
\r
426 sg = (SequenceGroup) allGroups.elementAt(g);
\r
427 sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
\r
430 ap.paintAlignment(true);
\r
434 public void mouseClicked(MouseEvent evt){}
\r
435 public void mousePressed(MouseEvent evt){}
\r
436 public void mouseReleased(MouseEvent evt){ ap.paintAlignment(true);}
\r
437 public void mouseEntered(MouseEvent evt){}
\r
438 public void mouseExited(MouseEvent evt){}
\r