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.ColourSchemeI;
26 import jalview.util.MessageManager;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31 import java.util.Iterator;
33 import javax.swing.JInternalFrame;
34 import javax.swing.JLayeredPane;
35 import javax.swing.event.ChangeEvent;
36 import javax.swing.event.ChangeListener;
44 public class SliderPanel extends GSliderPanel
46 static JInternalFrame conservationSlider;
48 static JInternalFrame PIDSlider;
52 boolean forConservation = true;
57 * Creates a new SliderPanel object.
68 public SliderPanel(final AlignmentPanel ap, int value,
69 boolean forConserve, ColourSchemeI cs)
73 forConservation = forConserve;
74 undoButton.setVisible(false);
75 applyButton.setVisible(false);
79 label.setText(MessageManager
80 .getString("label.enter_value_increase_conservation_visibility"));
82 slider.setMaximum(100);
86 label.setText(MessageManager
87 .getString("label.enter_percentage_identity_above_which_colour_residues"));
89 slider.setMaximum(100);
92 slider.addChangeListener(new ChangeListener()
94 public void stateChanged(ChangeEvent evt)
96 valueField.setText(slider.getValue() + "");
97 valueChanged(slider.getValue());
101 slider.addMouseListener(new MouseAdapter()
103 public void mouseReleased(MouseEvent evt)
105 ap.paintAlignment(true);
109 slider.setValue(value);
110 valueField.setText(value + "");
123 * @return DOCUMENT ME!
125 public static int setConservationSlider(AlignmentPanel ap,
126 ColourSchemeI cs, String source)
128 SliderPanel sp = null;
130 if (conservationSlider == null)
132 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
133 conservationSlider = new JInternalFrame();
134 conservationSlider.setContentPane(sp);
135 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
139 sp = (SliderPanel) conservationSlider.getContentPane();
143 conservationSlider.setTitle(MessageManager.formatMessage("label.conservation_colour_increment", new String[]{source}));
145 if (ap.av.getAlignment().getGroups() != null)
147 sp.setAllGroupsCheckEnabled(true);
151 sp.setAllGroupsCheckEnabled(false);
154 return sp.getValue();
160 public static void showConservationSlider()
164 PIDSlider.setClosed(true);
166 } catch (Exception ex)
170 if (!conservationSlider.isVisible())
172 Desktop.addInternalFrame(conservationSlider,
173 conservationSlider.getTitle(), 420, 90, false);
175 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
177 public void internalFrameClosed(
178 javax.swing.event.InternalFrameEvent e)
180 conservationSlider = null;
183 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
197 * @return DOCUMENT ME!
199 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
202 SliderPanel pid = null;
204 int threshold = cs.getThreshold();
206 if (PIDSlider == null)
208 pid = new SliderPanel(ap, threshold, false, cs);
209 PIDSlider = new JInternalFrame();
210 PIDSlider.setContentPane(pid);
211 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
215 pid = (SliderPanel) PIDSlider.getContentPane();
219 PIDSlider.setTitle(MessageManager.formatMessage("label.percentage_identity_thereshold", new String[]{source}));
221 if (ap.av.getAlignment().getGroups() != null)
223 pid.setAllGroupsCheckEnabled(true);
227 pid.setAllGroupsCheckEnabled(false);
230 return pid.getValue();
236 public static void showPIDSlider()
240 conservationSlider.setClosed(true);
241 conservationSlider = null;
242 } catch (Exception ex)
246 if (!PIDSlider.isVisible())
248 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
250 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
252 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
254 public void internalFrameClosed(
255 javax.swing.event.InternalFrameEvent e)
260 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
270 public void valueChanged(int i)
277 ColourSchemeI toChange = cs;
278 Iterator<SequenceGroup> allGroups = null;
280 if (allGroupsCheck.isSelected())
282 allGroups = ap.av.getAlignment().getGroups().listIterator();
285 while (toChange != null)
289 toChange.setConservationInc(i);
293 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
295 if (allGroups != null && allGroups.hasNext())
297 while ((toChange = allGroups.next().cs) == null
298 && allGroups.hasNext())
309 ap.getSeqPanel().seqCanvas.repaint();
318 public void setAllGroupsCheckEnabled(boolean b)
320 allGroupsCheck.setEnabled(b);
329 public void valueField_actionPerformed(ActionEvent e)
333 int i = Integer.parseInt(valueField.getText());
335 } catch (NumberFormatException ex)
337 valueField.setText(slider.getValue() + "");
347 public void setValue(int value)
349 slider.setValue(value);
355 * @return DOCUMENT ME!
357 public int getValue()
359 return Integer.parseInt(valueField.getText());
362 public void slider_mouseReleased(MouseEvent e)
364 if (ap.overviewPanel != null)
366 ap.overviewPanel.updateOverviewImage();