2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import java.awt.Rectangle;
30 public class FeatureColourChooser extends Panel implements
31 ActionListener, AdjustmentListener, ItemListener, MouseListener
42 Hashtable oldgroupColours;
45 boolean adjusting = false;
46 private float min,max;
49 public FeatureColourChooser(FeatureSettings fsettings, String type)
55 float mm[] = ((float[][]) fr.minmax.get(type))[0];
58 oldcs = fr.featureColours.get(type);
59 if (oldcs instanceof GraduatedColor)
61 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
63 // promote original color to a graduated color
64 Color bl = Color.black;
65 if (oldcs instanceof Color)
69 // original colour becomes the maximum colour
70 cs = new GraduatedColor(Color.white,bl,mm[0],mm[1]);
72 minColour.setBackground(cs.getMinColor());
73 maxColour.setBackground(cs.getMaxColor());
79 } catch (Exception ex)
85 slider.addAdjustmentListener(this);
86 slider.addMouseListener(this);
89 jalview.bin.JalviewLite.addFrame(frame, "Graduated Feature Colour for "+type, 480,
94 public FeatureColourChooser()
99 } catch (Exception ex)
101 ex.printStackTrace();
105 private void jbInit() throws Exception
107 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
108 minColour.setLabel("Min Colour");
109 minColour.addActionListener(this);
111 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
112 maxColour.setLabel("Max Colour");
113 maxColour.addActionListener(this);
115 thresholdIsMin.addItemListener(this);
117 ok.addActionListener(this);
119 cancel.setLabel("Cancel");
120 cancel.addActionListener(this);
122 this.setLayout(borderLayout1);
123 jPanel2.setLayout(flowLayout1);
125 jPanel1.setBackground(Color.white);
126 jPanel2.setBackground(Color.white);
127 threshold.addItemListener(this);
128 threshold.addItem("No Threshold");
129 threshold.addItem("Above Threshold");
130 threshold.addItem("Below Threshold");
131 jPanel3.setLayout(null);
132 thresholdValue.addActionListener(this);
134 slider.setBackground(Color.white);
135 slider.setEnabled(false);
136 slider.setBounds(new Rectangle(153, 3, 93, 21));
137 thresholdValue.setEnabled(false);
138 thresholdValue.setBounds(new Rectangle(248, 2, 79, 22));
139 thresholdValue.setColumns(5);
140 jPanel3.setBackground(Color.white);
141 //currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
142 //currentColours.setLabel("Use Original Colours");
143 //currentColours.addItemListener(this);
145 threshold.setBounds(new Rectangle(11, 3, 139, 22));
146 thresholdIsMin.setBackground(Color.white);
147 thresholdIsMin.setLabel("Threshold is min/max");
148 thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23));
151 //jPanel2.add(currentColours);
152 jPanel2.add(minColour);
153 jPanel2.add(maxColour);
154 jPanel3.add(threshold);
156 jPanel3.add(thresholdValue);
157 jPanel3.add(thresholdIsMin);
158 this.add(jPanel2, java.awt.BorderLayout.NORTH);
159 this.add(jPanel3, java.awt.BorderLayout.CENTER);
160 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
163 Button minColour = new Button();
165 Button maxColour = new Button();
167 Button ok = new Button();
169 Button cancel = new Button();
171 Panel jPanel1 = new Panel();
173 Panel jPanel2 = new Panel();
175 Choice threshold = new Choice();
177 FlowLayout flowLayout1 = new FlowLayout();
179 Panel jPanel3 = new Panel();
181 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
183 TextField thresholdValue = new TextField(20);
186 BorderLayout borderLayout1 = new BorderLayout();
188 Checkbox thresholdIsMin = new Checkbox();
190 private GraphLine threshline;
192 public void actionPerformed(ActionEvent evt)
194 if (evt.getSource() == thresholdValue)
198 float f = new Float(thresholdValue.getText()).floatValue();
199 slider.setValue((int) (f * 1000));
200 adjustmentValueChanged(null);
201 } catch (NumberFormatException ex)
205 else if (evt.getSource() == minColour)
207 minColour_actionPerformed(null);
209 else if (evt.getSource() == maxColour)
211 maxColour_actionPerformed(null);
214 else if (evt.getSource() == ok)
217 frame.setVisible(false);
219 else if (evt.getSource() == cancel)
222 ap.paintAlignment(true);
223 frame.setVisible(false);
232 public void itemStateChanged(ItemEvent evt)
238 public void adjustmentValueChanged(AdjustmentEvent evt)
242 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
246 protected void valueChanged() {
248 threshline.value = (float) slider.getValue() / 1000f;
249 ap.paintAlignment(false);
251 public void minColour_actionPerformed(Color newCol)
255 minColour.setBackground(newCol);
261 new UserDefinedColours(this, "Select Colour for Minimum Value", minColour.getBackground());
266 public void maxColour_actionPerformed(Color newCol)
270 maxColour.setBackground(newCol);
276 new UserDefinedColours(this, "Select Colour for Maximum Value", maxColour.getBackground());
282 // Check if combobox is still adjusting
288 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
289 if (threshold.getSelectedItem().equals("Above Threshold"))
291 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
293 else if (threshold.getSelectedItem().equals("Below Threshold"))
295 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
298 slider.setEnabled(true);
299 thresholdValue.setEnabled(true);
300 GraduatedColor acg = new GraduatedColor(minColour.getBackground(), maxColour.getBackground(), min, max);
302 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
304 slider.setEnabled(false);
305 thresholdValue.setEnabled(false);
306 thresholdValue.setText("");
309 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
310 && threshline == null)
312 // todo visual indication of feature threshold
313 threshline = new jalview.datamodel.GraphLine(
315 "Threshold", Color.black);
318 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
321 acg.setThresh(threshline.value);
323 float range = max * 1000f
326 slider.setMinimum((int) (min * 1000));
327 slider.setMaximum((int) (max * 1000));
328 slider.setValue((int) (threshline.value * 1000));
329 thresholdValue.setText(threshline.value + "");
330 slider.setEnabled(true);
331 thresholdValue.setEnabled(true);
335 acg.setThreshType(aboveThreshold);
336 if (thresholdIsMin.getState() && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
338 if (aboveThreshold==AnnotationColourGradient.ABOVE_THRESHOLD)
340 acg = new GraduatedColor(acg, threshline.value, max);
342 acg = new GraduatedColor(acg, min,threshline.value);
346 fr.featureColours.put(type,acg);
348 ap.paintAlignment(false);
353 fr.featureColours.put(type, oldcs);
354 ap.paintAlignment(true);
358 public void mouseClicked(MouseEvent evt)
362 public void mousePressed(MouseEvent evt)
366 public void mouseReleased(MouseEvent evt)
368 ap.paintAlignment(true);
371 public void mouseEntered(MouseEvent evt)
375 public void mouseExited(MouseEvent evt)