2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
27 import jalview.util.MessageManager;
29 public class AnnotationColourChooser extends Panel implements
30 ActionListener, AdjustmentListener, ItemListener, MouseListener
40 Hashtable oldgroupColours;
42 jalview.datamodel.AlignmentAnnotation currentAnnotation;
44 boolean adjusting = false;
46 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
51 } catch (Exception ex)
55 oldcs = av.getGlobalColourScheme();
56 if (av.getAlignment().getGroups() != null)
58 oldgroupColours = new Hashtable();
59 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
63 oldgroupColours.put(sg, sg.cs);
67 oldgroupColours.put(sg, "null");
74 slider.addAdjustmentListener(this);
75 slider.addMouseListener(this);
77 if (av.getAlignment().getAlignmentAnnotation() == null)
85 if (oldcs instanceof AnnotationColourGradient)
87 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
88 currentColours.setState(acg.isPredefinedColours() || acg.getBaseColour()!=null);
89 if (!acg.isPredefinedColours() && acg.getBaseColour()==null)
91 minColour.setBackground(acg.getMinColour());
92 maxColour.setBackground(acg.getMaxColour());
94 // seqAssociated.setState(acg.isSeqAssociated());
98 Vector list = new Vector();
100 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
102 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
103 if (!list.contains(label))
104 list.addElement(label);
106 list.addElement(label + "_" + (index++));
109 for (int i = 0; i < list.size(); i++)
111 annotations.addItem(list.elementAt(i).toString());
114 threshold.addItem(MessageManager.getString("label.threshold_feature_no_thereshold"));
115 threshold.addItem(MessageManager.getString("label.threshold_feature_above_thereshold"));
116 threshold.addItem(MessageManager.getString("label.threshold_feature_below_thereshold"));
118 if (oldcs instanceof AnnotationColourGradient)
120 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
121 annotations.select(acg.getAnnotation());
122 switch (acg.getAboveThreshold())
124 case AnnotationColourGradient.NO_THRESHOLD:
127 case AnnotationColourGradient.ABOVE_THRESHOLD:
130 case AnnotationColourGradient.BELOW_THRESHOLD:
135 "Implementation error: don't know about threshold setting for current AnnotationColourGradient.");
137 thresholdIsMin.setState(acg.thresholdIsMinMax);
138 thresholdValue.setText("" + acg.getAnnotationThreshold());
147 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.colour_by_annotation"), 560,
152 private void setDefaultMinMax()
154 minColour.setBackground(av.applet.getDefaultColourParameter(
155 "ANNOTATIONCOLOUR_MIN", Color.orange));
156 maxColour.setBackground(av.applet.getDefaultColourParameter(
157 "ANNOTATIONCOLOUR_MAX", Color.red));
161 public AnnotationColourChooser()
166 } catch (Exception ex)
168 ex.printStackTrace();
172 private void jbInit() throws Exception
174 minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
175 minColour.setLabel(MessageManager.getString("label.min_colour"));
176 minColour.addActionListener(this);
178 maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
179 maxColour.setLabel(MessageManager.getString("label.max_colour"));
180 maxColour.addActionListener(this);
182 thresholdIsMin.addItemListener(this);
183 ok.setLabel(MessageManager.getString("action.ok"));
184 ok.addActionListener(this);
186 cancel.setLabel(MessageManager.getString("action.cancel"));
187 cancel.addActionListener(this);
189 defColours.setLabel(MessageManager.getString("action.set_defaults"));
190 defColours.addActionListener(this);
192 annotations.addItemListener(this);
194 thresholdValue.addActionListener(this);
195 slider.setBackground(Color.white);
196 slider.setPreferredSize(new Dimension(193, 21));
197 slider.setEnabled(false);
198 thresholdValue.setPreferredSize(new Dimension(79, 22));
199 thresholdValue.setEnabled(false);
200 thresholdValue.setColumns(5);
201 currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
202 currentColours.setLabel(MessageManager.getString("label.use_original_colours"));
203 currentColours.addItemListener(this);
205 thresholdIsMin.setBackground(Color.white);
206 thresholdIsMin.setLabel(MessageManager.getString("label.threshold_minmax"));
208 this.setLayout(borderLayout1);
210 jPanel1.setBackground(Color.white);
212 jPanel2.setLayout(new FlowLayout());
213 jPanel2.setBackground(Color.white);
214 threshold.addItemListener(this);
215 jPanel3.setLayout(new FlowLayout());
216 jPanel3.setBackground(Color.white);
217 Panel jPanel4 = new Panel();
218 jPanel4.setLayout(new BorderLayout());
219 jPanel4.setBackground(Color.white);
224 jPanel2.add(annotations);
225 jPanel2.add(currentColours);
226 jPanel2.add(minColour);
227 jPanel2.add(maxColour);
229 jPanel4.add(thresholdIsMin, BorderLayout.WEST);
230 jPanel4.add(slider, BorderLayout.CENTER);
231 jPanel4.add(thresholdValue, BorderLayout.EAST);
233 Panel jPanel34 = new Panel();
234 jPanel34.setLayout(new BorderLayout());
235 jPanel34.setBackground(Color.white);
236 jPanel34.add(jPanel2, BorderLayout.NORTH);
237 jPanel34.add(threshold, BorderLayout.WEST);
238 jPanel3.add(defColours);
239 jPanel34.add(jPanel3, BorderLayout.EAST);
240 jPanel34.add(jPanel4, BorderLayout.SOUTH);
242 this.add(jPanel34, java.awt.BorderLayout.CENTER);
243 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
247 Choice annotations = new Choice();
249 Button minColour = new Button();
251 Button maxColour = new Button();
253 Button ok = new Button();
255 Button cancel = new Button();
257 Button defColours = new Button();
259 Panel jPanel1 = new Panel();
261 Panel jPanel2 = new Panel();
263 Choice threshold = new Choice();
265 FlowLayout flowLayout1 = new FlowLayout();
267 Panel jPanel3 = new Panel();
269 Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
271 TextField thresholdValue = new TextField(20);
273 Checkbox currentColours = new Checkbox();
275 BorderLayout borderLayout1 = new BorderLayout();
277 Checkbox thresholdIsMin = new Checkbox();
279 public void actionPerformed(ActionEvent evt)
281 if (evt.getSource() == thresholdValue)
285 float f = new Float(thresholdValue.getText()).floatValue();
286 slider.setValue((int) (f * 1000));
287 adjustmentValueChanged(null);
288 } catch (NumberFormatException ex)
292 else if (evt.getSource() == minColour)
294 minColour_actionPerformed(null);
296 else if (evt.getSource() == maxColour)
298 maxColour_actionPerformed(null);
300 else if (evt.getSource() == defColours)
302 defColour_actionPerformed();
304 else if (evt.getSource() == ok)
307 frame.setVisible(false);
309 else if (evt.getSource() == cancel)
312 ap.paintAlignment(true);
313 frame.setVisible(false);
322 public void itemStateChanged(ItemEvent evt)
324 if (evt.getSource() == currentColours)
326 if (currentColours.getState())
331 maxColour.setEnabled(!currentColours.getState());
332 minColour.setEnabled(!currentColours.getState());
339 public void adjustmentValueChanged(AdjustmentEvent evt)
343 thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
344 if (currentColours.getState()
345 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
350 currentAnnotation.threshold.value = (float) slider.getValue() / 1000f;
351 ap.paintAlignment(false);
355 public void minColour_actionPerformed(Color newCol)
359 minColour.setBackground(newCol);
365 new UserDefinedColours(this, "Min Colour", minColour.getBackground());
370 public void maxColour_actionPerformed(Color newCol)
374 maxColour.setBackground(newCol);
380 new UserDefinedColours(this, "Max Colour", maxColour.getBackground());
384 public void defColour_actionPerformed()
394 // Check if combobox is still adjusting
400 currentAnnotation = av.getAlignment().getAlignmentAnnotation()[annotations
401 .getSelectedIndex()];
403 int aboveThreshold = -1;
404 if (threshold.getSelectedIndex()==1)
406 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
408 else if (threshold.getSelectedIndex()==2)
410 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
413 slider.setEnabled(true);
414 thresholdValue.setEnabled(true);
415 thresholdIsMin.setEnabled(true);
417 if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
419 slider.setEnabled(false);
420 thresholdValue.setEnabled(false);
421 thresholdIsMin.setEnabled(false);
422 thresholdValue.setText("");
424 else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
425 && currentAnnotation.threshold == null)
428 .setThreshold(new jalview.datamodel.GraphLine(
429 (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f,
430 "Threshold", Color.black));
433 if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
437 slider.setMinimum((int) (currentAnnotation.graphMin * 1000));
438 slider.setMaximum((int) (currentAnnotation.graphMax * 1000));
439 slider.setValue((int) (currentAnnotation.threshold.value * 1000));
440 thresholdValue.setText(currentAnnotation.threshold.value + "");
441 slider.setEnabled(true);
442 thresholdValue.setEnabled(true);
446 AnnotationColourGradient acg = null;
447 if (currentColours.getState())
449 acg = new AnnotationColourGradient(currentAnnotation,
450 av.getGlobalColourScheme(), aboveThreshold);
454 acg = new AnnotationColourGradient(currentAnnotation,
455 minColour.getBackground(), maxColour.getBackground(),
459 if (currentAnnotation.graphMin == 0f
460 && currentAnnotation.graphMax == 0f)
462 acg.setPredefinedColours(true);
465 acg.thresholdIsMinMax = thresholdIsMin.getState();
467 av.setGlobalColourScheme(acg);
469 // TODO: per group colour propagation not always desired
470 if (av.getAlignment().getGroups() != null)
472 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
480 if (currentColours.getState())
482 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
487 sg.cs = new AnnotationColourGradient(currentAnnotation,
488 minColour.getBackground(), maxColour.getBackground(),
495 // update colours in linked windows
496 ap.alignmentChanged();
497 ap.paintAlignment(true);
502 av.setGlobalColourScheme(oldcs);
503 if (av.getAlignment().getGroups() != null)
505 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
507 Object cs = oldgroupColours.get(sg);
508 if (cs instanceof ColourSchemeI)
510 sg.cs = (ColourSchemeI) cs;
514 // probably the "null" string we set it to if it was null originally.
519 ap.paintAlignment(true);
523 public void mouseClicked(MouseEvent evt)
527 public void mousePressed(MouseEvent evt)
531 public void mouseReleased(MouseEvent evt)
533 ap.paintAlignment(true);
536 public void mouseEntered(MouseEvent evt)
540 public void mouseExited(MouseEvent evt)