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();
144 .setTitle(MessageManager.formatMessage(
145 "label.conservation_colour_increment",
146 new String[] { source }));
148 if (ap.av.getAlignment().getGroups() != null)
150 sp.setAllGroupsCheckEnabled(true);
154 sp.setAllGroupsCheckEnabled(false);
157 return sp.getValue();
163 public static void showConservationSlider()
167 PIDSlider.setClosed(true);
169 } catch (Exception ex)
173 if (!conservationSlider.isVisible())
175 Desktop.addInternalFrame(conservationSlider,
176 conservationSlider.getTitle(), 420, 90, false);
178 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
180 public void internalFrameClosed(
181 javax.swing.event.InternalFrameEvent e)
183 conservationSlider = null;
186 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
200 * @return DOCUMENT ME!
202 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
205 SliderPanel pid = null;
207 int threshold = cs.getThreshold();
209 if (PIDSlider == null)
211 pid = new SliderPanel(ap, threshold, false, cs);
212 PIDSlider = new JInternalFrame();
213 PIDSlider.setContentPane(pid);
214 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
218 pid = (SliderPanel) PIDSlider.getContentPane();
222 PIDSlider.setTitle(MessageManager
223 .formatMessage("label.percentage_identity_threshold",
224 new String[] { source }));
226 if (ap.av.getAlignment().getGroups() != null)
228 pid.setAllGroupsCheckEnabled(true);
232 pid.setAllGroupsCheckEnabled(false);
235 return pid.getValue();
241 public static void showPIDSlider()
245 conservationSlider.setClosed(true);
246 conservationSlider = null;
247 } catch (Exception ex)
251 if (!PIDSlider.isVisible())
253 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
255 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
257 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
259 public void internalFrameClosed(
260 javax.swing.event.InternalFrameEvent e)
265 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
275 public void valueChanged(int i)
282 ColourSchemeI toChange = cs;
283 Iterator<SequenceGroup> allGroups = null;
285 if (allGroupsCheck.isSelected())
287 allGroups = ap.av.getAlignment().getGroups().listIterator();
290 while (toChange != null)
294 toChange.setConservationInc(i);
298 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
300 if (allGroups != null && allGroups.hasNext())
302 while ((toChange = allGroups.next().cs) == null
303 && allGroups.hasNext())
314 ap.getSeqPanel().seqCanvas.repaint();
323 public void setAllGroupsCheckEnabled(boolean b)
325 allGroupsCheck.setEnabled(b);
334 public void valueField_actionPerformed(ActionEvent e)
338 int i = Integer.parseInt(valueField.getText());
340 } catch (NumberFormatException ex)
342 valueField.setText(slider.getValue() + "");
352 public void setValue(int value)
354 slider.setValue(value);
360 * @return DOCUMENT ME!
362 public int getValue()
364 return Integer.parseInt(valueField.getText());
367 public void slider_mouseReleased(MouseEvent e)
369 if (ap.overviewPanel != null)
371 ap.overviewPanel.updateOverviewImage();