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
\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
67 if (av.alignment.getAlignmentAnnotation() == null)
\r
72 if (oldcs instanceof AnnotationColourGradient)
\r
74 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
75 minColour.setBackground(acg.getMinColour());
\r
76 maxColour.setBackground(acg.getMaxColour());
\r
80 minColour.setBackground(Color.orange);
\r
81 maxColour.setBackground(Color.red);
\r
85 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
87 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
\r
89 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
93 threshold.addItem("No Threshold");
\r
94 threshold.addItem("Above Threshold");
\r
95 threshold.addItem("Below Threshold");
\r
101 frame = new Frame();
\r
103 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
\r
107 public AnnotationColourChooser()
\r
113 catch (Exception ex)
\r
115 ex.printStackTrace();
\r
119 private void jbInit()
\r
122 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
123 minColour.setLabel("Min Colour");
\r
124 minColour.addActionListener(this);
\r
126 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
127 maxColour.setLabel("Max Colour");
\r
128 maxColour.addActionListener(this);
\r
131 ok.addActionListener(this);
\r
133 cancel.setLabel("Cancel");
\r
134 cancel.addActionListener(this);
\r
136 this.setLayout(borderLayout1);
\r
137 jPanel2.setLayout(flowLayout1);
\r
138 annotations.addItemListener(this);
\r
140 jPanel1.setBackground(Color.white);
\r
141 jPanel2.setBackground(Color.white);
\r
142 threshold.addItemListener(this);
\r
143 jPanel3.setLayout(null);
\r
144 thresholdValue.addActionListener(this);
\r
146 slider.setBackground(Color.white);
\r
147 slider.setEnabled(false);
\r
148 slider.setBounds(new Rectangle(172, 7, 120, 16));
\r
149 thresholdValue.setEnabled(false);
\r
150 thresholdValue.setBounds(new Rectangle(295, 4, 83, 22));
\r
151 thresholdValue.setColumns(10);
\r
152 jPanel3.setBackground(Color.white);
\r
153 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
154 currentColours.setLabel("Use Original Colours");
\r
155 currentColours.addItemListener(this);
\r
157 threshold.setBounds(new Rectangle(19, 4, 141, 22));
\r
159 jPanel1.add(cancel);
\r
160 jPanel2.add(annotations);
\r
161 jPanel2.add(currentColours);
\r
162 jPanel2.add(minColour);
\r
163 jPanel2.add(maxColour);
\r
164 jPanel3.add(threshold);
\r
165 jPanel3.add(slider);
\r
166 jPanel3.add(thresholdValue);
\r
167 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
168 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
169 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
172 Choice annotations = new Choice();
\r
173 Button minColour = new Button();
\r
174 Button maxColour = new Button();
\r
175 Button ok = new Button();
\r
176 Button cancel = new Button();
\r
177 Panel jPanel1 = new Panel();
\r
178 Panel jPanel2 = new Panel();
\r
179 Choice threshold = new Choice();
\r
180 FlowLayout flowLayout1 = new FlowLayout();
\r
181 Panel jPanel3 = new Panel();
\r
182 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
\r
183 TextField thresholdValue = new TextField(20);
\r
184 Checkbox currentColours = new Checkbox();
\r
185 BorderLayout borderLayout1 = new BorderLayout();
\r
187 public void actionPerformed(ActionEvent evt)
\r
189 if (evt.getSource() == thresholdValue)
\r
193 float f = new Float(thresholdValue.getText()).floatValue();
\r
194 slider.setValue( (int) (f * 1000));
\r
195 adjustmentValueChanged(null);
\r
197 catch (NumberFormatException ex)
\r
200 else if (evt.getSource() == minColour)
\r
202 minColour_actionPerformed(null);
\r
204 else if (evt.getSource() == maxColour)
\r
206 maxColour_actionPerformed(null);
\r
209 else if (evt.getSource() == ok)
\r
212 frame.setVisible(false);
\r
214 else if (evt.getSource() == cancel)
\r
218 frame.setVisible(false);
\r
227 public void itemStateChanged(ItemEvent evt)
\r
229 if (evt.getSource() == currentColours)
\r
231 if (currentColours.getState())
\r
236 maxColour.setEnabled(!currentColours.getState());
\r
237 minColour.setEnabled(!currentColours.getState());
\r
244 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
248 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
249 if (currentColours.getState()
\r
250 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
255 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
\r
260 public void minColour_actionPerformed(Color newCol)
\r
262 if (newCol != null)
\r
264 minColour.setBackground(newCol);
\r
265 minColour.repaint();
\r
270 new UserDefinedColours(this, "Min Colour",
\r
271 minColour.getBackground());
\r
276 public void maxColour_actionPerformed(Color newCol)
\r
278 if (newCol != null)
\r
280 maxColour.setBackground(newCol);
\r
281 maxColour.repaint();
\r
286 new UserDefinedColours(this, "Max Colour",
\r
287 maxColour.getBackground());
\r
291 void changeColour()
\r
293 // Check if combobox is still adjusting
\r
299 // We removed the non-graph annotations when filling the combobox
\r
300 // so allow for them again here
\r
301 int nograph = 0, graph = -1;
\r
302 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
304 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
313 if (graph == annotations.getSelectedIndex())
\r
319 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
\r
321 int aboveThreshold = -1;
\r
322 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
324 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
326 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
328 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
331 slider.setEnabled(true);
\r
332 thresholdValue.setEnabled(true);
\r
334 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
336 slider.setEnabled(false);
\r
337 thresholdValue.setEnabled(false);
\r
338 thresholdValue.setText("");
\r
340 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
341 currentAnnotation.threshold == null)
\r
343 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
344 ( (currentAnnotation.graphMax -
\r
345 currentAnnotation.graphMin) / 2f,
\r
350 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
354 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
355 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
356 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
357 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
358 slider.setEnabled(true);
\r
359 thresholdValue.setEnabled(true);
\r
363 AnnotationColourGradient acg = null;
\r
364 if (currentColours.getState())
\r
366 acg = new AnnotationColourGradient(
\r
368 av.getGlobalColourScheme(), aboveThreshold);
\r
373 new AnnotationColourGradient(
\r
375 minColour.getBackground(),
\r
376 maxColour.getBackground(),
\r
380 av.setGlobalColourScheme(acg);
\r
382 if (av.alignment.getGroups() != null)
\r
384 Vector allGroups = ap.av.alignment.getGroups();
\r
386 for (int g = 0; g < allGroups.size(); g++)
\r
388 sg = (SequenceGroup) allGroups.elementAt(g);
\r
395 if (currentColours.getState())
\r
397 sg.cs = new AnnotationColourGradient(
\r
399 sg.cs, aboveThreshold);
\r
403 sg.cs = new AnnotationColourGradient(
\r
405 minColour.getBackground(),
\r
406 maxColour.getBackground(),
\r
418 av.setGlobalColourScheme(oldcs);
\r
419 if (av.alignment.getGroups() != null)
\r
421 Vector allGroups = ap.av.alignment.getGroups();
\r
423 for (int g = 0; g < allGroups.size(); g++)
\r
425 sg = (SequenceGroup) allGroups.elementAt(g);
\r
426 sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
\r