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