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 java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Dimension;
26 import java.awt.FlowLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31 import java.util.Hashtable;
32 import java.util.Vector;
34 import jalview.bin.Cache;
35 import jalview.datamodel.GraphLine;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.schemes.AnnotationColourGradient;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.util.MessageManager;
41 import javax.swing.BorderFactory;
42 import javax.swing.JButton;
43 import javax.swing.JColorChooser;
44 import javax.swing.JComboBox;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JLayeredPane;
47 import javax.swing.JPanel;
49 import net.miginfocom.swing.MigLayout;
51 @SuppressWarnings("serial")
52 public class AnnotationColourChooser extends AnnotationRowFilter
57 Hashtable<SequenceGroup, ColourSchemeI> oldgroupColours;
60 * enabled if the user is dragging the slider - try to keep updates to a
64 JComboBox<String> annotations;
66 JButton defColours = new JButton();
68 JPanel jPanel1 = new JPanel();
70 JPanel jPanel2 = new JPanel();
72 BorderLayout borderLayout1 = new BorderLayout();
74 private JComboBox<String> threshold = new JComboBox<String>();
76 public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
79 oldcs = av.getGlobalColourScheme();
80 if (av.getAlignment().getGroups() != null)
82 oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
83 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
87 oldgroupColours.put(sg, sg.cs);
91 frame = new JInternalFrame();
92 frame.setContentPane(this);
93 frame.setLayer(JLayeredPane.PALETTE_LAYER);
94 Desktop.addInternalFrame(frame,
95 MessageManager.getString("label.colour_by_annotation"), 520,
98 addSliderChangeListener();
99 addSliderMouseListeners();
101 if (av.getAlignment().getAlignmentAnnotation() == null)
106 // Always get default shading from preferences.
110 if (oldcs instanceof AnnotationColourGradient)
112 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
113 currentColours.setSelected(acg.isPredefinedColours()
114 || acg.getBaseColour() != null);
115 if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
117 minColour.setBackground(acg.getMinColour());
118 maxColour.setBackground(acg.getMaxColour());
120 seqAssociated.setSelected(acg.isSeqAssociated());
123 Vector<String> annotItems = getAnnotationItems(seqAssociated
125 annotations = new JComboBox<String>(annotItems);
127 populateThresholdComboBox(threshold);
129 if (oldcs instanceof AnnotationColourGradient)
131 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
132 String label = getAnnotationMenuLabel(acg.getAnnotation());
133 annotations.setSelectedItem(label);
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);
148 .getString("error.implementation_error_dont_know_about_threshold_setting"));
150 thresholdIsMin.setSelected(acg.isThresholdIsMinMax());
151 thresholdValue.setText("" + acg.getAnnotationThreshold());
157 } catch (Exception ex)
167 public AnnotationColourChooser()
172 } catch (Exception ex)
174 ex.printStackTrace();
178 private void jbInit() throws Exception
180 minColour.setFont(JvSwingUtils.getLabelFont());
181 minColour.setBorder(BorderFactory.createEtchedBorder());
182 minColour.setPreferredSize(new Dimension(40, 20));
183 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
184 minColour.addMouseListener(new MouseAdapter()
187 public void mousePressed(MouseEvent e)
189 if (minColour.isEnabled())
191 minColour_actionPerformed();
195 maxColour.setFont(JvSwingUtils.getLabelFont());
196 maxColour.setBorder(BorderFactory.createEtchedBorder());
197 maxColour.setPreferredSize(new Dimension(40, 20));
198 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
199 maxColour.addMouseListener(new MouseAdapter()
202 public void mousePressed(MouseEvent e)
204 if (maxColour.isEnabled())
206 maxColour_actionPerformed();
211 ok.setText(MessageManager.getString("action.ok"));
212 ok.addActionListener(new ActionListener()
215 public void actionPerformed(ActionEvent e)
217 ok_actionPerformed();
220 cancel.setOpaque(false);
221 cancel.setText(MessageManager.getString("action.cancel"));
222 cancel.addActionListener(new ActionListener()
225 public void actionPerformed(ActionEvent e)
227 cancel_actionPerformed();
230 defColours.setOpaque(false);
231 defColours.setText(MessageManager.getString("action.set_defaults"));
232 defColours.setToolTipText(MessageManager
233 .getString("label.reset_min_max_colours_to_defaults"));
234 defColours.addActionListener(new ActionListener()
238 public void actionPerformed(ActionEvent arg0)
240 resetColours_actionPerformed();
244 annotations.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 annotations_actionPerformed();
252 getThreshold().addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 threshold_actionPerformed();
260 thresholdValue.addActionListener(new ActionListener()
263 public void actionPerformed(ActionEvent e)
265 thresholdValue_actionPerformed();
268 slider.setPaintLabels(false);
269 slider.setPaintTicks(true);
270 slider.setBackground(Color.white);
271 slider.setEnabled(false);
272 slider.setOpaque(false);
273 slider.setPreferredSize(new Dimension(100, 32));
274 thresholdValue.setEnabled(false);
275 thresholdValue.setColumns(7);
276 currentColours.setFont(JvSwingUtils.getLabelFont());
277 currentColours.setOpaque(false);
278 currentColours.setText(MessageManager
279 .getString("label.use_original_colours"));
280 currentColours.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 currentColours_actionPerformed();
288 thresholdIsMin.setBackground(Color.white);
289 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
290 thresholdIsMin.setText(MessageManager
291 .getString("label.threshold_minmax"));
292 thresholdIsMin.addActionListener(new ActionListener()
295 public void actionPerformed(ActionEvent actionEvent)
297 thresholdIsMin_actionPerformed();
300 seqAssociated.setBackground(Color.white);
301 seqAssociated.setFont(JvSwingUtils.getLabelFont());
302 seqAssociated.setText(MessageManager
303 .getString("label.per_sequence_only"));
304 seqAssociated.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent arg0)
310 seqAssociated_actionPerformed(annotations);
314 this.setLayout(borderLayout1);
315 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
316 jPanel1.setBackground(Color.white);
317 jPanel2.setBackground(Color.white);
321 jPanel2.add(annotations, "grow, wrap");
322 jPanel2.add(seqAssociated);
323 jPanel2.add(currentColours);
324 JPanel colpanel = new JPanel(new FlowLayout());
325 colpanel.setBackground(Color.white);
326 colpanel.add(minColour);
327 colpanel.add(maxColour);
328 jPanel2.add(colpanel, "wrap");
329 jPanel2.add(getThreshold());
330 jPanel2.add(defColours, "skip 1, wrap");
331 jPanel2.add(thresholdIsMin);
332 jPanel2.add(slider, "grow");
333 jPanel2.add(thresholdValue, "grow");
334 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
335 this.add(jPanel2, java.awt.BorderLayout.CENTER);
339 protected void resetColours_actionPerformed()
345 private void setDefaultMinMax()
347 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
349 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
353 public void minColour_actionPerformed()
355 Color col = JColorChooser.showDialog(this,
356 MessageManager.getString("label.select_colour_minimum_value"),
357 minColour.getBackground());
360 minColour.setBackground(col);
366 public void maxColour_actionPerformed()
368 Color col = JColorChooser.showDialog(this,
369 MessageManager.getString("label.select_colour_maximum_value"),
370 maxColour.getBackground());
373 maxColour.setBackground(col);
382 av.setGlobalColourScheme(oldcs);
383 if (av.getAlignment().getGroups() != null)
386 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
388 sg.cs = oldgroupColours.get(sg);
394 public void valueChanged(boolean updateAllAnnotation)
396 if (slider.isEnabled())
398 if (currentColours.isSelected()
399 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
403 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
404 propagateSeqAssociatedThreshold(updateAllAnnotation,
405 getCurrentAnnotation());
406 ap.paintAlignment(false);
410 public JComboBox<String> getThreshold()
415 public void setThreshold(JComboBox<String> threshold)
417 this.threshold = threshold;
420 public void currentColours_actionPerformed()
422 if (currentColours.isSelected())
426 maxColour.setEnabled(!currentColours.isSelected());
427 minColour.setEnabled(!currentColours.isSelected());
432 public void updateView()
434 // Check if combobox is still adjusting
440 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
441 .getSelectedIndex()]]);
443 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
444 .getSelectedIndex());
446 slider.setEnabled(true);
447 thresholdValue.setEnabled(true);
448 thresholdIsMin.setEnabled(true);
450 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
452 slider.setEnabled(false);
453 thresholdValue.setEnabled(false);
454 thresholdValue.setText("");
455 thresholdIsMin.setEnabled(false);
457 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
458 && getCurrentAnnotation().threshold == null)
460 getCurrentAnnotation()
463 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
464 "Threshold", Color.black));
467 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
470 float range = getCurrentAnnotation().graphMax * 1000
471 - getCurrentAnnotation().graphMin * 1000;
473 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
474 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
475 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
476 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
477 slider.setMajorTickSpacing((int) (range / 10f));
478 slider.setEnabled(true);
479 thresholdValue.setEnabled(true);
482 colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem);
484 ap.alignmentChanged();
485 // ensure all associated views (overviews, structures, etc) are notified of
487 ap.paintAlignment(true);