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.analysis.Conservation;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.jbgui.GSliderPanel;
26 import jalview.renderer.ResidueShaderI;
27 import jalview.util.MessageManager;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31 import java.beans.PropertyVetoException;
32 import java.util.List;
34 import javax.swing.JInternalFrame;
35 import javax.swing.JLayeredPane;
36 import javax.swing.event.ChangeEvent;
37 import javax.swing.event.ChangeListener;
38 import javax.swing.event.InternalFrameAdapter;
39 import javax.swing.event.InternalFrameEvent;
47 public class SliderPanel extends GSliderPanel
49 private static final String BACKGROUND = "Background";
51 static JInternalFrame conservationSlider;
53 static JInternalFrame PIDSlider;
57 boolean forConservation = true;
62 * Returns the currently displayed slider panel (or null if none).
66 public static SliderPanel getSliderPanel()
68 if (conservationSlider != null && conservationSlider.isVisible())
70 return (SliderPanel) conservationSlider.getContentPane();
72 if (PIDSlider != null && PIDSlider.isVisible())
74 return (SliderPanel) PIDSlider.getContentPane();
80 * Creates a new SliderPanel object.
91 public SliderPanel(final AlignmentPanel ap, int value,
92 boolean forConserve, ResidueShaderI scheme)
96 forConservation = forConserve;
97 undoButton.setVisible(false);
98 applyButton.setVisible(false);
102 label.setText(MessageManager.getString(
103 "label.enter_value_increase_conservation_visibility"));
104 slider.setMinimum(0);
105 slider.setMaximum(100);
109 label.setText(MessageManager.getString(
110 "label.enter_percentage_identity_above_which_colour_residues"));
111 slider.setMinimum(0);
112 slider.setMaximum(100);
115 slider.addChangeListener(new ChangeListener()
118 public void stateChanged(ChangeEvent evt)
120 valueField.setText(slider.getValue() + "");
121 valueChanged(slider.getValue());
125 slider.addMouseListener(new MouseAdapter()
128 public void mouseReleased(MouseEvent evt)
130 ap.paintAlignment(true, true);
134 slider.setValue(value);
135 valueField.setText(value + "");
139 * Method to 'set focus' of the Conservation slider panel
142 * the panel to repaint on change of slider
144 * the colour scheme to update on change of slider
146 * a text description for the panel's title
150 public static int setConservationSlider(AlignmentPanel ap,
151 ResidueShaderI rs, String source)
153 SliderPanel sliderPanel = null;
155 if (conservationSlider == null)
157 sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
158 conservationSlider = new JInternalFrame();
159 conservationSlider.setContentPane(sliderPanel);
160 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
164 sliderPanel = (SliderPanel) conservationSlider.getContentPane();
165 sliderPanel.valueField
166 .setText(String.valueOf(rs.getConservationInc()));
169 sliderPanel.slider.setValue(rs.getConservationInc());
172 conservationSlider.setTitle(MessageManager.formatMessage(
173 "label.conservation_colour_increment", new String[]
174 { source == null ? BACKGROUND : source }));
176 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
177 if (groups != null && !groups.isEmpty())
179 sliderPanel.setAllGroupsCheckEnabled(true);
183 sliderPanel.setAllGroupsCheckEnabled(false);
186 return sliderPanel.getValue();
190 * Hides the PID slider panel if it is shown
192 public static void hidePIDSlider()
194 if (PIDSlider != null)
198 PIDSlider.setClosed(true);
200 } catch (PropertyVetoException ex)
207 * Hides the conservation slider panel if it is shown
209 public static void hideConservationSlider()
211 if (conservationSlider != null)
215 conservationSlider.setClosed(true);
216 conservationSlider = null;
217 } catch (PropertyVetoException ex)
226 public static void showConservationSlider()
230 if (!conservationSlider.isVisible())
232 Desktop.addInternalFrame(conservationSlider,
233 conservationSlider.getTitle(), 420, 90, false);
234 conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
237 public void internalFrameClosed(InternalFrameEvent e)
239 conservationSlider = null;
242 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
247 * Method to 'set focus' of the PID slider panel
250 * the panel to repaint on change of slider
252 * the colour scheme to update on change of slider
254 * a text description for the panel's title
258 public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
261 int threshold = rs.getThreshold();
263 SliderPanel sliderPanel = null;
265 if (PIDSlider == null)
267 sliderPanel = new SliderPanel(ap, threshold, false, rs);
268 PIDSlider = new JInternalFrame();
269 PIDSlider.setContentPane(sliderPanel);
270 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
274 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
277 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
278 sliderPanel.slider.setValue(rs.getThreshold());
281 PIDSlider.setTitle(MessageManager.formatMessage(
282 "label.percentage_identity_threshold", new String[]
283 { source == null ? BACKGROUND : source }));
285 if (ap.av.getAlignment().getGroups() != null)
287 sliderPanel.setAllGroupsCheckEnabled(true);
291 sliderPanel.setAllGroupsCheckEnabled(false);
294 return sliderPanel.getValue();
302 public static JInternalFrame showPIDSlider()
304 hideConservationSlider();
306 if (!PIDSlider.isVisible())
308 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
310 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
311 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
314 public void internalFrameClosed(InternalFrameEvent e)
319 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
325 * Updates the colour scheme with the current (identity threshold or
326 * conservation) percentage value. Also updates all groups if 'apply to all
327 * groups' is selected.
331 public void valueChanged(int percent)
333 if (!forConservation)
335 ap.av.setThreshold(percent);
337 updateColourScheme(percent, cs, null);
339 if (allGroupsCheck.isSelected())
341 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
342 for (SequenceGroup sg : groups)
344 updateColourScheme(percent, sg.getGroupColourScheme(), sg);
348 ap.getSeqPanel().seqCanvas.repaint();
352 * Updates the colour scheme (if not null) with the current (identity
353 * threshold or conservation) percentage value
359 protected void updateColourScheme(int percent, ResidueShaderI scheme,
368 if (!scheme.conservationApplied() && sg != null)
371 * first time the colour scheme has had Conservation shading applied
372 * - compute conservation
374 Conservation c = new Conservation("Group", sg.getSequences(null),
375 sg.getStartRes(), sg.getEndRes());
377 c.verdict(false, ap.av.getConsPercGaps());
378 sg.cs.setConservation(c);
381 scheme.setConservationApplied(true);
382 scheme.setConservationInc(percent);
386 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
396 public void setAllGroupsCheckEnabled(boolean b)
398 allGroupsCheck.setEnabled(b);
399 allGroupsCheck.setSelected(ap.av.getColourAppliesToAllGroups());
409 public void valueField_actionPerformed()
413 int i = Integer.parseInt(valueField.getText());
415 } catch (NumberFormatException ex)
417 valueField.setText(slider.getValue() + "");
427 public void setValue(int value)
429 slider.setValue(value);
435 * @return DOCUMENT ME!
437 public int getValue()
439 return Integer.parseInt(valueField.getText());
443 public void slider_mouseReleased(MouseEvent e)
445 if (ap.overviewPanel != null)
447 ap.overviewPanel.updateOverviewImage();
451 public static int getConservationValue()
453 return getValue(conservationSlider);
456 static int getValue(JInternalFrame slider)
458 return slider == null ? 0
459 : ((SliderPanel) slider.getContentPane()).getValue();
462 public static int getPIDValue()
464 return getValue(PIDSlider);
468 * Answers true if the SliderPanel is for Conservation, false if it is for PID
473 public boolean isForConservation()
475 return forConservation;
479 * Answers the title for the slider panel; this may include 'Background' if
480 * for the alignment, or the group id if for a group
484 public String getTitle()
487 if (isForConservation())
489 if (conservationSlider != null)
491 title = conservationSlider.getTitle();
494 else if (PIDSlider != null)
496 title = PIDSlider.getTitle();