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
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import java.awt.Rectangle;
30 public class AnnotationColourChooser extends Panel implements
31 ActionListener, AdjustmentListener, ItemListener, MouseListener
41 Hashtable oldgroupColours;
43 jalview.datamodel.AlignmentAnnotation currentAnnotation;
45 boolean adjusting = false;
47 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
52 } catch (Exception ex)
56 oldcs = av.getGlobalColourScheme();
57 if (av.alignment.getGroups() != null)
59 oldgroupColours = new Hashtable();
60 Vector allGroups = ap.av.alignment.getGroups();
62 for (int g = 0; g < allGroups.size(); g++)
64 sg = (SequenceGroup) allGroups.elementAt(g);
67 oldgroupColours.put(sg, sg.cs);
71 oldgroupColours.put(sg, "null");
78 slider.addAdjustmentListener(this);
79 slider.addMouseListener(this);
81 if (av.alignment.getAlignmentAnnotation() == null)
86 if (oldcs instanceof AnnotationColourGradient)
88 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
89 minColour.setBackground(acg.getMinColour());
90 maxColour.setBackground(acg.getMaxColour());
94 minColour.setBackground(Color.orange);
95 maxColour.setBackground(Color.red);
100 Vector list = new Vector();
102 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
104 String label = av.alignment.getAlignmentAnnotation()[i].label;
105 if (!list.contains(label))
106 list.addElement(label);
108 list.addElement(label + "_" + (index++));
111 for (int i = 0; i < list.size(); i++)
113 annotations.addItem(list.elementAt(i).toString());
116 threshold.addItem("No Threshold");
117 threshold.addItem("Above Threshold");
118 threshold.addItem("Below Threshold");
126 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480,
131 public AnnotationColourChooser()
136 } catch (Exception ex)
138 ex.printStackTrace();
142 private void jbInit() throws Exception
144 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
145 minColour.setLabel("Min Colour");
146 minColour.addActionListener(this);
148 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
149 maxColour.setLabel("Max Colour");
150 maxColour.addActionListener(this);
152 thresholdIsMin.addItemListener(this);
154 ok.addActionListener(this);
156 cancel.setLabel("Cancel");
157 cancel.addActionListener(this);
159 this.setLayout(borderLayout1);
160 jPanel2.setLayout(flowLayout1);
161 annotations.addItemListener(this);
163 jPanel1.setBackground(Color.white);
164 jPanel2.setBackground(Color.white);
165 threshold.addItemListener(this);
166 jPanel3.setLayout(null);
167 thresholdValue.addActionListener(this);
169 slider.setBackground(Color.white);
170 slider.setEnabled(false);
171 slider.setBounds(new Rectangle(153, 3, 93, 21));
172 thresholdValue.setEnabled(false);
173 thresholdValue.setBounds(new Rectangle(248, 2, 79, 22));
174 thresholdValue.setColumns(5);
175 jPanel3.setBackground(Color.white);
176 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
177 currentColours.setLabel("Use Original Colours");
178 currentColours.addItemListener(this);
180 threshold.setBounds(new Rectangle(11, 3, 139, 22));
181 thresholdIsMin.setBackground(Color.white);
182 thresholdIsMin.setLabel("Threshold is min/max");
183 thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
186 jPanel2.add(annotations);
187 jPanel2.add(currentColours);
188 jPanel2.add(minColour);
189 jPanel2.add(maxColour);
190 jPanel3.add(threshold);
192 jPanel3.add(thresholdValue);
193 jPanel3.add(thresholdIsMin);
194 this.add(jPanel2, java.awt.BorderLayout.NORTH);
195 this.add(jPanel3, java.awt.BorderLayout.CENTER);
196 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
199 Choice annotations = new Choice();
201 Button minColour = new Button();
203 Button maxColour = new Button();
205 Button ok = new Button();
207 Button cancel = new Button();
209 Panel jPanel1 = new Panel();
211 Panel jPanel2 = new Panel();
213 Choice threshold = new Choice();
215 FlowLayout flowLayout1 = new FlowLayout();
217 Panel jPanel3 = new Panel();
219 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
221 TextField thresholdValue = new TextField(20);
223 Checkbox currentColours = new Checkbox();
225 BorderLayout borderLayout1 = new BorderLayout();
227 Checkbox thresholdIsMin = new Checkbox();
229 public void actionPerformed(ActionEvent evt)
231 if (evt.getSource() == thresholdValue)
235 float f = new Float(thresholdValue.getText()).floatValue();
236 slider.setValue((int) (f * 1000));
237 adjustmentValueChanged(null);
238 } catch (NumberFormatException ex)
242 else if (evt.getSource() == minColour)
244 minColour_actionPerformed(null);
246 else if (evt.getSource() == maxColour)
248 maxColour_actionPerformed(null);
251 else if (evt.getSource() == ok)
254 frame.setVisible(false);
256 else if (evt.getSource() == cancel)
259 ap.paintAlignment(true);
260 frame.setVisible(false);
269 public void itemStateChanged(ItemEvent evt)
271 if (evt.getSource() == currentColours)
273 if (currentColours.getState())
278 maxColour.setEnabled(!currentColours.getState());
279 minColour.setEnabled(!currentColours.getState());
286 public void adjustmentValueChanged(AdjustmentEvent evt)
290 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
291 if (currentColours.getState()
292 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
297 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
298 ap.paintAlignment(false);
302 public void minColour_actionPerformed(Color newCol)
306 minColour.setBackground(newCol);
312 new UserDefinedColours(this, "Min Colour", minColour.getBackground());
317 public void maxColour_actionPerformed(Color newCol)
321 maxColour.setBackground(newCol);
327 new UserDefinedColours(this, "Max Colour", maxColour.getBackground());
333 // Check if combobox is still adjusting
339 currentAnnotation = av.alignment.getAlignmentAnnotation()[annotations
340 .getSelectedIndex()];
342 int aboveThreshold = -1;
343 if (threshold.getSelectedItem().equals("Above Threshold"))
345 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
347 else if (threshold.getSelectedItem().equals("Below Threshold"))
349 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
352 slider.setEnabled(true);
353 thresholdValue.setEnabled(true);
355 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
357 slider.setEnabled(false);
358 thresholdValue.setEnabled(false);
359 thresholdValue.setText("");
361 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
362 && currentAnnotation.threshold == null)
365 .setThreshold(new jalview.datamodel.GraphLine(
366 (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f,
367 "Threshold", Color.black));
370 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
374 slider.setMinimum((int) (currentAnnotation.graphMin * 1000));
375 slider.setMaximum((int) (currentAnnotation.graphMax * 1000));
376 slider.setValue((int) (currentAnnotation.threshold.value * 1000));
377 thresholdValue.setText(currentAnnotation.threshold.value + "");
378 slider.setEnabled(true);
379 thresholdValue.setEnabled(true);
383 AnnotationColourGradient acg = null;
384 if (currentColours.getState())
386 acg = new AnnotationColourGradient(currentAnnotation, av
387 .getGlobalColourScheme(), aboveThreshold);
391 acg = new AnnotationColourGradient(currentAnnotation, minColour
392 .getBackground(), maxColour.getBackground(), aboveThreshold);
395 if (currentAnnotation.graphMin == 0f
396 && currentAnnotation.graphMax == 0f)
398 acg.predefinedColours = true;
401 acg.thresholdIsMinMax = thresholdIsMin.getState();
403 av.setGlobalColourScheme(acg);
405 if (av.alignment.getGroups() != null)
407 Vector allGroups = ap.av.alignment.getGroups();
409 for (int g = 0; g < allGroups.size(); g++)
411 sg = (SequenceGroup) allGroups.elementAt(g);
418 if (currentColours.getState())
420 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
425 sg.cs = new AnnotationColourGradient(currentAnnotation, minColour
426 .getBackground(), maxColour.getBackground(),
433 ap.paintAlignment(false);
438 av.setGlobalColourScheme(oldcs);
439 if (av.alignment.getGroups() != null)
441 Vector allGroups = ap.av.alignment.getGroups();
443 for (int g = 0; g < allGroups.size(); g++)
445 sg = (SequenceGroup) allGroups.elementAt(g);
446 Object cs = oldgroupColours.get(sg);
447 if (cs instanceof ColourSchemeI)
449 sg.cs = (ColourSchemeI) cs;
453 // probably the "null" string we set it to if it was null originally.
458 ap.paintAlignment(true);
462 public void mouseClicked(MouseEvent evt)
466 public void mousePressed(MouseEvent evt)
470 public void mouseReleased(MouseEvent evt)
472 ap.paintAlignment(true);
475 public void mouseEntered(MouseEvent evt)
479 public void mouseExited(MouseEvent evt)