2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
24 import java.awt.event.*;
26 import javax.swing.event.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import java.awt.Dimension;
32 public class FeatureColourChooser extends JPanel
43 Hashtable oldgroupColours;
48 boolean adjusting = false;
54 public FeatureColourChooser(FeatureSettings fsettings, String type)
60 frame = new JInternalFrame();
61 frame.setContentPane(this);
62 frame.setLayer(JLayeredPane.PALETTE_LAYER);
63 Desktop.addInternalFrame(frame, "Graduated Feature Colour for "+type, 480, 145);
65 slider.addChangeListener(new ChangeListener()
67 public void stateChanged(ChangeEvent evt)
71 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
76 slider.addMouseListener(new MouseAdapter()
78 public void mouseReleased(MouseEvent evt)
80 if (fr.ap!=null) { fr.ap.paintAlignment(true); };
84 float mm[] = ((float[][]) fr.minmax.get(type))[0];
87 oldcs = fr.featureColours.get(type);
88 if (oldcs instanceof GraduatedColor)
90 cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
92 // promote original color to a graduated color
93 Color bl = Color.black;
94 if (oldcs instanceof Color)
98 // original colour becomes the maximum colour
99 cs = new GraduatedColor(Color.white,bl,mm[0],mm[1]);
101 minColour.setBackground(cs.getMinColor());
102 maxColour.setBackground(cs.getMaxColor());
108 } catch (Exception ex)
118 public FeatureColourChooser()
123 } catch (Exception ex)
125 ex.printStackTrace();
129 private void jbInit() throws Exception
131 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
132 minColour.setBorder(BorderFactory.createEtchedBorder());
133 minColour.setPreferredSize(new Dimension(40, 20));
134 minColour.setToolTipText("Minimum Colour");
135 minColour.addMouseListener(new MouseAdapter()
137 public void mousePressed(MouseEvent e)
139 if (minColour.isEnabled())
141 minColour_actionPerformed();
145 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
146 maxColour.setBorder(BorderFactory.createEtchedBorder());
147 maxColour.setPreferredSize(new Dimension(40, 20));
148 maxColour.setToolTipText("Maximum Colour");
149 maxColour.addMouseListener(new MouseAdapter()
151 public void mousePressed(MouseEvent e)
153 if (maxColour.isEnabled())
155 maxColour_actionPerformed();
161 ok.addActionListener(new ActionListener()
163 public void actionPerformed(ActionEvent e)
165 ok_actionPerformed(e);
168 cancel.setOpaque(false);
169 cancel.setText("Cancel");
170 cancel.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent e)
174 cancel_actionPerformed(e);
177 this.setLayout(borderLayout1);
178 jPanel2.setLayout(flowLayout1);
179 jPanel1.setBackground(Color.white);
180 jPanel2.setBackground(Color.white);
181 threshold.addActionListener(new ActionListener()
183 public void actionPerformed(ActionEvent e)
185 threshold_actionPerformed(e);
188 threshold.addItem("No Threshold");
189 threshold.addItem("Above Threshold");
190 threshold.addItem("Below Threshold");
191 jPanel3.setLayout(flowLayout2);
192 thresholdValue.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent e)
196 thresholdValue_actionPerformed(e);
199 slider.setPaintLabels(false);
200 slider.setPaintTicks(true);
201 slider.setBackground(Color.white);
202 slider.setEnabled(false);
203 slider.setOpaque(false);
204 slider.setPreferredSize(new Dimension(100, 32));
205 thresholdValue.setEnabled(false);
206 thresholdValue.setColumns(7);
207 jPanel3.setBackground(Color.white);
208 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
209 currentColours.setOpaque(false);
210 currentColours.setText("Use Original Colours");
211 currentColours.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 currentColours_actionPerformed(e);
218 thresholdIsMin.setBackground(Color.white);
219 thresholdIsMin.setText("Threshold is Min/Max");
220 thresholdIsMin.addActionListener(new ActionListener()
222 public void actionPerformed(ActionEvent actionEvent)
224 thresholdIsMin_actionPerformed(actionEvent);
229 // jPanel2.add(currentColours);
230 jPanel2.add(minColour);
231 jPanel2.add(maxColour);
232 this.add(jPanel3, java.awt.BorderLayout.CENTER);
233 jPanel3.add(threshold);
235 jPanel3.add(thresholdValue);
236 jPanel3.add(thresholdIsMin);
237 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
238 this.add(jPanel2, java.awt.BorderLayout.NORTH);
242 JPanel minColour = new JPanel();
244 JPanel maxColour = new JPanel();
246 JButton ok = new JButton();
248 JButton cancel = new JButton();
250 JPanel jPanel1 = new JPanel();
252 JPanel jPanel2 = new JPanel();
254 BorderLayout borderLayout1 = new BorderLayout();
256 JComboBox threshold = new JComboBox();
258 FlowLayout flowLayout1 = new FlowLayout();
260 JPanel jPanel3 = new JPanel();
262 FlowLayout flowLayout2 = new FlowLayout();
264 JSlider slider = new JSlider();
266 JTextField thresholdValue = new JTextField(20);
267 // TODO refactor to tolower flag
268 JCheckBox currentColours = new JCheckBox();
270 JCheckBox thresholdIsMin = new JCheckBox();
272 private GraphLine threshline;
274 public void minColour_actionPerformed()
276 Color col = JColorChooser.showDialog(this,
277 "Select Colour for Minimum Value", minColour.getBackground());
280 minColour.setBackground(col);
286 public void maxColour_actionPerformed()
288 Color col = JColorChooser.showDialog(this,
289 "Select Colour for Maximum Value", maxColour.getBackground());
292 maxColour.setBackground(col);
300 // Check if combobox is still adjusting
307 int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
308 if (threshold.getSelectedItem().equals("Above Threshold"))
310 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
312 else if (threshold.getSelectedItem().equals("Below Threshold"))
314 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
317 slider.setEnabled(true);
318 thresholdValue.setEnabled(true);
319 GraduatedColor acg = new GraduatedColor(minColour.getBackground(), maxColour.getBackground(), min, max);
321 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
323 slider.setEnabled(false);
324 thresholdValue.setEnabled(false);
325 thresholdValue.setText("");
327 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
328 && threshline == null)
330 // todo visual indication of feature threshold
331 threshline = new jalview.datamodel.GraphLine(
333 "Threshold", Color.black);
336 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
339 acg.setThresh(threshline.value);
341 float range = max * 1000f
344 slider.setMinimum((int) (min * 1000));
345 slider.setMaximum((int) (max * 1000));
346 slider.setValue((int) (threshline.value * 1000));
347 thresholdValue.setText(threshline.value + "");
348 slider.setMajorTickSpacing((int) (range / 10f));
349 slider.setEnabled(true);
350 thresholdValue.setEnabled(true);
354 acg.setThreshType(aboveThreshold);
355 if (thresholdIsMin.isSelected() && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
357 if (aboveThreshold==AnnotationColourGradient.ABOVE_THRESHOLD)
359 acg = new GraduatedColor(acg, threshline.value, max);
361 acg = new GraduatedColor(acg, min,threshline.value);
365 fr.featureColours.put(type,acg);
367 ap.paintAlignment(false);
370 public void ok_actionPerformed(ActionEvent e)
375 frame.setClosed(true);
376 } catch (Exception ex)
381 public void cancel_actionPerformed(ActionEvent e)
386 frame.setClosed(true);
387 } catch (Exception ex)
394 fr.featureColours.put(type, oldcs);
397 public void thresholdCheck_actionPerformed(ActionEvent e)
402 public void annotations_actionPerformed(ActionEvent e)
407 public void threshold_actionPerformed(ActionEvent e)
412 public void thresholdValue_actionPerformed(ActionEvent e)
416 float f = Float.parseFloat(thresholdValue.getText());
417 slider.setValue((int) (f * 1000));
418 threshline.value = f;
419 } catch (NumberFormatException ex)
424 public void valueChanged()
426 threshline.value = (float) slider.getValue() / 1000f;
427 cs.setThresh(threshline.value);
429 ap.paintAlignment(false);
432 public void currentColours_actionPerformed(ActionEvent e)
434 if (currentColours.isSelected())
439 maxColour.setEnabled(!currentColours.isSelected());
440 minColour.setEnabled(!currentColours.isSelected());
445 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)