2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 JPanel jPanel1 = new JPanel();
68 JPanel jPanel2 = new JPanel();
70 BorderLayout borderLayout1 = new BorderLayout();
72 private JComboBox<String> threshold = new JComboBox<String>();
74 public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
77 oldcs = av.getGlobalColourScheme();
78 if (av.getAlignment().getGroups() != null)
80 oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
81 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
83 if (sg.getColourScheme() != null)
85 oldgroupColours.put(sg, sg.getColourScheme());
89 frame = new JInternalFrame();
90 frame.setContentPane(this);
91 frame.setLayer(JLayeredPane.PALETTE_LAYER);
92 Desktop.addInternalFrame(frame,
93 MessageManager.getString("label.colour_by_annotation"), 520,
96 addSliderChangeListener();
97 addSliderMouseListeners();
99 if (av.getAlignment().getAlignmentAnnotation() == null)
104 // Always get default shading from preferences.
108 if (oldcs instanceof AnnotationColourGradient)
110 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
111 currentColours.setSelected(acg.isPredefinedColours()
112 || acg.getBaseColour() != null);
113 if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
115 minColour.setBackground(acg.getMinColour());
116 maxColour.setBackground(acg.getMaxColour());
118 seqAssociated.setSelected(acg.isSeqAssociated());
121 annotations = new JComboBox<String>(
122 getAnnotationItems(seqAssociated.isSelected()));
124 populateThresholdComboBox(threshold);
126 if (oldcs instanceof AnnotationColourGradient)
128 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
129 annotations.setSelectedItem(acg.getAnnotation());
130 switch (acg.getAboveThreshold())
132 case AnnotationColourGradient.NO_THRESHOLD:
133 getThreshold().setSelectedIndex(0);
135 case AnnotationColourGradient.ABOVE_THRESHOLD:
136 getThreshold().setSelectedIndex(1);
138 case AnnotationColourGradient.BELOW_THRESHOLD:
139 getThreshold().setSelectedIndex(2);
144 .getString("error.implementation_error_dont_know_about_threshold_setting"));
146 thresholdIsMin.setSelected(acg.thresholdIsMinMax);
147 thresholdValue.setText("" + acg.getAnnotationThreshold());
153 } catch (Exception ex)
163 public AnnotationColourChooser()
168 } catch (Exception ex)
170 ex.printStackTrace();
174 private void jbInit() throws Exception
176 minColour.setFont(JvSwingUtils.getLabelFont());
177 minColour.setBorder(BorderFactory.createEtchedBorder());
178 minColour.setPreferredSize(new Dimension(40, 20));
179 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
180 minColour.addMouseListener(new MouseAdapter()
183 public void mousePressed(MouseEvent e)
185 if (minColour.isEnabled())
187 minColour_actionPerformed();
191 maxColour.setFont(JvSwingUtils.getLabelFont());
192 maxColour.setBorder(BorderFactory.createEtchedBorder());
193 maxColour.setPreferredSize(new Dimension(40, 20));
194 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
195 maxColour.addMouseListener(new MouseAdapter()
198 public void mousePressed(MouseEvent e)
200 if (maxColour.isEnabled())
202 maxColour_actionPerformed();
207 ok.setText(MessageManager.getString("action.ok"));
208 ok.addActionListener(new ActionListener()
211 public void actionPerformed(ActionEvent e)
213 ok_actionPerformed();
216 cancel.setOpaque(false);
217 cancel.setText(MessageManager.getString("action.cancel"));
218 cancel.addActionListener(new ActionListener()
221 public void actionPerformed(ActionEvent e)
223 cancel_actionPerformed();
226 defColours.setOpaque(false);
227 defColours.setText(MessageManager.getString("action.set_defaults"));
228 defColours.setToolTipText(MessageManager
229 .getString("label.reset_min_max_colours_to_defaults"));
230 defColours.addActionListener(new ActionListener()
234 public void actionPerformed(ActionEvent arg0)
236 resetColours_actionPerformed();
240 annotations.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 annotations_actionPerformed();
248 getThreshold().addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 threshold_actionPerformed();
256 thresholdValue.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 thresholdValue_actionPerformed();
264 slider.setPaintLabels(false);
265 slider.setPaintTicks(true);
266 slider.setBackground(Color.white);
267 slider.setEnabled(false);
268 slider.setOpaque(false);
269 slider.setPreferredSize(new Dimension(100, 32));
270 thresholdValue.setEnabled(false);
271 thresholdValue.setColumns(7);
272 currentColours.setFont(JvSwingUtils.getLabelFont());
273 currentColours.setOpaque(false);
274 currentColours.setText(MessageManager
275 .getString("label.use_original_colours"));
276 currentColours.addActionListener(new ActionListener()
279 public void actionPerformed(ActionEvent e)
281 currentColours_actionPerformed();
284 thresholdIsMin.setBackground(Color.white);
285 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
286 thresholdIsMin.setText(MessageManager
287 .getString("label.threshold_minmax"));
288 thresholdIsMin.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent actionEvent)
293 thresholdIsMin_actionPerformed();
296 seqAssociated.setBackground(Color.white);
297 seqAssociated.setFont(JvSwingUtils.getLabelFont());
298 seqAssociated.setText(MessageManager
299 .getString("label.per_sequence_only"));
300 seqAssociated.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent arg0)
306 seqAssociated_actionPerformed(annotations);
310 this.setLayout(borderLayout1);
311 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
312 jPanel1.setBackground(Color.white);
313 jPanel2.setBackground(Color.white);
317 jPanel2.add(annotations, "grow, wrap");
318 jPanel2.add(seqAssociated);
319 jPanel2.add(currentColours);
320 JPanel colpanel = new JPanel(new FlowLayout());
321 colpanel.setBackground(Color.white);
322 colpanel.add(minColour);
323 colpanel.add(maxColour);
324 jPanel2.add(colpanel, "wrap");
325 jPanel2.add(getThreshold());
326 jPanel2.add(defColours, "skip 1, wrap");
327 jPanel2.add(thresholdIsMin);
328 jPanel2.add(slider, "grow");
329 jPanel2.add(thresholdValue, "grow");
330 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
331 this.add(jPanel2, java.awt.BorderLayout.CENTER);
335 protected void resetColours_actionPerformed()
341 private void setDefaultMinMax()
343 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
345 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
349 public void minColour_actionPerformed()
351 Color col = JColorChooser.showDialog(this,
352 MessageManager.getString("label.select_colour_minimum_value"),
353 minColour.getBackground());
356 minColour.setBackground(col);
362 public void maxColour_actionPerformed()
364 Color col = JColorChooser.showDialog(this,
365 MessageManager.getString("label.select_colour_maximum_value"),
366 maxColour.getBackground());
369 maxColour.setBackground(col);
378 av.setGlobalColourScheme(oldcs);
379 if (av.getAlignment().getGroups() != null)
382 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
384 sg.setColourScheme(oldgroupColours.get(sg));
390 public void valueChanged(boolean updateAllAnnotation)
392 if (slider.isEnabled())
394 if (currentColours.isSelected()
395 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
399 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
400 propagateSeqAssociatedThreshold(updateAllAnnotation,
401 getCurrentAnnotation());
402 ap.paintAlignment(false);
406 public JComboBox<String> getThreshold()
411 public void setThreshold(JComboBox<String> threshold)
413 this.threshold = threshold;
416 public void currentColours_actionPerformed()
418 if (currentColours.isSelected())
422 maxColour.setEnabled(!currentColours.isSelected());
423 minColour.setEnabled(!currentColours.isSelected());
428 public void updateView()
430 // Check if combobox is still adjusting
436 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
437 .getSelectedIndex()]]);
439 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
440 .getSelectedIndex());
442 slider.setEnabled(true);
443 thresholdValue.setEnabled(true);
444 thresholdIsMin.setEnabled(true);
446 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
448 slider.setEnabled(false);
449 thresholdValue.setEnabled(false);
450 thresholdValue.setText("");
451 thresholdIsMin.setEnabled(false);
453 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
454 && getCurrentAnnotation().threshold == null)
456 getCurrentAnnotation()
458 new jalview.datamodel.GraphLine(
459 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
460 "Threshold", Color.black));
463 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
466 float range = getCurrentAnnotation().graphMax * 1000
467 - getCurrentAnnotation().graphMin * 1000;
469 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
470 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
471 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
472 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
473 slider.setMajorTickSpacing((int) (range / 10f));
474 slider.setEnabled(true);
475 thresholdValue.setEnabled(true);
478 colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem);
480 ap.alignmentChanged();
481 // ensure all associated views (overviews, structures, etc) are notified of
483 ap.paintAlignment(true);