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();
67 JPanel jPanel1 = new JPanel();
69 JPanel jPanel2 = new JPanel();
71 BorderLayout borderLayout1 = new BorderLayout();
73 private JComboBox<String> threshold = new JComboBox<String>();
75 public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
78 oldcs = av.getGlobalColourScheme();
79 if (av.getAlignment().getGroups() != null)
81 oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
82 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
86 oldgroupColours.put(sg, sg.cs);
90 frame = new JInternalFrame();
91 frame.setContentPane(this);
92 frame.setLayer(JLayeredPane.PALETTE_LAYER);
93 Desktop.addInternalFrame(frame,
94 MessageManager.getString("label.colour_by_annotation"), 520,
97 addSliderChangeListener();
98 addSliderMouseListeners();
100 if (av.getAlignment().getAlignmentAnnotation() == null)
105 // Always get default shading from preferences.
109 if (oldcs instanceof AnnotationColourGradient)
111 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
112 currentColours.setSelected(acg.isPredefinedColours()
113 || acg.getBaseColour() != null);
114 if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
116 minColour.setBackground(acg.getMinColour());
117 maxColour.setBackground(acg.getMaxColour());
119 seqAssociated.setSelected(acg.isSeqAssociated());
122 annotations = new JComboBox<String>(
123 getAnnotationItems(seqAssociated.isSelected()));
125 populateThresholdComboBox(threshold);
127 if (oldcs instanceof AnnotationColourGradient)
129 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
130 annotations.setSelectedItem(acg.getAnnotation());
131 switch (acg.getAboveThreshold())
133 case AnnotationColourGradient.NO_THRESHOLD:
134 getThreshold().setSelectedIndex(0);
136 case AnnotationColourGradient.ABOVE_THRESHOLD:
137 getThreshold().setSelectedIndex(1);
139 case AnnotationColourGradient.BELOW_THRESHOLD:
140 getThreshold().setSelectedIndex(2);
143 throw new Error(MessageManager.getString("error.implementation_error_dont_know_about_thereshold_setting"));
145 thresholdIsMin.setSelected(acg.thresholdIsMinMax);
146 thresholdValue.setText("" + acg.getAnnotationThreshold());
152 } catch (Exception ex)
162 public AnnotationColourChooser()
167 } catch (Exception ex)
169 ex.printStackTrace();
173 private void jbInit() throws Exception
175 minColour.setFont(JvSwingUtils.getLabelFont());
176 minColour.setBorder(BorderFactory.createEtchedBorder());
177 minColour.setPreferredSize(new Dimension(40, 20));
178 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
179 minColour.addMouseListener(new MouseAdapter()
182 public void mousePressed(MouseEvent e)
184 if (minColour.isEnabled())
186 minColour_actionPerformed();
190 maxColour.setFont(JvSwingUtils.getLabelFont());
191 maxColour.setBorder(BorderFactory.createEtchedBorder());
192 maxColour.setPreferredSize(new Dimension(40, 20));
193 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
194 maxColour.addMouseListener(new MouseAdapter()
197 public void mousePressed(MouseEvent e)
199 if (maxColour.isEnabled())
201 maxColour_actionPerformed();
206 ok.setText(MessageManager.getString("action.ok"));
207 ok.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
212 ok_actionPerformed(e);
215 cancel.setOpaque(false);
216 cancel.setText(MessageManager.getString("action.cancel"));
217 cancel.addActionListener(new ActionListener()
220 public void actionPerformed(ActionEvent e)
222 cancel_actionPerformed(e);
225 defColours.setOpaque(false);
226 defColours.setText(MessageManager.getString("action.set_defaults"));
227 defColours.setToolTipText(MessageManager
228 .getString("label.reset_min_max_colours_to_defaults"));
229 defColours.addActionListener(new ActionListener()
233 public void actionPerformed(ActionEvent arg0)
235 resetColours_actionPerformed(arg0);
239 annotations.addActionListener(new ActionListener()
242 public void actionPerformed(ActionEvent e)
244 annotations_actionPerformed(e);
247 getThreshold().addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent e)
252 threshold_actionPerformed(e);
255 thresholdValue.addActionListener(new ActionListener()
258 public void actionPerformed(ActionEvent e)
260 thresholdValue_actionPerformed(e);
263 slider.setPaintLabels(false);
264 slider.setPaintTicks(true);
265 slider.setBackground(Color.white);
266 slider.setEnabled(false);
267 slider.setOpaque(false);
268 slider.setPreferredSize(new Dimension(100, 32));
269 thresholdValue.setEnabled(false);
270 thresholdValue.setColumns(7);
271 currentColours.setFont(JvSwingUtils.getLabelFont());
272 currentColours.setOpaque(false);
273 currentColours.setText(MessageManager
274 .getString("label.use_original_colours"));
275 currentColours.addActionListener(new ActionListener()
278 public void actionPerformed(ActionEvent e)
280 currentColours_actionPerformed(e);
283 thresholdIsMin.setBackground(Color.white);
284 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
285 thresholdIsMin.setText(MessageManager
286 .getString("label.threshold_minmax"));
287 thresholdIsMin.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent actionEvent)
292 thresholdIsMin_actionPerformed(actionEvent);
295 seqAssociated.setBackground(Color.white);
296 seqAssociated.setFont(JvSwingUtils.getLabelFont());
297 seqAssociated.setText(MessageManager
298 .getString("label.per_sequence_only"));
299 seqAssociated.addActionListener(new ActionListener()
303 public void actionPerformed(ActionEvent arg0)
305 seqAssociated_actionPerformed(arg0, annotations, seqAssociated);
309 this.setLayout(borderLayout1);
310 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
311 jPanel1.setBackground(Color.white);
312 jPanel2.setBackground(Color.white);
316 jPanel2.add(annotations, "grow, wrap");
317 jPanel2.add(seqAssociated);
318 jPanel2.add(currentColours);
319 JPanel colpanel = new JPanel(new FlowLayout());
320 colpanel.setBackground(Color.white);
321 colpanel.add(minColour);
322 colpanel.add(maxColour);
323 jPanel2.add(colpanel, "wrap");
324 jPanel2.add(getThreshold());
325 jPanel2.add(defColours, "skip 1, wrap");
326 jPanel2.add(thresholdIsMin);
327 jPanel2.add(slider, "grow");
328 jPanel2.add(thresholdValue, "grow");
329 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
330 this.add(jPanel2, java.awt.BorderLayout.CENTER);
334 protected void resetColours_actionPerformed(ActionEvent arg0)
340 private void setDefaultMinMax()
342 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
344 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
348 public void minColour_actionPerformed()
350 Color col = JColorChooser.showDialog(this,
351 MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground());
354 minColour.setBackground(col);
360 public void maxColour_actionPerformed()
362 Color col = JColorChooser.showDialog(this,
363 MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground());
366 maxColour.setBackground(col);
374 av.setGlobalColourScheme(oldcs);
375 if (av.getAlignment().getGroups() != null)
378 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
380 sg.cs = oldgroupColours.get(sg);
385 public void valueChanged(boolean updateAllAnnotation)
387 if (slider.isEnabled())
389 if (currentColours.isSelected()
390 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
394 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
395 propagateSeqAssociatedThreshold(updateAllAnnotation,
396 getCurrentAnnotation());
397 ap.paintAlignment(false);
401 public JComboBox<String> getThreshold()
406 public void setThreshold(JComboBox<String> threshold)
408 this.threshold = threshold;
411 public void currentColours_actionPerformed(ActionEvent e)
413 if (currentColours.isSelected())
417 maxColour.setEnabled(!currentColours.isSelected());
418 minColour.setEnabled(!currentColours.isSelected());
423 public void updateView()
425 // Check if combobox is still adjusting
431 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
432 .getSelectedIndex()]]);
434 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
435 .getSelectedIndex());
437 slider.setEnabled(true);
438 thresholdValue.setEnabled(true);
439 thresholdIsMin.setEnabled(true);
441 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
443 slider.setEnabled(false);
444 thresholdValue.setEnabled(false);
445 thresholdValue.setText("");
446 thresholdIsMin.setEnabled(false);
448 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
449 && getCurrentAnnotation().threshold == null)
451 getCurrentAnnotation()
452 .setThreshold(new jalview.datamodel.GraphLine(
453 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
454 "Threshold", Color.black));
457 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
460 float range = getCurrentAnnotation().graphMax * 1000
461 - getCurrentAnnotation().graphMin * 1000;
463 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
464 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
465 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
466 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
467 slider.setMajorTickSpacing((int) (range / 10f));
468 slider.setEnabled(true);
469 thresholdValue.setEnabled(true);
472 colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem);
474 ap.alignmentChanged();
475 // ensure all associated views (overviews, structures, etc) are notified of
477 ap.paintAlignment(true);