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 java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.beans.PropertyVetoException;
26 import java.util.List;
28 import javax.swing.JInternalFrame;
29 import javax.swing.JLayeredPane;
30 import javax.swing.event.ChangeEvent;
31 import javax.swing.event.ChangeListener;
32 import javax.swing.event.InternalFrameAdapter;
33 import javax.swing.event.InternalFrameEvent;
35 import jalview.analysis.Conservation;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.jbgui.GSliderPanel;
38 import jalview.renderer.ResidueShaderI;
39 import jalview.util.MessageManager;
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(String.valueOf(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(String.valueOf(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);
180 sliderPanel.allGroupsCheck
181 .setSelected(ap.av.getColourAppliesToAllGroups());
185 sliderPanel.setAllGroupsCheckEnabled(false);
188 return sliderPanel.getValue();
192 * Hides the PID slider panel if it is shown
194 public static void hidePIDSlider()
196 if (PIDSlider != null)
200 PIDSlider.setClosed(true);
202 } catch (PropertyVetoException ex)
209 * Hides the conservation slider panel if it is shown
211 public static void hideConservationSlider()
213 if (conservationSlider != null)
217 conservationSlider.setClosed(true);
218 conservationSlider = null;
219 } catch (PropertyVetoException ex)
228 public static void showConservationSlider()
232 if (!conservationSlider.isVisible())
234 Desktop.addInternalFrame(conservationSlider,
235 conservationSlider.getTitle(), Desktop.FRAME_MAKE_VISIBLE, FRAME_WIDTH,
236 FRAME_HEIGHT, Desktop.FRAME_NOT_RESIZABLE, Desktop.FRAME_ALLOW_ANY_SIZE);
237 conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
240 public void internalFrameClosed(InternalFrameEvent e)
242 conservationSlider = null;
245 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
250 * Method to 'set focus' of the PID slider panel
253 * the panel to repaint on change of slider
255 * the colour scheme to update on change of slider
257 * a text description for the panel's title
261 public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
264 int threshold = rs.getThreshold();
266 SliderPanel sliderPanel = null;
268 if (PIDSlider == null)
270 sliderPanel = new SliderPanel(ap, threshold, false, rs);
271 PIDSlider = new JInternalFrame();
272 PIDSlider.setContentPane(sliderPanel);
273 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
277 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
280 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
281 sliderPanel.slider.setValue(rs.getThreshold());
284 PIDSlider.setTitle(MessageManager.formatMessage(
285 "label.percentage_identity_threshold", new String[]
286 { source == null ? BACKGROUND : source }));
288 if (ap.av.getAlignment().getGroups() != null)
290 sliderPanel.setAllGroupsCheckEnabled(true);
294 sliderPanel.setAllGroupsCheckEnabled(false);
297 return sliderPanel.getValue();
305 public static JInternalFrame showPIDSlider()
307 hideConservationSlider();
309 if (!PIDSlider.isVisible())
311 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), Desktop.FRAME_MAKE_VISIBLE,
312 FRAME_WIDTH, FRAME_HEIGHT, Desktop.FRAME_NOT_RESIZABLE, Desktop.FRAME_ALLOW_ANY_SIZE);
313 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
314 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
317 public void internalFrameClosed(InternalFrameEvent e)
322 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
328 * Updates the colour scheme with the current (identity threshold or
329 * conservation) percentage value. Also updates all groups if 'apply to all
330 * groups' is selected.
334 public void valueChanged(int percent)
336 if (!forConservation)
338 ap.av.setThreshold(percent);
340 updateColourScheme(percent, cs, null);
342 if (allGroupsCheck.isSelected())
344 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
345 for (SequenceGroup sg : groups)
347 updateColourScheme(percent, sg.getGroupColourScheme(), sg);
351 ap.getSeqPanel().seqCanvas.repaint();
355 * Updates the colour scheme (if not null) with the current (identity
356 * threshold or conservation) percentage value
362 protected void updateColourScheme(int percent, ResidueShaderI scheme,
371 if (!scheme.conservationApplied() && sg != null)
374 * first time the colour scheme has had Conservation shading applied
375 * - compute conservation
377 Conservation c = new Conservation("Group", sg.getSequences(null),
378 sg.getStartRes(), sg.getEndRes());
380 c.verdict(false, ap.av.getConsPercGaps());
381 sg.cs.setConservation(c);
384 scheme.setConservationApplied(true);
385 scheme.setConservationInc(percent);
389 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
399 public void setAllGroupsCheckEnabled(boolean b)
401 allGroupsCheck.setEnabled(b);
411 public void valueField_actionPerformed()
415 int i = Integer.parseInt(valueField.getText());
417 } catch (NumberFormatException ex)
419 valueField.setText(slider.getValue() + "");
429 public void setValue(int value)
431 slider.setValue(value);
437 * @return DOCUMENT ME!
439 public int getValue()
441 return Integer.parseInt(valueField.getText());
445 public void slider_mouseReleased(MouseEvent e)
447 if (ap.overviewPanel != null)
449 ap.overviewPanel.updateOverviewImage();
453 public static int getConservationValue()
455 return getValue(conservationSlider);
458 static int getValue(JInternalFrame slider)
460 return slider == null ? 0
461 : ((SliderPanel) slider.getContentPane()).getValue();
464 public static int getPIDValue()
466 return getValue(PIDSlider);
470 * Answers true if the SliderPanel is for Conservation, false if it is for PID
475 public boolean isForConservation()
477 return forConservation;
481 * Answers the title for the slider panel; this may include 'Background' if
482 * for the alignment, or the group id if for a group
486 public String getTitle()
489 if (isForConservation())
491 if (conservationSlider != null)
493 title = conservationSlider.getTitle();
496 else if (PIDSlider != null)
498 title = PIDSlider.getTitle();