2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.bin.JalviewLite;
\r
24 import jalview.datamodel.AlignmentAnnotation;
\r
25 import jalview.datamodel.GraphLine;
\r
26 import jalview.datamodel.SequenceGroup;
\r
27 import jalview.schemes.AnnotationColourGradient;
\r
28 import jalview.schemes.ColourSchemeI;
\r
29 import jalview.util.MessageManager;
\r
31 import java.awt.BorderLayout;
\r
32 import java.awt.Color;
\r
33 import java.awt.Dimension;
\r
34 import java.awt.FlowLayout;
\r
35 import java.awt.Font;
\r
36 import java.awt.event.ActionEvent;
\r
37 import java.awt.event.ActionListener;
\r
38 import java.awt.event.AdjustmentEvent;
\r
39 import java.awt.event.AdjustmentListener;
\r
40 import java.awt.event.ItemEvent;
\r
41 import java.awt.event.ItemListener;
\r
42 import java.awt.event.MouseEvent;
\r
43 import java.awt.event.MouseListener;
\r
44 import java.util.Hashtable;
\r
45 import java.util.Vector;
\r
47 import javax.swing.JButton;
\r
48 import javax.swing.JCheckBox;
\r
49 import javax.swing.JComboBox;
\r
50 import javax.swing.JFrame;
\r
51 import javax.swing.JPanel;
\r
52 import javax.swing.JScrollBar;
\r
53 import javax.swing.JTextField;
\r
55 public class AnnotationColourChooser extends JPanel implements
\r
56 ActionListener, AdjustmentListener, ItemListener, MouseListener
\r
64 ColourSchemeI oldcs;
\r
66 Hashtable oldgroupColours;
\r
68 AlignmentAnnotation currentAnnotation;
\r
70 boolean adjusting = false;
\r
72 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
77 } catch (Exception ex)
\r
81 oldcs = av.getGlobalColourScheme();
\r
82 if (av.getAlignment().getGroups() != null)
\r
84 oldgroupColours = new Hashtable();
\r
85 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
\r
89 oldgroupColours.put(sg, sg.cs);
\r
93 oldgroupColours.put(sg, "null");
\r
100 slider.addAdjustmentListener(this);
\r
101 slider.addMouseListener(this);
\r
103 if (av.getAlignment().getAlignmentAnnotation() == null)
\r
108 setDefaultMinMax();
\r
111 if (oldcs instanceof AnnotationColourGradient)
\r
113 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
114 currentColours.setSelected(acg.isPredefinedColours()
\r
115 || acg.getBaseColour() != null);
\r
116 if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
\r
118 minColour.setBackground(acg.getMinColour());
\r
119 maxColour.setBackground(acg.getMaxColour());
\r
121 // seqAssociated.setState(acg.isSeqAssociated());
\r
124 Vector list = new Vector();
\r
126 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
\r
128 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
\r
129 if (!list.contains(label))
\r
131 list.addElement(label);
\r
135 list.addElement(label + "_" + (index++));
\r
139 for (int i = 0; i < list.size(); i++)
\r
141 annotations.addItem(list.elementAt(i).toString());
\r
144 threshold.addItem(MessageManager
\r
145 .getString("label.threshold_feature_no_thereshold"));
\r
146 threshold.addItem(MessageManager
\r
147 .getString("label.threshold_feature_above_thereshold"));
\r
148 threshold.addItem(MessageManager
\r
149 .getString("label.threshold_feature_below_thereshold"));
\r
151 if (oldcs instanceof AnnotationColourGradient)
\r
153 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
\r
154 annotations.select(acg.getAnnotation());
\r
155 switch (acg.getAboveThreshold())
\r
157 case AnnotationColourGradient.NO_THRESHOLD:
\r
158 threshold.select(0);
\r
160 case AnnotationColourGradient.ABOVE_THRESHOLD:
\r
161 threshold.select(1);
\r
163 case AnnotationColourGradient.BELOW_THRESHOLD:
\r
164 threshold.select(1);
\r
169 .getString("error.implementation_error_dont_know_thereshold_annotationcolourgradient"));
\r
171 thresholdIsMin.setSelected(acg.thresholdIsMinMax);
\r
172 thresholdValue.setText("" + acg.getAnnotationThreshold());
\r
179 frame = new JFrame();
\r
181 JalviewLite.addFrame(frame,
\r
182 MessageManager.getString("label.colour_by_annotation"), 560,
\r
187 private void setDefaultMinMax()
\r
189 minColour.setBackground(av.applet.getDefaultColourParameter(
\r
190 "ANNOTATIONCOLOUR_MIN", Color.orange));
\r
191 maxColour.setBackground(av.applet.getDefaultColourParameter(
\r
192 "ANNOTATIONCOLOUR_MAX", Color.red));
\r
196 public AnnotationColourChooser()
\r
201 } catch (Exception ex)
\r
203 ex.printStackTrace();
\r
207 private void jbInit() throws Exception
\r
209 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
210 minColour.setLabel(MessageManager.getString("label.min_colour"));
\r
211 minColour.addActionListener(this);
\r
213 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
214 maxColour.setLabel(MessageManager.getString("label.max_colour"));
\r
215 maxColour.addActionListener(this);
\r
217 thresholdIsMin.addItemListener(this);
\r
218 ok.setLabel(MessageManager.getString("action.ok"));
\r
219 ok.addActionListener(this);
\r
221 cancel.setLabel(MessageManager.getString("action.cancel"));
\r
222 cancel.addActionListener(this);
\r
224 defColours.setLabel(MessageManager.getString("action.set_defaults"));
\r
225 defColours.addActionListener(this);
\r
227 annotations.addItemListener(this);
\r
229 thresholdValue.addActionListener(this);
\r
230 slider.setBackground(Color.white);
\r
231 slider.setPreferredSize(new Dimension(193, 21));
\r
232 slider.setEnabled(false);
\r
233 thresholdValue.setPreferredSize(new Dimension(79, 22));
\r
234 thresholdValue.setEnabled(false);
\r
235 thresholdValue.setColumns(5);
\r
236 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
237 currentColours.setLabel(MessageManager
\r
238 .getString("label.use_original_colours"));
\r
239 currentColours.addItemListener(this);
\r
241 thresholdIsMin.setBackground(Color.white);
\r
242 thresholdIsMin.setLabel(MessageManager
\r
243 .getString("label.threshold_minmax"));
\r
245 this.setLayout(borderLayout1);
\r
247 jPanel1.setBackground(Color.white);
\r
249 jPanel2.setLayout(new FlowLayout());
\r
250 jPanel2.setBackground(Color.white);
\r
251 threshold.addItemListener(this);
\r
252 jPanel3.setLayout(new FlowLayout());
\r
253 jPanel3.setBackground(Color.white);
\r
254 JPanel jPanel4 = new JPanel();
\r
255 jPanel4.setLayout(new BorderLayout());
\r
256 jPanel4.setBackground(Color.white);
\r
259 jPanel1.add(cancel);
\r
261 jPanel2.add(annotations);
\r
262 jPanel2.add(currentColours);
\r
263 jPanel2.add(minColour);
\r
264 jPanel2.add(maxColour);
\r
266 jPanel4.add(thresholdIsMin, BorderLayout.WEST);
\r
267 jPanel4.add(slider, BorderLayout.CENTER);
\r
268 jPanel4.add(thresholdValue, BorderLayout.EAST);
\r
270 JPanel jPanel34 = new JPanel();
\r
271 jPanel34.setLayout(new BorderLayout());
\r
272 jPanel34.setBackground(Color.white);
\r
273 jPanel34.add(jPanel2, BorderLayout.NORTH);
\r
274 jPanel34.add(threshold, BorderLayout.WEST);
\r
275 jPanel3.add(defColours);
\r
276 jPanel34.add(jPanel3, BorderLayout.EAST);
\r
277 jPanel34.add(jPanel4, BorderLayout.SOUTH);
\r
279 this.add(jPanel34, java.awt.BorderLayout.CENTER);
\r
280 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
284 Choice annotations = new Choice();
\r
286 JButton minColour = new JButton();
\r
288 JButton maxColour = new JButton();
\r
290 JButton ok = new JButton();
\r
292 JButton cancel = new JButton();
\r
294 JButton defColours = new JButton();
\r
296 JPanel jPanel1 = new JPanel();
\r
298 JPanel jPanel2 = new JPanel();
\r
300 Choice threshold = new Choice();
\r
302 FlowLayout flowLayout1 = new FlowLayout();
\r
304 JPanel jPanel3 = new JPanel();
\r
306 JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL);
\r
308 JTextField thresholdValue = new JTextField(20);
\r
310 JCheckBox currentColours = new JCheckBox();
\r
312 BorderLayout borderLayout1 = new BorderLayout();
\r
314 JCheckBox thresholdIsMin = new JCheckBox();
\r
316 public void actionPerformed(ActionEvent evt)
\r
318 if (evt.getSource() == thresholdValue)
\r
322 float f = new Float(thresholdValue.getText()).floatValue();
\r
323 slider.setValue((int) (f * 1000));
\r
324 adjustmentValueChanged(null);
\r
325 } catch (NumberFormatException ex)
\r
329 else if (evt.getSource() == minColour)
\r
331 minColour_actionPerformed(null);
\r
333 else if (evt.getSource() == maxColour)
\r
335 maxColour_actionPerformed(null);
\r
337 else if (evt.getSource() == defColours)
\r
339 defColour_actionPerformed();
\r
341 else if (evt.getSource() == ok)
\r
344 frame.setVisible(false);
\r
346 else if (evt.getSource() == cancel)
\r
349 ap.paintAlignment(true);
\r
350 frame.setVisible(false);
\r
359 public void itemStateChanged(ItemEvent evt)
\r
361 if (evt.getSource() == currentColours)
\r
363 if (currentColours.isSelected())
\r
368 maxColour.setEnabled(!currentColours.isSelected());
\r
369 minColour.setEnabled(!currentColours.isSelected());
\r
376 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
380 thresholdValue.setText((slider.getValue() / 1000f) + "");
\r
381 if (currentColours.isSelected()
\r
382 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
\r
387 currentAnnotation.threshold.value = slider.getValue() / 1000f;
\r
388 ap.paintAlignment(false);
\r
392 public void minColour_actionPerformed(Color newCol)
\r
394 if (newCol != null)
\r
396 minColour.setBackground(newCol);
\r
397 minColour.repaint();
\r
402 new UserDefinedColours(this, "Min Colour", minColour.getBackground());
\r
407 public void maxColour_actionPerformed(Color newCol)
\r
409 if (newCol != null)
\r
411 maxColour.setBackground(newCol);
\r
412 maxColour.repaint();
\r
417 new UserDefinedColours(this, "Max Colour", maxColour.getBackground());
\r
421 public void defColour_actionPerformed()
\r
423 setDefaultMinMax();
\r
424 minColour.repaint();
\r
425 maxColour.repaint();
\r
429 void changeColour()
\r
431 // Check if combobox is still adjusting
\r
437 currentAnnotation = av.getAlignment().getAlignmentAnnotation()[annotations
\r
438 .getSelectedIndex()];
\r
440 int aboveThreshold = -1;
\r
441 if (threshold.getSelectedIndex() == 1)
\r
443 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
445 else if (threshold.getSelectedIndex() == 2)
\r
447 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
450 slider.setEnabled(true);
\r
451 thresholdValue.setEnabled(true);
\r
452 thresholdIsMin.setEnabled(true);
\r
454 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
\r
456 slider.setEnabled(false);
\r
457 thresholdValue.setEnabled(false);
\r
458 thresholdIsMin.setEnabled(false);
\r
459 thresholdValue.setText("");
\r
461 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
\r
462 && currentAnnotation.threshold == null)
\r
465 .setThreshold(new GraphLine(
\r
466 (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f,
\r
467 "Threshold", Color.black));
\r
470 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
\r
474 slider.setMinimum((int) (currentAnnotation.graphMin * 1000));
\r
475 slider.setMaximum((int) (currentAnnotation.graphMax * 1000));
\r
476 slider.setValue((int) (currentAnnotation.threshold.value * 1000));
\r
477 thresholdValue.setText(currentAnnotation.threshold.value + "");
\r
478 slider.setEnabled(true);
\r
479 thresholdValue.setEnabled(true);
\r
483 AnnotationColourGradient acg = null;
\r
484 if (currentColours.isSelected())
\r
486 acg = new AnnotationColourGradient(currentAnnotation,
\r
487 av.getGlobalColourScheme(), aboveThreshold);
\r
491 acg = new AnnotationColourGradient(currentAnnotation,
\r
492 minColour.getBackground(), maxColour.getBackground(),
\r
496 if (currentAnnotation.graphMin == 0f
\r
497 && currentAnnotation.graphMax == 0f)
\r
499 acg.setPredefinedColours(true);
\r
502 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
\r
504 av.setGlobalColourScheme(acg);
\r
506 // TODO: per group colour propagation not always desired
\r
507 if (av.getAlignment().getGroups() != null)
\r
509 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
\r
517 if (currentColours.isSelected())
\r
519 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
\r
524 sg.cs = new AnnotationColourGradient(currentAnnotation,
\r
525 minColour.getBackground(), maxColour.getBackground(),
\r
532 // update colours in linked windows
\r
533 ap.alignmentChanged();
\r
534 ap.paintAlignment(true);
\r
539 av.setGlobalColourScheme(oldcs);
\r
540 if (av.getAlignment().getGroups() != null)
\r
542 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
\r
544 Object cs = oldgroupColours.get(sg);
\r
545 if (cs instanceof ColourSchemeI)
\r
547 sg.cs = (ColourSchemeI) cs;
\r
551 // probably the "null" string we set it to if it was null originally.
\r
556 ap.paintAlignment(true);
\r
560 public void mouseClicked(MouseEvent evt)
\r
564 public void mousePressed(MouseEvent evt)
\r
568 public void mouseReleased(MouseEvent evt)
\r
570 ap.paintAlignment(true);
\r
573 public void mouseEntered(MouseEvent evt)
\r
577 public void mouseExited(MouseEvent evt)
\r