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.
23 import jalview.bin.Cache;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.schemes.AnnotationColourGradient;
26 import jalview.schemes.ColourSchemeI;
27 import jalview.util.MessageManager;
29 import java.awt.BorderLayout;
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.MouseAdapter;
36 import java.awt.event.MouseEvent;
37 import java.util.Hashtable;
39 import javax.swing.BorderFactory;
40 import javax.swing.JButton;
41 import javax.swing.JColorChooser;
42 import javax.swing.JComboBox;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLayeredPane;
45 import javax.swing.JPanel;
47 import net.miginfocom.swing.MigLayout;
49 @SuppressWarnings("serial")
50 public class AnnotationColourChooser extends AnnotationRowFilter
55 Hashtable<SequenceGroup, ColourSchemeI> oldgroupColours;
58 * enabled if the user is dragging the slider - try to keep updates to a
62 JComboBox<String> annotations;
64 JButton defColours = new JButton();
66 JButton ok = new JButton();
68 JButton cancel = new JButton();
70 JPanel jPanel1 = new JPanel();
72 JPanel jPanel2 = new JPanel();
74 BorderLayout borderLayout1 = new BorderLayout();
76 private JComboBox<String> threshold = new JComboBox<String>();
78 public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
81 oldcs = av.getGlobalColourScheme();
82 if (av.getAlignment().getGroups() != null)
84 oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
85 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
89 oldgroupColours.put(sg, sg.cs);
93 frame = new JInternalFrame();
94 frame.setContentPane(this);
95 frame.setLayer(JLayeredPane.PALETTE_LAYER);
96 Desktop.addInternalFrame(frame,
97 MessageManager.getString("label.colour_by_annotation"), 520,
100 addSliderChangeListener();
101 addSliderMouseListeners();
103 if (av.getAlignment().getAlignmentAnnotation() == null)
108 // Always get default shading from preferences.
112 if (oldcs instanceof AnnotationColourGradient)
114 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
115 currentColours.setSelected(acg.isPredefinedColours()
116 || acg.getBaseColour() != null);
117 if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
119 minColour.setBackground(acg.getMinColour());
120 maxColour.setBackground(acg.getMaxColour());
122 seqAssociated.setSelected(acg.isSeqAssociated());
125 annotations = new JComboBox<String>(
126 getAnnotationItems(seqAssociated.isSelected()));
128 populateThresholdComboBox(threshold);
130 if (oldcs instanceof AnnotationColourGradient)
132 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
133 annotations.setSelectedItem(acg.getAnnotation());
134 switch (acg.getAboveThreshold())
136 case AnnotationColourGradient.NO_THRESHOLD:
137 getThreshold().setSelectedIndex(0);
139 case AnnotationColourGradient.ABOVE_THRESHOLD:
140 getThreshold().setSelectedIndex(1);
142 case AnnotationColourGradient.BELOW_THRESHOLD:
143 getThreshold().setSelectedIndex(2);
146 throw new Error(MessageManager.getString("error.implementation_error_dont_know_about_thereshold_setting"));
148 thresholdIsMin.setSelected(acg.thresholdIsMinMax);
149 thresholdValue.setText("" + acg.getAnnotationThreshold());
155 } catch (Exception ex)
165 public AnnotationColourChooser()
170 } catch (Exception ex)
172 ex.printStackTrace();
176 private void jbInit() throws Exception
178 minColour.setFont(JvSwingUtils.getLabelFont());
179 minColour.setBorder(BorderFactory.createEtchedBorder());
180 minColour.setPreferredSize(new Dimension(40, 20));
181 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
182 minColour.addMouseListener(new MouseAdapter()
185 public void mousePressed(MouseEvent e)
187 if (minColour.isEnabled())
189 minColour_actionPerformed();
193 maxColour.setFont(JvSwingUtils.getLabelFont());
194 maxColour.setBorder(BorderFactory.createEtchedBorder());
195 maxColour.setPreferredSize(new Dimension(40, 20));
196 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
197 maxColour.addMouseListener(new MouseAdapter()
200 public void mousePressed(MouseEvent e)
202 if (maxColour.isEnabled())
204 maxColour_actionPerformed();
209 ok.setText(MessageManager.getString("action.ok"));
210 ok.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 ok_actionPerformed(e);
218 cancel.setOpaque(false);
219 cancel.setText(MessageManager.getString("action.cancel"));
220 cancel.addActionListener(new ActionListener()
223 public void actionPerformed(ActionEvent e)
225 cancel_actionPerformed(e);
228 defColours.setOpaque(false);
229 defColours.setText(MessageManager.getString("action.set_defaults"));
230 defColours.setToolTipText(MessageManager
231 .getString("label.reset_min_max_colours_to_defaults"));
232 defColours.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent arg0)
238 resetColours_actionPerformed(arg0);
242 annotations.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 annotations_actionPerformed(e);
250 getThreshold().addActionListener(new ActionListener()
253 public void actionPerformed(ActionEvent e)
255 threshold_actionPerformed(e);
258 thresholdValue.addActionListener(new ActionListener()
261 public void actionPerformed(ActionEvent e)
263 thresholdValue_actionPerformed(e);
266 slider.setPaintLabels(false);
267 slider.setPaintTicks(true);
268 slider.setBackground(Color.white);
269 slider.setEnabled(false);
270 slider.setOpaque(false);
271 slider.setPreferredSize(new Dimension(100, 32));
272 thresholdValue.setEnabled(false);
273 thresholdValue.setColumns(7);
274 currentColours.setFont(JvSwingUtils.getLabelFont());
275 currentColours.setOpaque(false);
276 currentColours.setText(MessageManager
277 .getString("label.use_original_colours"));
278 currentColours.addActionListener(new ActionListener()
281 public void actionPerformed(ActionEvent e)
283 currentColours_actionPerformed(e);
286 thresholdIsMin.setBackground(Color.white);
287 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
288 thresholdIsMin.setText(MessageManager
289 .getString("label.threshold_minmax"));
290 thresholdIsMin.addActionListener(new ActionListener()
293 public void actionPerformed(ActionEvent actionEvent)
295 thresholdIsMin_actionPerformed(actionEvent);
298 seqAssociated.setBackground(Color.white);
299 seqAssociated.setFont(JvSwingUtils.getLabelFont());
300 seqAssociated.setText(MessageManager
301 .getString("label.per_sequence_only"));
302 seqAssociated.addActionListener(new ActionListener()
306 public void actionPerformed(ActionEvent arg0)
308 seqAssociated_actionPerformed(arg0, annotations, seqAssociated);
312 this.setLayout(borderLayout1);
313 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
314 jPanel1.setBackground(Color.white);
315 jPanel2.setBackground(Color.white);
319 jPanel2.add(annotations, "grow, wrap");
320 jPanel2.add(seqAssociated);
321 jPanel2.add(currentColours);
322 JPanel colpanel = new JPanel(new FlowLayout());
323 colpanel.setBackground(Color.white);
324 colpanel.add(minColour);
325 colpanel.add(maxColour);
326 jPanel2.add(colpanel, "wrap");
327 jPanel2.add(getThreshold());
328 jPanel2.add(defColours, "skip 1, wrap");
329 jPanel2.add(thresholdIsMin);
330 jPanel2.add(slider, "grow");
331 jPanel2.add(thresholdValue, "grow");
332 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
333 this.add(jPanel2, java.awt.BorderLayout.CENTER);
337 protected void resetColours_actionPerformed(ActionEvent arg0)
343 private void setDefaultMinMax()
345 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
347 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
351 public void minColour_actionPerformed()
353 Color col = JColorChooser.showDialog(this,
354 MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground());
357 minColour.setBackground(col);
363 public void maxColour_actionPerformed()
365 Color col = JColorChooser.showDialog(this,
366 MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground());
369 maxColour.setBackground(col);
377 av.setGlobalColourScheme(oldcs);
378 if (av.getAlignment().getGroups() != null)
381 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
383 sg.cs = oldgroupColours.get(sg);
388 public void valueChanged(boolean updateAllAnnotation)
390 if (slider.isEnabled())
392 if (currentColours.isSelected()
393 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
397 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
398 propagateSeqAssociatedThreshold(updateAllAnnotation,
399 getCurrentAnnotation());
400 ap.paintAlignment(false);
404 public JComboBox<String> getThreshold()
409 public void setThreshold(JComboBox<String> threshold)
411 this.threshold = threshold;
414 public void currentColours_actionPerformed(ActionEvent e)
416 if (currentColours.isSelected())
420 maxColour.setEnabled(!currentColours.isSelected());
421 minColour.setEnabled(!currentColours.isSelected());
426 public void updateView()
428 // Check if combobox is still adjusting
434 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
435 .getSelectedIndex()]]);
437 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
438 .getSelectedIndex());
440 slider.setEnabled(true);
441 thresholdValue.setEnabled(true);
442 thresholdIsMin.setEnabled(true);
444 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
446 slider.setEnabled(false);
447 thresholdValue.setEnabled(false);
448 thresholdValue.setText("");
449 thresholdIsMin.setEnabled(false);
451 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
452 && getCurrentAnnotation().threshold == null)
454 getCurrentAnnotation()
455 .setThreshold(new jalview.datamodel.GraphLine(
456 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
457 "Threshold", Color.black));
460 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
463 float range = getCurrentAnnotation().graphMax * 1000
464 - getCurrentAnnotation().graphMin * 1000;
466 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
467 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
468 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
469 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
470 slider.setMajorTickSpacing((int) (range / 10f));
471 slider.setEnabled(true);
472 thresholdValue.setEnabled(true);
475 colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem);
477 ap.alignmentChanged();
478 // ensure all associated views (overviews, structures, etc) are notified of
480 ap.paintAlignment(true);