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.renderer.ResidueShaderI;
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 private static final String BACKGROUND = "Background";
49 static JInternalFrame conservationSlider;
51 static JInternalFrame PIDSlider;
55 boolean forConservation = true;
60 * Returns the currently displayed slider panel (or null if none).
64 public static SliderPanel getSliderPanel()
66 if (conservationSlider != null && conservationSlider.isVisible())
68 return (SliderPanel) conservationSlider.getContentPane();
70 if (PIDSlider != null && PIDSlider.isVisible())
72 return (SliderPanel) PIDSlider.getContentPane();
78 * Creates a new SliderPanel object.
89 public SliderPanel(final AlignmentPanel ap, int value,
90 boolean forConserve, ResidueShaderI scheme)
94 forConservation = forConserve;
95 undoButton.setVisible(false);
96 applyButton.setVisible(false);
100 label.setText(MessageManager
101 .getString("label.enter_value_increase_conservation_visibility"));
102 slider.setMinimum(0);
103 slider.setMaximum(100);
107 label.setText(MessageManager
108 .getString("label.enter_percentage_identity_above_which_colour_residues"));
109 slider.setMinimum(0);
110 slider.setMaximum(100);
113 slider.addChangeListener(new ChangeListener()
116 public void stateChanged(ChangeEvent evt)
118 valueField.setText(slider.getValue() + "");
119 valueChanged(slider.getValue());
123 slider.addMouseListener(new MouseAdapter()
126 public void mouseReleased(MouseEvent evt)
128 ap.paintAlignment(true);
132 slider.setValue(value);
133 valueField.setText(value + "");
137 * Method to 'set focus' of the Conservation slider panel
140 * the panel to repaint on change of slider
142 * the colour scheme to update on change of slider
144 * a text description for the panel's title
148 public static int setConservationSlider(AlignmentPanel ap,
149 ResidueShaderI rs, String source)
151 SliderPanel sliderPanel = null;
153 if (conservationSlider == null)
155 sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
156 conservationSlider = new JInternalFrame();
157 conservationSlider.setContentPane(sliderPanel);
158 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
162 sliderPanel = (SliderPanel) conservationSlider.getContentPane();
163 sliderPanel.valueField.setText(String.valueOf(rs.getConservationInc()));
166 sliderPanel.slider.setValue(rs.getConservationInc());
169 conservationSlider.setTitle(MessageManager.formatMessage(
170 "label.conservation_colour_increment",
171 new String[] { source == null ? BACKGROUND : source }));
173 if (ap.av.getAlignment().getGroups() != null)
175 sliderPanel.setAllGroupsCheckEnabled(true);
179 sliderPanel.setAllGroupsCheckEnabled(false);
182 return sliderPanel.getValue();
186 * Hides the PID slider panel if it is shown
188 public static void hidePIDSlider()
190 if (PIDSlider != null)
194 PIDSlider.setClosed(true);
196 } catch (PropertyVetoException ex)
203 * Hides the conservation slider panel if it is shown
205 public static void hideConservationSlider()
207 if (conservationSlider != null)
211 conservationSlider.setClosed(true);
212 conservationSlider = null;
213 } catch (PropertyVetoException ex)
222 public static void showConservationSlider()
226 if (!conservationSlider.isVisible())
228 Desktop.addInternalFrame(conservationSlider,
229 conservationSlider.getTitle(), 420, 90, false);
231 .addInternalFrameListener(new InternalFrameAdapter()
234 public void internalFrameClosed(InternalFrameEvent e)
236 conservationSlider = null;
239 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
244 * Method to 'set focus' of the PID slider panel
247 * the panel to repaint on change of slider
249 * the colour scheme to update on change of slider
251 * a text description for the panel's title
255 public static int setPIDSliderSource(AlignmentPanel ap,
256 ResidueShaderI rs, String source)
258 int threshold = rs.getThreshold();
260 SliderPanel sliderPanel = null;
262 if (PIDSlider == null)
264 sliderPanel = new SliderPanel(ap, threshold, false, rs);
265 PIDSlider = new JInternalFrame();
266 PIDSlider.setContentPane(sliderPanel);
267 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
271 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
274 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
275 sliderPanel.slider.setValue(rs.getThreshold());
278 PIDSlider.setTitle(MessageManager.formatMessage(
279 "label.percentage_identity_threshold",
280 new String[] { source == null ? BACKGROUND : source }));
282 if (ap.av.getAlignment().getGroups() != null)
284 sliderPanel.setAllGroupsCheckEnabled(true);
288 sliderPanel.setAllGroupsCheckEnabled(false);
291 return sliderPanel.getValue();
299 public static JInternalFrame showPIDSlider()
301 hideConservationSlider();
303 if (!PIDSlider.isVisible())
305 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
307 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
308 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
311 public void internalFrameClosed(InternalFrameEvent e)
316 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
322 * Updates the colour scheme with the current (identity threshold or
323 * conservation) percentage value. Also updates all groups if 'apply to all
324 * groups' is selected.
328 public void valueChanged(int percent)
330 if (!forConservation)
332 ap.av.setThreshold(percent);
334 updateColourScheme(percent, cs);
336 if (allGroupsCheck.isSelected())
338 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
340 updateColourScheme(percent, sg.getGroupColourScheme());
344 ap.getSeqPanel().seqCanvas.repaint();
348 * Updates the colour scheme (if not null) with the current (identity
349 * threshold or conservation) percentage value
354 protected void updateColourScheme(int percent, ResidueShaderI scheme)
362 scheme.setConservationInc(percent);
366 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
376 public void setAllGroupsCheckEnabled(boolean b)
378 allGroupsCheck.setEnabled(b);
388 public void valueField_actionPerformed()
392 int i = Integer.parseInt(valueField.getText());
394 } catch (NumberFormatException ex)
396 valueField.setText(slider.getValue() + "");
406 public void setValue(int value)
408 slider.setValue(value);
414 * @return DOCUMENT ME!
416 public int getValue()
418 return Integer.parseInt(valueField.getText());
422 public void slider_mouseReleased(MouseEvent e)
424 if (ap.overviewPanel != null)
426 ap.overviewPanel.updateOverviewImage();
430 public static int getConservationValue()
432 return getValue(conservationSlider);
435 static int getValue(JInternalFrame slider)
437 return slider == null ? 0 : ((SliderPanel) slider.getContentPane())
441 public static int getPIDValue()
443 return getValue(PIDSlider);
447 * Answers true if the SliderPanel is for Conservation, false if it is for PID
452 public boolean isForConservation()
454 return forConservation;
458 * Answers the title for the slider panel; this may include 'Background' if
459 * for the alignment, or the group id if for a group
463 public String getTitle()
466 if (isForConservation())
468 if (conservationSlider != null)
470 title = conservationSlider.getTitle();
473 else if (PIDSlider != null)
475 title = PIDSlider.getTitle();