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())
85 oldgroupColours.put(sg, sg.cs);
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(e);
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(e);
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(arg0);
240 annotations.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 annotations_actionPerformed(e);
248 getThreshold().addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 threshold_actionPerformed(e);
256 thresholdValue.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 thresholdValue_actionPerformed(e);
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(e);
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(actionEvent);
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(arg0, annotations, seqAssociated);
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(ActionEvent arg0)
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);
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()
456 new jalview.datamodel.GraphLine(
457 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
458 "Threshold", Color.black));
461 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
464 float range = getCurrentAnnotation().graphMax * 1000
465 - getCurrentAnnotation().graphMin * 1000;
467 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
468 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
469 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
470 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
471 slider.setMajorTickSpacing((int) (range / 10f));
472 slider.setEnabled(true);
473 thresholdValue.setEnabled(true);
476 colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem);
478 ap.alignmentChanged();
479 // ensure all associated views (overviews, structures, etc) are notified of
481 ap.paintAlignment(true);