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
28 import java.awt.Rectangle;
\r
30 public class AnnotationColourChooser
\r
31 extends Panel implements ActionListener,
\r
32 AdjustmentListener, ItemListener, MouseListener
\r
37 ColourSchemeI oldcs;
\r
38 Hashtable oldgroupColours;
\r
39 jalview.datamodel.AlignmentAnnotation currentAnnotation;
\r
40 boolean adjusting = false;
\r
42 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
48 catch (Exception ex)
\r
51 oldcs = av.getGlobalColourScheme();
\r
52 if (av.alignment.getGroups() != null)
\r
54 oldgroupColours = new Hashtable();
\r
55 Vector allGroups = ap.av.alignment.getGroups();
\r
57 for (int g = 0; g < allGroups.size(); g++)
\r
59 sg = (SequenceGroup) allGroups.elementAt(g);
\r
60 oldgroupColours.put(sg, sg.cs);
\r
66 slider.addAdjustmentListener(this);
\r
67 slider.addMouseListener(this);
\r
69 if (av.alignment.getAlignmentAnnotation() == null)
\r
74 if (oldcs instanceof AnnotationColourGradient)
\r
76 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
77 minColour.setBackground(acg.getMinColour());
\r
78 maxColour.setBackground(acg.getMaxColour());
\r
82 minColour.setBackground(Color.orange);
\r
83 maxColour.setBackground(Color.red);
\r
88 Vector list = new Vector();
\r
90 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
92 String label = av.alignment.getAlignmentAnnotation()[i].label;
\r
93 if (!list.contains(label))
\r
94 list.addElement(label);
\r
96 list.addElement(label+"_"+(index++));
\r
99 for (int i = 0; i < list.size(); i++)
\r
101 annotations.addItem(list.elementAt(i).toString());
\r
104 threshold.addItem("No Threshold");
\r
105 threshold.addItem("Above Threshold");
\r
106 threshold.addItem("Below Threshold");
\r
112 frame = new Frame();
\r
114 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
\r
118 public AnnotationColourChooser()
\r
124 catch (Exception ex)
\r
126 ex.printStackTrace();
\r
130 private void jbInit()
\r
133 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
134 minColour.setLabel("Min Colour");
\r
135 minColour.addActionListener(this);
\r
137 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
138 maxColour.setLabel("Max Colour");
\r
139 maxColour.addActionListener(this);
\r
141 thresholdIsMin.addItemListener(this);
\r
143 ok.addActionListener(this);
\r
145 cancel.setLabel("Cancel");
\r
146 cancel.addActionListener(this);
\r
148 this.setLayout(borderLayout1);
\r
149 jPanel2.setLayout(flowLayout1);
\r
150 annotations.addItemListener(this);
\r
152 jPanel1.setBackground(Color.white);
\r
153 jPanel2.setBackground(Color.white);
\r
154 threshold.addItemListener(this);
\r
155 jPanel3.setLayout(null);
\r
156 thresholdValue.addActionListener(this);
\r
158 slider.setBackground(Color.white);
\r
159 slider.setEnabled(false);
\r
160 slider.setBounds(new Rectangle(153, 3, 93, 21));
\r
161 thresholdValue.setEnabled(false);
\r
162 thresholdValue.setBounds(new Rectangle(248, 2, 79, 22));
\r
163 thresholdValue.setColumns(5);
\r
164 jPanel3.setBackground(Color.white);
\r
165 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
166 currentColours.setLabel("Use Original Colours");
\r
167 currentColours.addItemListener(this);
\r
169 threshold.setBounds(new Rectangle(11, 3, 139, 22));
\r
170 thresholdIsMin.setBackground(Color.white);
\r
171 thresholdIsMin.setLabel("Threshold is min/max");
\r
172 thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
\r
174 jPanel1.add(cancel);
\r
175 jPanel2.add(annotations);
\r
176 jPanel2.add(currentColours);
\r
177 jPanel2.add(minColour);
\r
178 jPanel2.add(maxColour);
\r
179 jPanel3.add(threshold);
\r
180 jPanel3.add(slider);
\r
181 jPanel3.add(thresholdValue);
\r
182 jPanel3.add(thresholdIsMin);
\r
183 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
184 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
185 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
188 Choice annotations = new Choice();
\r
189 Button minColour = new Button();
\r
190 Button maxColour = new Button();
\r
191 Button ok = new Button();
\r
192 Button cancel = new Button();
\r
193 Panel jPanel1 = new Panel();
\r
194 Panel jPanel2 = new Panel();
\r
195 Choice threshold = new Choice();
\r
196 FlowLayout flowLayout1 = new FlowLayout();
\r
197 Panel jPanel3 = new Panel();
\r
198 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
\r
199 TextField thresholdValue = new TextField(20);
\r
200 Checkbox currentColours = new Checkbox();
\r
201 BorderLayout borderLayout1 = new BorderLayout();
\r
202 Checkbox thresholdIsMin = new Checkbox();
\r
204 public void actionPerformed(ActionEvent evt)
\r
206 if (evt.getSource() == thresholdValue)
\r
210 float f = new Float(thresholdValue.getText()).floatValue();
\r
211 slider.setValue( (int) (f * 1000));
\r
212 adjustmentValueChanged(null);
\r
214 catch (NumberFormatException ex)
\r
217 else if (evt.getSource() == minColour)
\r
219 minColour_actionPerformed(null);
\r
221 else if (evt.getSource() == maxColour)
\r
223 maxColour_actionPerformed(null);
\r
226 else if (evt.getSource() == ok)
\r
229 frame.setVisible(false);
\r
231 else if (evt.getSource() == cancel)
\r
234 ap.paintAlignment(true);
\r
235 frame.setVisible(false);
\r
244 public void itemStateChanged(ItemEvent evt)
\r
246 if (evt.getSource() == currentColours)
\r
248 if (currentColours.getState())
\r
253 maxColour.setEnabled(!currentColours.getState());
\r
254 minColour.setEnabled(!currentColours.getState());
\r
261 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
265 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
266 if (currentColours.getState()
\r
267 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
272 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
\r
273 ap.paintAlignment(false);
\r
277 public void minColour_actionPerformed(Color newCol)
\r
279 if (newCol != null)
\r
281 minColour.setBackground(newCol);
\r
282 minColour.repaint();
\r
287 new UserDefinedColours(this, "Min Colour",
\r
288 minColour.getBackground());
\r
293 public void maxColour_actionPerformed(Color newCol)
\r
295 if (newCol != null)
\r
297 maxColour.setBackground(newCol);
\r
298 maxColour.repaint();
\r
303 new UserDefinedColours(this, "Max Colour",
\r
304 maxColour.getBackground());
\r
308 void changeColour()
\r
310 // Check if combobox is still adjusting
\r
317 currentAnnotation = av.alignment.getAlignmentAnnotation()
\r
318 [annotations.getSelectedIndex()];
\r
320 int aboveThreshold = -1;
\r
321 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
323 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
325 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
327 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
330 slider.setEnabled(true);
\r
331 thresholdValue.setEnabled(true);
\r
333 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
335 slider.setEnabled(false);
\r
336 thresholdValue.setEnabled(false);
\r
337 thresholdValue.setText("");
\r
339 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
340 currentAnnotation.threshold == null)
\r
342 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
343 ( (currentAnnotation.graphMax -
\r
344 currentAnnotation.graphMin) / 2f,
\r
349 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
353 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
354 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
355 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
356 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
357 slider.setEnabled(true);
\r
358 thresholdValue.setEnabled(true);
\r
362 AnnotationColourGradient acg = null;
\r
363 if (currentColours.getState())
\r
365 acg = new AnnotationColourGradient(
\r
367 av.getGlobalColourScheme(), aboveThreshold);
\r
372 new AnnotationColourGradient(
\r
374 minColour.getBackground(),
\r
375 maxColour.getBackground(),
\r
379 if (currentAnnotation.graphMin == 0f && currentAnnotation.graphMax == 0f)
\r
381 acg.predefinedColours = true;
\r
384 acg.thresholdIsMinMax = thresholdIsMin.getState();
\r
386 av.setGlobalColourScheme(acg);
\r
388 if (av.alignment.getGroups() != null)
\r
390 Vector allGroups = ap.av.alignment.getGroups();
\r
392 for (int g = 0; g < allGroups.size(); g++)
\r
394 sg = (SequenceGroup) allGroups.elementAt(g);
\r
401 if (currentColours.getState())
\r
403 sg.cs = new AnnotationColourGradient(
\r
405 sg.cs, aboveThreshold);
\r
409 sg.cs = new AnnotationColourGradient(
\r
411 minColour.getBackground(),
\r
412 maxColour.getBackground(),
\r
419 ap.paintAlignment(false);
\r
424 av.setGlobalColourScheme(oldcs);
\r
425 if (av.alignment.getGroups() != null)
\r
427 Vector allGroups = ap.av.alignment.getGroups();
\r
429 for (int g = 0; g < allGroups.size(); g++)
\r
431 sg = (SequenceGroup) allGroups.elementAt(g);
\r
432 sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
\r
435 ap.paintAlignment(true);
\r
439 public void mouseClicked(MouseEvent evt){}
\r
440 public void mousePressed(MouseEvent evt){}
\r
441 public void mouseReleased(MouseEvent evt){ ap.paintAlignment(true);}
\r
442 public void mouseEntered(MouseEvent evt){}
\r
443 public void mouseExited(MouseEvent evt){}
\r