2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
21 import java.awt.event.*;
\r
24 import jalview.schemes.*;
\r
26 import jalview.datamodel.SequenceGroup;
\r
28 public class AnnotationColourChooser extends Panel implements ActionListener,
\r
29 AdjustmentListener, ItemListener
\r
34 ColourSchemeI oldcs;
\r
35 Hashtable oldgroupColours;
\r
36 jalview.datamodel.AlignmentAnnotation currentAnnotation;
\r
37 boolean adjusting = false;
\r
39 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
45 catch (Exception ex)
\r
48 oldcs = av.getGlobalColourScheme();
\r
49 if (av.alignment.getGroups() != null)
\r
51 oldgroupColours = new Hashtable();
\r
52 Vector allGroups = ap.av.alignment.getGroups();
\r
54 for (int g = 0; g < allGroups.size(); g++)
\r
56 sg = (SequenceGroup) allGroups.elementAt(g);
\r
57 oldgroupColours.put(sg, sg.cs);
\r
63 slider.addAdjustmentListener(this);
\r
65 if (av.alignment.getAlignmentAnnotation() == null)
\r
68 if (oldcs instanceof AnnotationColourGradient)
\r
70 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
71 minColour.setBackground(acg.getMinColour());
\r
72 maxColour.setBackground(acg.getMaxColour());
\r
76 minColour.setBackground(Color.orange);
\r
77 maxColour.setBackground(Color.red);
\r
81 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
83 if (av.alignment.getAlignmentAnnotation()[i].graph > 0)
\r
84 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
87 threshold.addItem("No Threshold");
\r
88 threshold.addItem("Above Threshold");
\r
89 threshold.addItem("Below Threshold");
\r
95 frame = new Frame();
\r
97 jalview.bin.JalviewLite.addFrame(frame, "Colour by Annotation", 480, 145);
\r
101 public AnnotationColourChooser()
\r
107 catch (Exception ex)
\r
109 ex.printStackTrace();
\r
113 private void jbInit()
\r
116 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
117 minColour.setLabel("Min Colour");
\r
118 minColour.addActionListener(this);
\r
120 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
121 maxColour.setLabel("Max Colour");
\r
122 maxColour.addActionListener(this);
\r
125 ok.addActionListener(this);
\r
127 cancel.setLabel("Cancel");
\r
128 cancel.addActionListener(this);
\r
130 this.setLayout(borderLayout1);
\r
131 jPanel2.setLayout(flowLayout1);
\r
132 annotations.addItemListener(this);
\r
134 jPanel1.setBackground(Color.white);
\r
135 jPanel2.setBackground(Color.white);
\r
136 threshold.addItemListener(this);
\r
137 jPanel3.setLayout(null);
\r
138 thresholdValue.addActionListener(this);
\r
140 slider.setBackground(Color.white);
\r
141 slider.setEnabled(false);
\r
142 slider.setBounds(new Rectangle(172, 7, 120, 16));
\r
143 thresholdValue.setEnabled(false);
\r
144 thresholdValue.setBounds(new Rectangle(295, 4, 83, 22));
\r
145 thresholdValue.setColumns(10);
\r
146 jPanel3.setBackground(Color.white);
\r
147 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
148 currentColours.setLabel("Use Original Colours");
\r
149 currentColours.addItemListener(this);
\r
151 threshold.setBounds(new Rectangle(19, 4, 141, 22));
\r
153 jPanel1.add(cancel);
\r
154 jPanel2.add(annotations);
\r
155 jPanel2.add(currentColours);
\r
156 jPanel2.add(minColour);
\r
157 jPanel2.add(maxColour);
\r
158 jPanel3.add(threshold);
\r
159 jPanel3.add(slider);
\r
160 jPanel3.add(thresholdValue);
\r
161 this.add(jPanel2, java.awt.BorderLayout.NORTH);
\r
162 this.add(jPanel3, java.awt.BorderLayout.CENTER);
\r
163 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
166 Choice annotations = new Choice();
\r
167 Button minColour = new Button();
\r
168 Button maxColour = new Button();
\r
169 Button ok = new Button();
\r
170 Button cancel = new Button();
\r
171 Panel jPanel1 = new Panel();
\r
172 Panel jPanel2 = new Panel();
\r
173 Choice threshold = new Choice();
\r
174 FlowLayout flowLayout1 = new FlowLayout();
\r
175 Panel jPanel3 = new Panel();
\r
176 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
\r
177 TextField thresholdValue = new TextField(20);
\r
178 Checkbox currentColours = new Checkbox();
\r
179 BorderLayout borderLayout1 = new BorderLayout();
\r
182 public void actionPerformed(ActionEvent evt)
\r
184 if(evt.getSource() == thresholdValue)
\r
188 float f = new Float(thresholdValue.getText()).floatValue();
\r
189 slider.setValue( (int) (f * 1000));
\r
190 adjustmentValueChanged(null);
\r
192 catch (NumberFormatException ex)
\r
195 else if (evt.getSource() == minColour)
\r
196 minColour_actionPerformed(null);
\r
197 else if (evt.getSource() == maxColour)
\r
198 maxColour_actionPerformed(null);
\r
200 else if (evt.getSource() == ok)
\r
203 frame.setVisible(false);
\r
205 else if (evt.getSource() == cancel)
\r
209 frame.setVisible(false);
\r
217 public void itemStateChanged(ItemEvent evt)
\r
219 if (evt.getSource() == currentColours)
\r
221 if (currentColours.getState())
\r
226 maxColour.setEnabled(!currentColours.getState());
\r
227 minColour.setEnabled(!currentColours.getState());
\r
234 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
238 thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");
\r
239 if (currentColours.getState()
\r
240 && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
245 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
\r
250 public void minColour_actionPerformed(Color newCol)
\r
252 if (newCol != null)
\r
254 minColour.setBackground(newCol);
\r
255 minColour.repaint();
\r
259 new UserDefinedColours(this, "Min Colour",
\r
260 minColour.getBackground());
\r
264 public void maxColour_actionPerformed(Color newCol)
\r
266 if (newCol != null)
\r
268 maxColour.setBackground(newCol);
\r
269 maxColour.repaint();
\r
273 new UserDefinedColours(this, "Max Colour",
\r
274 maxColour.getBackground());
\r
278 void changeColour()
\r
280 // Check if combobox is still adjusting
\r
284 // We removed the non-graph annotations when filling the combobox
\r
285 // so allow for them again here
\r
286 int nograph = 0, graph = -1;
\r
287 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
289 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
294 if (graph == annotations.getSelectedIndex())
\r
298 currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph];
\r
300 int aboveThreshold = -1;
\r
301 if (threshold.getSelectedItem().equals("Above Threshold"))
\r
302 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
303 else if (threshold.getSelectedItem().equals("Below Threshold"))
\r
304 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
306 slider.setEnabled(true);
\r
307 thresholdValue.setEnabled(true);
\r
309 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
311 slider.setEnabled(false);
\r
312 thresholdValue.setEnabled(false);
\r
313 thresholdValue.setText("");
\r
315 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD &&
\r
316 currentAnnotation.threshold == null)
\r
318 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine
\r
319 ( (currentAnnotation.graphMax -
\r
320 currentAnnotation.graphMin) / 2f,
\r
325 if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
329 slider.setMinimum( (int) (currentAnnotation.graphMin * 1000));
\r
330 slider.setMaximum( (int) (currentAnnotation.graphMax * 1000));
\r
331 slider.setValue( (int) (currentAnnotation.threshold.value * 1000));
\r
332 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
333 slider.setEnabled(true);
\r
334 thresholdValue.setEnabled(true);
\r
338 AnnotationColourGradient acg = null;
\r
339 if (currentColours.getState())
\r
340 acg = new AnnotationColourGradient(
\r
342 av.getGlobalColourScheme(), aboveThreshold);
\r
345 new AnnotationColourGradient(
\r
347 minColour.getBackground(),
\r
348 maxColour.getBackground(),
\r
351 av.setGlobalColourScheme(acg);
\r
353 if (av.alignment.getGroups() != null)
\r
355 Vector allGroups = ap.av.alignment.getGroups();
\r
357 for (int g = 0; g < allGroups.size(); g++)
\r
359 sg = (SequenceGroup) allGroups.elementAt(g);
\r
366 if (currentColours.getState())
\r
367 sg.cs = new AnnotationColourGradient(
\r
369 sg.cs, aboveThreshold);
\r
371 sg.cs = new AnnotationColourGradient(
\r
373 minColour.getBackground(),
\r
374 maxColour.getBackground(),
\r
386 av.setGlobalColourScheme(oldcs);
\r
387 if (av.alignment.getGroups() != null)
\r
389 Vector allGroups = ap.av.alignment.getGroups();
\r
391 for (int g = 0; g < allGroups.size(); g++)
\r
393 sg = (SequenceGroup) allGroups.elementAt(g);
\r
394 sg.cs = (ColourSchemeI)oldgroupColours.get(sg);
\r