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.SequenceGroup;
36 import jalview.schemes.AnnotationColourGradient;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.util.MessageManager;
40 import javax.swing.BorderFactory;
41 import javax.swing.JButton;
42 import javax.swing.JColorChooser;
43 import javax.swing.JComboBox;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
48 import net.miginfocom.swing.MigLayout;
50 @SuppressWarnings("serial")
51 public class AnnotationColourChooser extends AnnotationRowFilter
56 Hashtable<SequenceGroup, ColourSchemeI> oldgroupColours;
59 * enabled if the user is dragging the slider - try to keep updates to a
63 JComboBox<String> annotations;
65 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 Vector<String> annotItems = getAnnotationItems(seqAssociated
124 annotations = new JComboBox<String>(annotItems);
126 populateThresholdComboBox(threshold);
128 if (oldcs instanceof AnnotationColourGradient)
130 AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
131 String label = getAnnotationMenuLabel(acg.getAnnotation());
132 annotations.setSelectedItem(label);
133 switch (acg.getAboveThreshold())
135 case AnnotationColourGradient.NO_THRESHOLD:
136 getThreshold().setSelectedIndex(0);
138 case AnnotationColourGradient.ABOVE_THRESHOLD:
139 getThreshold().setSelectedIndex(1);
141 case AnnotationColourGradient.BELOW_THRESHOLD:
142 getThreshold().setSelectedIndex(2);
147 .getString("error.implementation_error_dont_know_about_threshold_setting"));
149 thresholdIsMin.setSelected(acg.isThresholdIsMinMax());
150 thresholdValue.setText("" + acg.getAnnotationThreshold());
156 } catch (Exception ex)
166 public AnnotationColourChooser()
171 } catch (Exception ex)
173 ex.printStackTrace();
177 private void jbInit() throws Exception
179 minColour.setFont(JvSwingUtils.getLabelFont());
180 minColour.setBorder(BorderFactory.createEtchedBorder());
181 minColour.setPreferredSize(new Dimension(40, 20));
182 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
183 minColour.addMouseListener(new MouseAdapter()
186 public void mousePressed(MouseEvent e)
188 if (minColour.isEnabled())
190 minColour_actionPerformed();
194 maxColour.setFont(JvSwingUtils.getLabelFont());
195 maxColour.setBorder(BorderFactory.createEtchedBorder());
196 maxColour.setPreferredSize(new Dimension(40, 20));
197 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
198 maxColour.addMouseListener(new MouseAdapter()
201 public void mousePressed(MouseEvent e)
203 if (maxColour.isEnabled())
205 maxColour_actionPerformed();
210 ok.setText(MessageManager.getString("action.ok"));
211 ok.addActionListener(new ActionListener()
214 public void actionPerformed(ActionEvent e)
216 ok_actionPerformed();
219 cancel.setOpaque(false);
220 cancel.setText(MessageManager.getString("action.cancel"));
221 cancel.addActionListener(new ActionListener()
224 public void actionPerformed(ActionEvent e)
226 cancel_actionPerformed();
229 defColours.setOpaque(false);
230 defColours.setText(MessageManager.getString("action.set_defaults"));
231 defColours.setToolTipText(MessageManager
232 .getString("label.reset_min_max_colours_to_defaults"));
233 defColours.addActionListener(new ActionListener()
237 public void actionPerformed(ActionEvent arg0)
239 resetColours_actionPerformed();
243 annotations.addActionListener(new ActionListener()
246 public void actionPerformed(ActionEvent e)
248 annotations_actionPerformed();
251 getThreshold().addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent e)
256 threshold_actionPerformed();
259 thresholdValue.addActionListener(new ActionListener()
262 public void actionPerformed(ActionEvent e)
264 thresholdValue_actionPerformed();
267 slider.setPaintLabels(false);
268 slider.setPaintTicks(true);
269 slider.setBackground(Color.white);
270 slider.setEnabled(false);
271 slider.setOpaque(false);
272 slider.setPreferredSize(new Dimension(100, 32));
273 thresholdValue.setEnabled(false);
274 thresholdValue.setColumns(7);
275 currentColours.setFont(JvSwingUtils.getLabelFont());
276 currentColours.setOpaque(false);
277 currentColours.setText(MessageManager
278 .getString("label.use_original_colours"));
279 currentColours.addActionListener(new ActionListener()
282 public void actionPerformed(ActionEvent e)
284 currentColours_actionPerformed();
287 thresholdIsMin.setBackground(Color.white);
288 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
289 thresholdIsMin.setText(MessageManager
290 .getString("label.threshold_minmax"));
291 thresholdIsMin.addActionListener(new ActionListener()
294 public void actionPerformed(ActionEvent actionEvent)
296 thresholdIsMin_actionPerformed();
299 seqAssociated.setBackground(Color.white);
300 seqAssociated.setFont(JvSwingUtils.getLabelFont());
301 seqAssociated.setText(MessageManager
302 .getString("label.per_sequence_only"));
303 seqAssociated.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent arg0)
309 seqAssociated_actionPerformed(annotations);
313 this.setLayout(borderLayout1);
314 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
315 jPanel1.setBackground(Color.white);
316 jPanel2.setBackground(Color.white);
320 jPanel2.add(annotations, "grow, wrap");
321 jPanel2.add(seqAssociated);
322 jPanel2.add(currentColours);
323 JPanel colpanel = new JPanel(new FlowLayout());
324 colpanel.setBackground(Color.white);
325 colpanel.add(minColour);
326 colpanel.add(maxColour);
327 jPanel2.add(colpanel, "wrap");
328 jPanel2.add(getThreshold());
329 jPanel2.add(defColours, "skip 1, wrap");
330 jPanel2.add(thresholdIsMin);
331 jPanel2.add(slider, "grow");
332 jPanel2.add(thresholdValue, "grow");
333 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
334 this.add(jPanel2, java.awt.BorderLayout.CENTER);
338 protected void resetColours_actionPerformed()
344 private void setDefaultMinMax()
346 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
348 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
352 public void minColour_actionPerformed()
354 Color col = JColorChooser.showDialog(this,
355 MessageManager.getString("label.select_colour_minimum_value"),
356 minColour.getBackground());
359 minColour.setBackground(col);
365 public void maxColour_actionPerformed()
367 Color col = JColorChooser.showDialog(this,
368 MessageManager.getString("label.select_colour_maximum_value"),
369 maxColour.getBackground());
372 maxColour.setBackground(col);
381 av.setGlobalColourScheme(oldcs);
382 if (av.getAlignment().getGroups() != null)
385 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
387 sg.cs = oldgroupColours.get(sg);
393 public void valueChanged(boolean updateAllAnnotation)
395 if (slider.isEnabled())
397 if (currentColours.isSelected()
398 && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
402 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
403 propagateSeqAssociatedThreshold(updateAllAnnotation,
404 getCurrentAnnotation());
405 ap.paintAlignment(false);
409 public JComboBox<String> getThreshold()
414 public void setThreshold(JComboBox<String> threshold)
416 this.threshold = threshold;
419 public void currentColours_actionPerformed()
421 if (currentColours.isSelected())
425 maxColour.setEnabled(!currentColours.isSelected());
426 minColour.setEnabled(!currentColours.isSelected());
431 public void updateView()
433 // Check if combobox is still adjusting
439 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
440 .getSelectedIndex()]]);
442 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
443 .getSelectedIndex());
445 slider.setEnabled(true);
446 thresholdValue.setEnabled(true);
447 thresholdIsMin.setEnabled(true);
449 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
451 slider.setEnabled(false);
452 thresholdValue.setEnabled(false);
453 thresholdValue.setText("");
454 thresholdIsMin.setEnabled(false);
456 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
457 && getCurrentAnnotation().threshold == null)
459 getCurrentAnnotation()
461 new jalview.datamodel.GraphLine(
462 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
463 "Threshold", Color.black));
466 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
469 float range = getCurrentAnnotation().graphMax * 1000
470 - getCurrentAnnotation().graphMin * 1000;
472 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
473 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
474 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
475 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
476 slider.setMajorTickSpacing((int) (range / 10f));
477 slider.setEnabled(true);
478 thresholdValue.setEnabled(true);
481 colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem);
483 ap.alignmentChanged();
484 // ensure all associated views (overviews, structures, etc) are notified of
486 ap.paintAlignment(true);