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.ActionEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.beans.PropertyVetoException;
33 import java.util.List;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JLayeredPane;
37 import javax.swing.event.ChangeEvent;
38 import javax.swing.event.ChangeListener;
39 import javax.swing.event.InternalFrameAdapter;
40 import javax.swing.event.InternalFrameEvent;
48 public class SliderPanel extends GSliderPanel
50 private static final String BACKGROUND = "Background";
52 static JInternalFrame conservationSlider;
54 static JInternalFrame PIDSlider;
58 boolean forConservation = true;
63 * Returns the currently displayed slider panel (or null if none).
67 public static SliderPanel getSliderPanel()
69 if (conservationSlider != null && conservationSlider.isVisible())
71 return (SliderPanel) conservationSlider.getContentPane();
73 if (PIDSlider != null && PIDSlider.isVisible())
75 return (SliderPanel) PIDSlider.getContentPane();
81 * Creates a new SliderPanel object.
92 public SliderPanel(final AlignmentPanel ap, int value,
93 boolean forConserve, ResidueShaderI scheme)
97 forConservation = forConserve;
98 undoButton.setVisible(false);
99 applyButton.setVisible(false);
103 label.setText(MessageManager.getString(
104 "label.enter_value_increase_conservation_visibility"));
105 slider.setMinimum(0);
106 slider.setMaximum(100);
110 label.setText(MessageManager.getString(
111 "label.enter_percentage_identity_above_which_colour_residues"));
112 slider.setMinimum(0);
113 slider.setMaximum(100);
116 slider.addChangeListener(new ChangeListener()
119 public void stateChanged(ChangeEvent evt)
121 valueField.setText(String.valueOf(slider.getValue()));
122 valueChanged(slider.getValue());
126 slider.addMouseListener(new MouseAdapter()
129 public void mouseReleased(MouseEvent evt)
131 ap.paintAlignment(true, true);
135 slider.setValue(value);
136 valueField.setText(String.valueOf(value));
140 * Method to 'set focus' of the Conservation slider panel
143 * the panel to repaint on change of slider
145 * the colour scheme to update on change of slider
147 * a text description for the panel's title
151 public static int setConservationSlider(AlignmentPanel ap,
152 ResidueShaderI rs, String source)
154 SliderPanel sliderPanel = null;
156 if (conservationSlider == null)
158 sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
159 conservationSlider = new JInternalFrame();
160 conservationSlider.setContentPane(sliderPanel);
161 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
165 sliderPanel = (SliderPanel) conservationSlider.getContentPane();
166 sliderPanel.valueField
167 .setText(String.valueOf(rs.getConservationInc()));
170 sliderPanel.slider.setValue(rs.getConservationInc());
173 conservationSlider.setTitle(MessageManager.formatMessage(
174 "label.conservation_colour_increment", new String[]
175 { source == null ? BACKGROUND : source }));
177 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
178 if (groups != null && !groups.isEmpty())
180 sliderPanel.setAllGroupsCheckEnabled(true);
184 sliderPanel.setAllGroupsCheckEnabled(false);
187 return sliderPanel.getValue();
191 * Hides the PID slider panel if it is shown
193 public static void hidePIDSlider()
195 if (PIDSlider != null)
199 PIDSlider.setClosed(true);
201 } catch (PropertyVetoException ex)
208 * Hides the conservation slider panel if it is shown
210 public static void hideConservationSlider()
212 if (conservationSlider != null)
216 conservationSlider.setClosed(true);
217 conservationSlider = null;
218 } catch (PropertyVetoException ex)
227 public static void showConservationSlider()
231 if (!conservationSlider.isVisible())
233 Desktop.addInternalFrame(conservationSlider,
234 conservationSlider.getTitle(), true, FRAME_WIDTH,
235 FRAME_HEIGHT, false, true);
236 conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
239 public void internalFrameClosed(InternalFrameEvent e)
241 conservationSlider = null;
244 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
249 * Method to 'set focus' of the PID slider panel
252 * the panel to repaint on change of slider
254 * the colour scheme to update on change of slider
256 * a text description for the panel's title
260 public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
263 int threshold = rs.getThreshold();
265 SliderPanel sliderPanel = null;
267 if (PIDSlider == null)
269 sliderPanel = new SliderPanel(ap, threshold, false, rs);
270 PIDSlider = new JInternalFrame();
271 PIDSlider.setContentPane(sliderPanel);
272 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
276 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
279 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
280 sliderPanel.slider.setValue(rs.getThreshold());
283 PIDSlider.setTitle(MessageManager.formatMessage(
284 "label.percentage_identity_threshold", new String[]
285 { source == null ? BACKGROUND : source }));
287 if (ap.av.getAlignment().getGroups() != null)
289 sliderPanel.setAllGroupsCheckEnabled(true);
293 sliderPanel.setAllGroupsCheckEnabled(false);
296 return sliderPanel.getValue();
304 public static JInternalFrame showPIDSlider()
306 hideConservationSlider();
308 if (!PIDSlider.isVisible())
310 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true,
311 FRAME_WIDTH, FRAME_HEIGHT, false, true);
312 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
313 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
316 public void internalFrameClosed(InternalFrameEvent e)
321 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
327 * Updates the colour scheme with the current (identity threshold or
328 * conservation) percentage value. Also updates all groups if 'apply to all
329 * groups' is selected.
333 public void valueChanged(int percent)
335 if (!forConservation)
337 ap.av.setThreshold(percent);
339 updateColourScheme(percent, cs, null);
341 if (allGroupsCheck.isSelected())
343 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
344 for (SequenceGroup sg : groups)
346 updateColourScheme(percent, sg.getGroupColourScheme(), sg);
350 ap.getSeqPanel().seqCanvas.repaint();
354 * Updates the colour scheme (if not null) with the current (identity
355 * threshold or conservation) percentage value
361 protected void updateColourScheme(int percent, ResidueShaderI scheme,
370 if (!scheme.conservationApplied() && sg != null)
373 * first time the colour scheme has had Conservation shading applied
374 * - compute conservation
376 Conservation c = new Conservation("Group", sg.getSequences(null),
377 sg.getStartRes(), sg.getEndRes());
379 c.verdict(false, ap.av.getConsPercGaps());
380 sg.cs.setConservation(c);
383 scheme.setConservationApplied(true);
384 scheme.setConservationInc(percent);
388 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
398 public void setAllGroupsCheckEnabled(boolean b)
400 allGroupsCheck.setEnabled(b);
410 public void valueField_actionPerformed()
414 int i = Integer.parseInt(valueField.getText());
416 } catch (NumberFormatException ex)
418 valueField.setText(slider.getValue() + "");
428 public void setValue(int value)
430 slider.setValue(value);
436 * @return DOCUMENT ME!
438 public int getValue()
440 return Integer.parseInt(valueField.getText());
444 public void slider_mouseReleased(MouseEvent e)
446 if (ap.overviewPanel != null)
448 ap.overviewPanel.updateOverviewImage();
452 public static int getConservationValue()
454 return getValue(conservationSlider);
457 static int getValue(JInternalFrame slider)
459 return slider == null ? 0
460 : ((SliderPanel) slider.getContentPane()).getValue();
463 public static int getPIDValue()
465 return getValue(PIDSlider);
469 * Answers true if the SliderPanel is for Conservation, false if it is for PID
474 public boolean isForConservation()
476 return forConservation;
480 * Answers the title for the slider panel; this may include 'Background' if
481 * for the alignment, or the group id if for a group
485 public String getTitle()
488 if (isForConservation())
490 if (conservationSlider != null)
492 title = conservationSlider.getTitle();
495 else if (PIDSlider != null)
497 title = PIDSlider.getTitle();