2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
27 import java.awt.Rectangle;
29 public class AnnotationColourChooser extends Panel implements
30 ActionListener, AdjustmentListener, ItemListener, MouseListener
40 Hashtable oldgroupColours;
42 jalview.datamodel.AlignmentAnnotation currentAnnotation;
44 boolean adjusting = false;
46 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
51 } catch (Exception ex)
55 oldcs = av.getGlobalColourScheme();
56 if (av.alignment.getGroups() != null)
58 oldgroupColours = new Hashtable();
59 Vector allGroups = ap.av.alignment.getGroups();
61 for (int g = 0; g < allGroups.size(); g++)
63 sg = (SequenceGroup) allGroups.elementAt(g);
66 oldgroupColours.put(sg, sg.cs);
70 oldgroupColours.put(sg, "null");
77 slider.addAdjustmentListener(this);
78 slider.addMouseListener(this);
80 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);
99 Vector list = new Vector();
101 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
103 String label = av.alignment.getAlignmentAnnotation()[i].label;
104 if (!list.contains(label))
105 list.addElement(label);
107 list.addElement(label + "_" + (index++));
110 for (int i = 0; i < list.size(); i++)
112 annotations.addItem(list.elementAt(i).toString());
115 threshold.addItem("No Threshold");
116 threshold.addItem("Above Threshold");
117 threshold.addItem("Below Threshold");
125 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480,
130 public AnnotationColourChooser()
135 } catch (Exception ex)
137 ex.printStackTrace();
141 private void jbInit() throws Exception
143 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
144 minColour.setLabel("Min Colour");
145 minColour.addActionListener(this);
147 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
148 maxColour.setLabel("Max Colour");
149 maxColour.addActionListener(this);
151 thresholdIsMin.addItemListener(this);
153 ok.addActionListener(this);
155 cancel.setLabel("Cancel");
156 cancel.addActionListener(this);
158 this.setLayout(borderLayout1);
159 jPanel2.setLayout(flowLayout1);
160 annotations.addItemListener(this);
162 jPanel1.setBackground(Color.white);
163 jPanel2.setBackground(Color.white);
164 threshold.addItemListener(this);
165 jPanel3.setLayout(null);
166 thresholdValue.addActionListener(this);
168 slider.setBackground(Color.white);
169 slider.setEnabled(false);
170 slider.setBounds(new Rectangle(153, 3, 93, 21));
171 thresholdValue.setEnabled(false);
172 thresholdValue.setBounds(new Rectangle(248, 2, 79, 22));
173 thresholdValue.setColumns(5);
174 jPanel3.setBackground(Color.white);
175 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
176 currentColours.setLabel("Use Original Colours");
177 currentColours.addItemListener(this);
179 threshold.setBounds(new Rectangle(11, 3, 139, 22));
180 thresholdIsMin.setBackground(Color.white);
181 thresholdIsMin.setLabel("Threshold is min/max");
182 thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
185 jPanel2.add(annotations);
186 jPanel2.add(currentColours);
187 jPanel2.add(minColour);
188 jPanel2.add(maxColour);
189 jPanel3.add(threshold);
191 jPanel3.add(thresholdValue);
192 jPanel3.add(thresholdIsMin);
193 this.add(jPanel2, java.awt.BorderLayout.NORTH);
194 this.add(jPanel3, java.awt.BorderLayout.CENTER);
195 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
198 Choice annotations = new Choice();
200 Button minColour = new Button();
202 Button maxColour = new Button();
204 Button ok = new Button();
206 Button cancel = new Button();
208 Panel jPanel1 = new Panel();
210 Panel jPanel2 = new Panel();
212 Choice threshold = new Choice();
214 FlowLayout flowLayout1 = new FlowLayout();
216 Panel jPanel3 = new Panel();
218 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
220 TextField thresholdValue = new TextField(20);
222 Checkbox currentColours = new Checkbox();
224 BorderLayout borderLayout1 = new BorderLayout();
226 Checkbox thresholdIsMin = new Checkbox();
228 public void actionPerformed(ActionEvent evt)
230 if (evt.getSource() == thresholdValue)
234 float f = new Float(thresholdValue.getText()).floatValue();
235 slider.setValue((int) (f * 1000));
236 adjustmentValueChanged(null);
237 } catch (NumberFormatException ex)
241 else if (evt.getSource() == minColour)
243 minColour_actionPerformed(null);
245 else if (evt.getSource() == maxColour)
247 maxColour_actionPerformed(null);
250 else if (evt.getSource() == ok)
253 frame.setVisible(false);
255 else if (evt.getSource() == cancel)
258 ap.paintAlignment(true);
259 frame.setVisible(false);
268 public void itemStateChanged(ItemEvent evt)
270 if (evt.getSource() == currentColours)
272 if (currentColours.getState())
277 maxColour.setEnabled(!currentColours.getState());
278 minColour.setEnabled(!currentColours.getState());
285 public void adjustmentValueChanged(AdjustmentEvent evt)
289 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
290 if (currentColours.getState()
291 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
296 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
297 ap.paintAlignment(false);
301 public void minColour_actionPerformed(Color newCol)
305 minColour.setBackground(newCol);
311 new UserDefinedColours(this, "Min Colour", minColour.getBackground());
316 public void maxColour_actionPerformed(Color newCol)
320 maxColour.setBackground(newCol);
326 new UserDefinedColours(this, "Max Colour", maxColour.getBackground());
332 // Check if combobox is still adjusting
338 currentAnnotation = av.alignment.getAlignmentAnnotation()[annotations
339 .getSelectedIndex()];
341 int aboveThreshold = -1;
342 if (threshold.getSelectedItem().equals("Above Threshold"))
344 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
346 else if (threshold.getSelectedItem().equals("Below Threshold"))
348 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
351 slider.setEnabled(true);
352 thresholdValue.setEnabled(true);
354 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
356 slider.setEnabled(false);
357 thresholdValue.setEnabled(false);
358 thresholdValue.setText("");
360 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
361 && currentAnnotation.threshold == null)
364 .setThreshold(new jalview.datamodel.GraphLine(
365 (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f,
366 "Threshold", Color.black));
369 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
373 slider.setMinimum((int) (currentAnnotation.graphMin * 1000));
374 slider.setMaximum((int) (currentAnnotation.graphMax * 1000));
375 slider.setValue((int) (currentAnnotation.threshold.value * 1000));
376 thresholdValue.setText(currentAnnotation.threshold.value + "");
377 slider.setEnabled(true);
378 thresholdValue.setEnabled(true);
382 AnnotationColourGradient acg = null;
383 if (currentColours.getState())
385 acg = new AnnotationColourGradient(currentAnnotation, av
386 .getGlobalColourScheme(), aboveThreshold);
390 acg = new AnnotationColourGradient(currentAnnotation, minColour
391 .getBackground(), maxColour.getBackground(), aboveThreshold);
394 if (currentAnnotation.graphMin == 0f
395 && currentAnnotation.graphMax == 0f)
397 acg.predefinedColours = true;
400 acg.thresholdIsMinMax = thresholdIsMin.getState();
402 av.setGlobalColourScheme(acg);
404 if (av.alignment.getGroups() != null)
406 Vector allGroups = ap.av.alignment.getGroups();
408 for (int g = 0; g < allGroups.size(); g++)
410 sg = (SequenceGroup) allGroups.elementAt(g);
417 if (currentColours.getState())
419 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
424 sg.cs = new AnnotationColourGradient(currentAnnotation, minColour
425 .getBackground(), maxColour.getBackground(),
432 ap.paintAlignment(false);
437 av.setGlobalColourScheme(oldcs);
438 if (av.alignment.getGroups() != null)
440 Vector allGroups = ap.av.alignment.getGroups();
442 for (int g = 0; g < allGroups.size(); g++)
444 sg = (SequenceGroup) allGroups.elementAt(g);
445 Object cs = oldgroupColours.get(sg);
446 if (cs instanceof ColourSchemeI)
448 sg.cs = (ColourSchemeI) cs;
452 // probably the "null" string we set it to if it was null originally.
457 ap.paintAlignment(true);
461 public void mouseClicked(MouseEvent evt)
465 public void mousePressed(MouseEvent evt)
469 public void mouseReleased(MouseEvent evt)
471 ap.paintAlignment(true);
474 public void mouseEntered(MouseEvent evt)
478 public void mouseExited(MouseEvent evt)