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.setFrameIcon(null);
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);
181 sliderPanel.allGroupsCheck
182 .setSelected(ap.av.getColourAppliesToAllGroups());
186 sliderPanel.setAllGroupsCheckEnabled(false);
189 return sliderPanel.getValue();
193 * Hides the PID slider panel if it is shown
195 public static void hidePIDSlider()
197 if (PIDSlider != null)
201 PIDSlider.setClosed(true);
203 } catch (PropertyVetoException ex)
210 * Hides the conservation slider panel if it is shown
212 public static void hideConservationSlider()
214 if (conservationSlider != null)
218 conservationSlider.setClosed(true);
219 conservationSlider = null;
220 } catch (PropertyVetoException ex)
229 public static void showConservationSlider()
233 if (!conservationSlider.isVisible())
235 Desktop.addInternalFrame(conservationSlider,
236 conservationSlider.getTitle(), true, FRAME_WIDTH,
237 FRAME_HEIGHT, false, true);
238 conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
241 public void internalFrameClosed(InternalFrameEvent e)
243 conservationSlider = null;
246 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
251 * Method to 'set focus' of the PID slider panel
254 * the panel to repaint on change of slider
256 * the colour scheme to update on change of slider
258 * a text description for the panel's title
262 public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
265 int threshold = rs.getThreshold();
267 SliderPanel sliderPanel = null;
269 if (PIDSlider == null)
271 sliderPanel = new SliderPanel(ap, threshold, false, rs);
272 PIDSlider = new JInternalFrame();
273 PIDSlider.setFrameIcon(null);
274 PIDSlider.setContentPane(sliderPanel);
275 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
279 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
282 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
283 sliderPanel.slider.setValue(rs.getThreshold());
286 PIDSlider.setTitle(MessageManager.formatMessage(
287 "label.percentage_identity_threshold", new String[]
288 { source == null ? BACKGROUND : source }));
290 if (ap.av.getAlignment().getGroups() != null)
292 sliderPanel.setAllGroupsCheckEnabled(true);
296 sliderPanel.setAllGroupsCheckEnabled(false);
299 return sliderPanel.getValue();
307 public static JInternalFrame showPIDSlider()
309 hideConservationSlider();
311 if (!PIDSlider.isVisible())
313 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true,
314 FRAME_WIDTH, FRAME_HEIGHT, false, true);
315 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
316 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
319 public void internalFrameClosed(InternalFrameEvent e)
324 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
330 * Updates the colour scheme with the current (identity threshold or
331 * conservation) percentage value. Also updates all groups if 'apply to all
332 * groups' is selected.
336 public void valueChanged(int percent)
338 if (!forConservation)
340 ap.av.setThreshold(percent);
342 updateColourScheme(percent, cs, null);
344 if (allGroupsCheck.isSelected())
346 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
347 for (SequenceGroup sg : groups)
349 updateColourScheme(percent, sg.getGroupColourScheme(), sg);
353 ap.getSeqPanel().seqCanvas.repaint();
357 * Updates the colour scheme (if not null) with the current (identity
358 * threshold or conservation) percentage value
364 protected void updateColourScheme(int percent, ResidueShaderI scheme,
373 if (!scheme.conservationApplied() && sg != null)
376 * first time the colour scheme has had Conservation shading applied
377 * - compute conservation
379 Conservation c = new Conservation("Group", sg.getSequences(null),
380 sg.getStartRes(), sg.getEndRes());
382 c.verdict(false, ap.av.getConsPercGaps());
383 sg.cs.setConservation(c);
386 scheme.setConservationApplied(true);
387 scheme.setConservationInc(percent);
391 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
401 public void setAllGroupsCheckEnabled(boolean b)
403 allGroupsCheck.setEnabled(b);
413 public void valueField_actionPerformed()
417 int i = Integer.parseInt(valueField.getText());
419 } catch (NumberFormatException ex)
421 valueField.setText(slider.getValue() + "");
431 public void setValue(int value)
433 slider.setValue(value);
439 * @return DOCUMENT ME!
441 public int getValue()
443 return Integer.parseInt(valueField.getText());
447 public void slider_mouseReleased(MouseEvent e)
449 if (ap.overviewPanel != null)
451 ap.overviewPanel.updateOverviewImage();
455 public static int getConservationValue()
457 return getValue(conservationSlider);
460 static int getValue(JInternalFrame slider)
462 return slider == null ? 0
463 : ((SliderPanel) slider.getContentPane()).getValue();
466 public static int getPIDValue()
468 return getValue(PIDSlider);
472 * Answers true if the SliderPanel is for Conservation, false if it is for PID
477 public boolean isForConservation()
479 return forConservation;
483 * Answers the title for the slider panel; this may include 'Background' if
484 * for the alignment, or the group id if for a group
488 public String getTitle()
491 if (isForConservation())
493 if (conservationSlider != null)
495 title = conservationSlider.getTitle();
498 else if (PIDSlider != null)
500 title = PIDSlider.getTitle();