2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
26 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.util.MessageManager;
32 public class AnnotationColourChooser extends Panel implements
33 ActionListener, AdjustmentListener, ItemListener, MouseListener
43 Hashtable oldgroupColours;
45 jalview.datamodel.AlignmentAnnotation currentAnnotation;
47 boolean adjusting = false;
49 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
54 } catch (Exception ex)
58 oldcs = av.getGlobalColourScheme();
59 if (av.getAlignment().getGroups() != null)
61 oldgroupColours = new Hashtable();
62 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
66 oldgroupColours.put(sg, sg.cs);
70 oldgroupColours.put(sg, "null");
77 slider.addAdjustmentListener(this);
78 slider.addMouseListener(this);
80 if (av.getAlignment().getAlignmentAnnotation() == null)
88 if (oldcs instanceof AnnotationColourGradient)
90 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
91 currentColours.setState(acg.isPredefinedColours() || acg.getBaseColour()!=null);
92 if (!acg.isPredefinedColours() && acg.getBaseColour()==null)
94 minColour.setBackground(acg.getMinColour());
95 maxColour.setBackground(acg.getMaxColour());
97 // seqAssociated.setState(acg.isSeqAssociated());
101 Vector list = new Vector();
103 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
105 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
106 if (!list.contains(label))
107 list.addElement(label);
109 list.addElement(label + "_" + (index++));
112 for (int i = 0; i < list.size(); i++)
114 annotations.addItem(list.elementAt(i).toString());
117 threshold.addItem(MessageManager.getString("label.threshold_feature_no_thereshold"));
118 threshold.addItem(MessageManager.getString("label.threshold_feature_above_thereshold"));
119 threshold.addItem(MessageManager.getString("label.threshold_feature_below_thereshold"));
121 if (oldcs instanceof AnnotationColourGradient)
123 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
124 annotations.select(acg.getAnnotation());
125 switch (acg.getAboveThreshold())
127 case AnnotationColourGradient.NO_THRESHOLD:
130 case AnnotationColourGradient.ABOVE_THRESHOLD:
133 case AnnotationColourGradient.BELOW_THRESHOLD:
138 "Implementation error: don't know about threshold setting for current AnnotationColourGradient.");
140 thresholdIsMin.setState(acg.thresholdIsMinMax);
141 thresholdValue.setText("" + acg.getAnnotationThreshold());
150 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.colour_by_annotation"), 560,
155 private void setDefaultMinMax()
157 minColour.setBackground(av.applet.getDefaultColourParameter(
158 "ANNOTATIONCOLOUR_MIN", Color.orange));
159 maxColour.setBackground(av.applet.getDefaultColourParameter(
160 "ANNOTATIONCOLOUR_MAX", Color.red));
164 public AnnotationColourChooser()
169 } catch (Exception ex)
171 ex.printStackTrace();
175 private void jbInit() throws Exception
177 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
178 minColour.setLabel(MessageManager.getString("label.min_colour"));
179 minColour.addActionListener(this);
181 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
182 maxColour.setLabel(MessageManager.getString("label.max_colour"));
183 maxColour.addActionListener(this);
185 thresholdIsMin.addItemListener(this);
186 ok.setLabel(MessageManager.getString("action.ok"));
187 ok.addActionListener(this);
189 cancel.setLabel(MessageManager.getString("action.cancel"));
190 cancel.addActionListener(this);
192 defColours.setLabel(MessageManager.getString("action.set_defaults"));
193 defColours.addActionListener(this);
195 annotations.addItemListener(this);
197 thresholdValue.addActionListener(this);
198 slider.setBackground(Color.white);
199 slider.setPreferredSize(new Dimension(193, 21));
200 slider.setEnabled(false);
201 thresholdValue.setPreferredSize(new Dimension(79, 22));
202 thresholdValue.setEnabled(false);
203 thresholdValue.setColumns(5);
204 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
205 currentColours.setLabel(MessageManager.getString("label.use_original_colours"));
206 currentColours.addItemListener(this);
208 thresholdIsMin.setBackground(Color.white);
209 thresholdIsMin.setLabel(MessageManager.getString("label.threshold_minmax"));
211 this.setLayout(borderLayout1);
213 jPanel1.setBackground(Color.white);
215 jPanel2.setLayout(new FlowLayout());
216 jPanel2.setBackground(Color.white);
217 threshold.addItemListener(this);
218 jPanel3.setLayout(new FlowLayout());
219 jPanel3.setBackground(Color.white);
220 Panel jPanel4 = new Panel();
221 jPanel4.setLayout(new BorderLayout());
222 jPanel4.setBackground(Color.white);
227 jPanel2.add(annotations);
228 jPanel2.add(currentColours);
229 jPanel2.add(minColour);
230 jPanel2.add(maxColour);
232 jPanel4.add(thresholdIsMin, BorderLayout.WEST);
233 jPanel4.add(slider, BorderLayout.CENTER);
234 jPanel4.add(thresholdValue, BorderLayout.EAST);
236 Panel jPanel34 = new Panel();
237 jPanel34.setLayout(new BorderLayout());
238 jPanel34.setBackground(Color.white);
239 jPanel34.add(jPanel2, BorderLayout.NORTH);
240 jPanel34.add(threshold, BorderLayout.WEST);
241 jPanel3.add(defColours);
242 jPanel34.add(jPanel3, BorderLayout.EAST);
243 jPanel34.add(jPanel4, BorderLayout.SOUTH);
245 this.add(jPanel34, java.awt.BorderLayout.CENTER);
246 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
250 Choice annotations = new Choice();
252 Button minColour = new Button();
254 Button maxColour = new Button();
256 Button ok = new Button();
258 Button cancel = new Button();
260 Button defColours = new Button();
262 Panel jPanel1 = new Panel();
264 Panel jPanel2 = new Panel();
266 Choice threshold = new Choice();
268 FlowLayout flowLayout1 = new FlowLayout();
270 Panel jPanel3 = new Panel();
272 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
274 TextField thresholdValue = new TextField(20);
276 Checkbox currentColours = new Checkbox();
278 BorderLayout borderLayout1 = new BorderLayout();
280 Checkbox thresholdIsMin = new Checkbox();
282 public void actionPerformed(ActionEvent evt)
284 if (evt.getSource() == thresholdValue)
288 float f = new Float(thresholdValue.getText()).floatValue();
289 slider.setValue((int) (f * 1000));
290 adjustmentValueChanged(null);
291 } catch (NumberFormatException ex)
295 else if (evt.getSource() == minColour)
297 minColour_actionPerformed(null);
299 else if (evt.getSource() == maxColour)
301 maxColour_actionPerformed(null);
303 else if (evt.getSource() == defColours)
305 defColour_actionPerformed();
307 else if (evt.getSource() == ok)
310 frame.setVisible(false);
312 else if (evt.getSource() == cancel)
315 ap.paintAlignment(true);
316 frame.setVisible(false);
325 public void itemStateChanged(ItemEvent evt)
327 if (evt.getSource() == currentColours)
329 if (currentColours.getState())
334 maxColour.setEnabled(!currentColours.getState());
335 minColour.setEnabled(!currentColours.getState());
342 public void adjustmentValueChanged(AdjustmentEvent evt)
346 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
347 if (currentColours.getState()
348 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
353 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
354 ap.paintAlignment(false);
358 public void minColour_actionPerformed(Color newCol)
362 minColour.setBackground(newCol);
368 new UserDefinedColours(this, "Min Colour", minColour.getBackground());
373 public void maxColour_actionPerformed(Color newCol)
377 maxColour.setBackground(newCol);
383 new UserDefinedColours(this, "Max Colour", maxColour.getBackground());
387 public void defColour_actionPerformed()
397 // Check if combobox is still adjusting
403 currentAnnotation = av.getAlignment().getAlignmentAnnotation()[annotations
404 .getSelectedIndex()];
406 int aboveThreshold = -1;
407 if (threshold.getSelectedIndex()==1)
409 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
411 else if (threshold.getSelectedIndex()==2)
413 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
416 slider.setEnabled(true);
417 thresholdValue.setEnabled(true);
418 thresholdIsMin.setEnabled(true);
420 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
422 slider.setEnabled(false);
423 thresholdValue.setEnabled(false);
424 thresholdIsMin.setEnabled(false);
425 thresholdValue.setText("");
427 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
428 && currentAnnotation.threshold == null)
431 .setThreshold(new jalview.datamodel.GraphLine(
432 (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f,
433 "Threshold", Color.black));
436 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
440 slider.setMinimum((int) (currentAnnotation.graphMin * 1000));
441 slider.setMaximum((int) (currentAnnotation.graphMax * 1000));
442 slider.setValue((int) (currentAnnotation.threshold.value * 1000));
443 thresholdValue.setText(currentAnnotation.threshold.value + "");
444 slider.setEnabled(true);
445 thresholdValue.setEnabled(true);
449 AnnotationColourGradient acg = null;
450 if (currentColours.getState())
452 acg = new AnnotationColourGradient(currentAnnotation,
453 av.getGlobalColourScheme(), aboveThreshold);
457 acg = new AnnotationColourGradient(currentAnnotation,
458 minColour.getBackground(), maxColour.getBackground(),
462 if (currentAnnotation.graphMin == 0f
463 && currentAnnotation.graphMax == 0f)
465 acg.setPredefinedColours(true);
468 acg.thresholdIsMinMax = thresholdIsMin.getState();
470 av.setGlobalColourScheme(acg);
472 // TODO: per group colour propagation not always desired
473 if (av.getAlignment().getGroups() != null)
475 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
483 if (currentColours.getState())
485 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
490 sg.cs = new AnnotationColourGradient(currentAnnotation,
491 minColour.getBackground(), maxColour.getBackground(),
498 // update colours in linked windows
499 ap.alignmentChanged();
500 ap.paintAlignment(true);
505 av.setGlobalColourScheme(oldcs);
506 if (av.getAlignment().getGroups() != null)
508 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
510 Object cs = oldgroupColours.get(sg);
511 if (cs instanceof ColourSchemeI)
513 sg.cs = (ColourSchemeI) cs;
517 // probably the "null" string we set it to if it was null originally.
522 ap.paintAlignment(true);
526 public void mouseClicked(MouseEvent evt)
530 public void mousePressed(MouseEvent evt)
534 public void mouseReleased(MouseEvent evt)
536 ap.paintAlignment(true);
539 public void mouseEntered(MouseEvent evt)
543 public void mouseExited(MouseEvent evt)