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.datamodel.SequenceGroup;
24 import jalview.jbgui.GSliderPanel;
25 import jalview.schemes.CollectionColourSchemeI;
26 import jalview.util.MessageManager;
28 import java.awt.event.MouseAdapter;
29 import java.awt.event.MouseEvent;
30 import java.beans.PropertyVetoException;
32 import javax.swing.JInternalFrame;
33 import javax.swing.JLayeredPane;
34 import javax.swing.event.ChangeEvent;
35 import javax.swing.event.ChangeListener;
36 import javax.swing.event.InternalFrameAdapter;
37 import javax.swing.event.InternalFrameEvent;
45 public class SliderPanel extends GSliderPanel
47 static JInternalFrame conservationSlider;
49 static JInternalFrame PIDSlider;
53 boolean forConservation = true;
55 CollectionColourSchemeI cs;
58 * Creates a new SliderPanel object.
69 public SliderPanel(final AlignmentPanel ap, int value,
70 boolean forConserve, CollectionColourSchemeI scheme)
74 forConservation = forConserve;
75 undoButton.setVisible(false);
76 applyButton.setVisible(false);
80 label.setText(MessageManager
81 .getString("label.enter_value_increase_conservation_visibility"));
83 slider.setMaximum(100);
87 label.setText(MessageManager
88 .getString("label.enter_percentage_identity_above_which_colour_residues"));
90 slider.setMaximum(100);
93 slider.addChangeListener(new ChangeListener()
96 public void stateChanged(ChangeEvent evt)
98 valueField.setText(slider.getValue() + "");
99 valueChanged(slider.getValue());
103 slider.addMouseListener(new MouseAdapter()
106 public void mouseReleased(MouseEvent evt)
108 ap.paintAlignment(true);
112 slider.setValue(value);
113 valueField.setText(value + "");
126 * @return DOCUMENT ME!
128 public static int setConservationSlider(AlignmentPanel ap,
129 CollectionColourSchemeI cs, String source)
131 SliderPanel sp = null;
133 if (conservationSlider == null)
135 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
136 conservationSlider = new JInternalFrame();
137 conservationSlider.setContentPane(sp);
138 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
142 sp = (SliderPanel) conservationSlider.getContentPane();
143 sp.slider.setValue(cs.getConservationInc());
148 .setTitle(MessageManager.formatMessage(
149 "label.conservation_colour_increment",
150 new String[] { source }));
152 if (ap.av.getAlignment().getGroups() != null)
154 sp.setAllGroupsCheckEnabled(true);
158 sp.setAllGroupsCheckEnabled(false);
161 return sp.getValue();
165 * Hides the PID slider panel if it is shown
167 public static void hidePIDSlider()
169 if (PIDSlider != null)
173 PIDSlider.setClosed(true);
175 } catch (PropertyVetoException ex)
182 * Hides the conservation slider panel if it is shown
184 public static void hideConservationSlider()
186 if (conservationSlider != null)
190 conservationSlider.setClosed(true);
191 conservationSlider = null;
192 } catch (PropertyVetoException ex)
201 public static void showConservationSlider()
205 if (!conservationSlider.isVisible())
207 Desktop.addInternalFrame(conservationSlider,
208 conservationSlider.getTitle(), 420, 90, false);
210 .addInternalFrameListener(new InternalFrameAdapter()
213 public void internalFrameClosed(InternalFrameEvent e)
215 conservationSlider = null;
218 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
227 * @param collectionColourScheme
232 * @return DOCUMENT ME!
234 public static int setPIDSliderSource(AlignmentPanel ap,
235 CollectionColourSchemeI collectionColourScheme,
238 SliderPanel pid = null;
240 int threshold = collectionColourScheme.getThreshold();
242 if (PIDSlider == null)
244 pid = new SliderPanel(ap, threshold, false, collectionColourScheme);
245 PIDSlider = new JInternalFrame();
246 PIDSlider.setContentPane(pid);
247 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
251 pid = (SliderPanel) PIDSlider.getContentPane();
252 pid.cs = collectionColourScheme;
253 pid.slider.setValue(collectionColourScheme.getThreshold());
257 .setTitle(MessageManager.formatMessage(
258 "label.percentage_identity_threshold",
259 new String[] { source }));
261 if (ap.av.getAlignment().getGroups() != null)
263 pid.setAllGroupsCheckEnabled(true);
267 pid.setAllGroupsCheckEnabled(false);
270 return pid.getValue();
276 public static void showPIDSlider()
278 hideConservationSlider();
280 if (!PIDSlider.isVisible())
282 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
284 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
285 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
288 public void internalFrameClosed(InternalFrameEvent e)
293 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
298 * Updates the colour scheme with the current (identity threshold or
299 * conservation) percentage value. Also updates all groups if 'apply to all
300 * groups' is selected.
304 public void valueChanged(int percent)
306 if (!forConservation)
308 ap.av.setThreshold(percent);
310 updateColourScheme(percent, cs);
312 if (allGroupsCheck.isSelected())
314 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
316 updateColourScheme(percent, sg.getGroupColourScheme());
320 ap.getSeqPanel().seqCanvas.repaint();
324 * Updates the colour scheme (if not null) with the current (identity
325 * threshold or conservation) percentage value
330 protected void updateColourScheme(int percent, CollectionColourSchemeI scheme)
338 scheme.setConservationInc(percent);
342 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
352 public void setAllGroupsCheckEnabled(boolean b)
354 allGroupsCheck.setEnabled(b);
364 public void valueField_actionPerformed()
368 int i = Integer.parseInt(valueField.getText());
370 } catch (NumberFormatException ex)
372 valueField.setText(slider.getValue() + "");
382 public void setValue(int value)
384 slider.setValue(value);
390 * @return DOCUMENT ME!
392 public int getValue()
394 return Integer.parseInt(valueField.getText());
398 public void slider_mouseReleased(MouseEvent e)
400 if (ap.overviewPanel != null)
402 ap.overviewPanel.updateOverviewImage();
406 public static int getConservationValue()
408 return getValue(conservationSlider);
411 static int getValue(JInternalFrame slider)
413 return slider == null ? 0 : ((SliderPanel) slider.getContentPane())
417 public static int getPIDValue()
419 return getValue(PIDSlider);