X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSliderPanel.java;h=940bab27a161d51cc861073dd64c9ca458983678;hb=cb51e62fe2166b236ef488e0a8f35081fcd71388;hp=1793a9be9edb27fa88adead5581c1d42762ea561;hpb=b2b7e99113e1f0962140fc72d989cc826799a2d4;p=jalview.git diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 1793a9b..940bab2 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.analysis.Conservation; import jalview.datamodel.SequenceGroup; import jalview.jbgui.GSliderPanel; import jalview.renderer.ResidueShaderI; @@ -28,6 +29,7 @@ import jalview.util.MessageManager; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyVetoException; +import java.util.List; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; @@ -42,11 +44,10 @@ import javax.swing.event.InternalFrameEvent; * @author $author$ * @version $Revision$ */ +@SuppressWarnings("serial") public class SliderPanel extends GSliderPanel { - static JInternalFrame conservationSlider; - - static JInternalFrame PIDSlider; + private static final String BACKGROUND = "Background"; AlignmentPanel ap; @@ -54,16 +55,27 @@ public class SliderPanel extends GSliderPanel ResidueShaderI cs; - private static SliderPanel sliderPanel; - /** - * Returns the currently active slider panel (or null if none). + * Returns the currently displayed slider panel (or null if none). * * @return */ public static SliderPanel getSliderPanel() { - return sliderPanel; + + JInternalFrame conservationSlider = getConservationSlider(); + + JInternalFrame PIDSlider = getPIDSlider(); + + if (conservationSlider != null && conservationSlider.isVisible()) + { + return (SliderPanel) conservationSlider.getContentPane(); + } + if (PIDSlider != null && PIDSlider.isVisible()) + { + return (SliderPanel) PIDSlider.getContentPane(); + } + return null; } /** @@ -89,15 +101,15 @@ public class SliderPanel extends GSliderPanel if (forConservation) { - label.setText(MessageManager - .getString("label.enter_value_increase_conservation_visibility")); + label.setText(MessageManager.getString( + "label.enter_value_increase_conservation_visibility")); slider.setMinimum(0); slider.setMaximum(100); } else { - label.setText(MessageManager - .getString("label.enter_percentage_identity_above_which_colour_residues")); + label.setText(MessageManager.getString( + "label.enter_percentage_identity_above_which_colour_residues")); slider.setMinimum(0); slider.setMaximum(100); } @@ -107,7 +119,7 @@ public class SliderPanel extends GSliderPanel @Override public void stateChanged(ChangeEvent evt) { - valueField.setText(slider.getValue() + ""); + valueField.setText(String.valueOf(slider.getValue())); valueChanged(slider.getValue()); } }); @@ -117,51 +129,57 @@ public class SliderPanel extends GSliderPanel @Override public void mouseReleased(MouseEvent evt) { - ap.paintAlignment(true); + ap.paintAlignment(true, true); } }); slider.setValue(value); - valueField.setText(value + ""); + valueField.setText(String.valueOf(value)); } /** - * DOCUMENT ME! + * Method to 'set focus' of the Conservation slider panel * * @param ap - * DOCUMENT ME! - * @param ccs - * DOCUMENT ME! + * the panel to repaint on change of slider + * @param rs + * the colour scheme to update on change of slider * @param source - * DOCUMENT ME! + * a text description for the panel's title * - * @return DOCUMENT ME! + * @return */ public static int setConservationSlider(AlignmentPanel ap, - ResidueShaderI ccs, String source) + ResidueShaderI rs, String source) { - sliderPanel = null; + SliderPanel sliderPanel = null; + + JInternalFrame conservationSlider = getConservationSlider(); if (conservationSlider == null) { - sliderPanel = new SliderPanel(ap, ccs.getConservationInc(), true, ccs); - conservationSlider = new JInternalFrame(); + sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); + conservationSlider = Desktop + .getInstance().conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { sliderPanel = (SliderPanel) conservationSlider.getContentPane(); - sliderPanel.valueField.setText(String.valueOf(ccs.getConservationInc())); - sliderPanel.cs = ccs; + sliderPanel.valueField + .setText(String.valueOf(rs.getConservationInc())); + sliderPanel.cs = rs; + sliderPanel.ap = ap; + sliderPanel.slider.setValue(rs.getConservationInc()); } - conservationSlider - .setTitle(MessageManager.formatMessage( - "label.conservation_colour_increment", - new String[] { source })); + conservationSlider.setTitle(MessageManager.formatMessage( + "label.conservation_colour_increment", new String[] + { source == null ? BACKGROUND : source })); - if (ap.av.getAlignment().getGroups() != null) + List groups = ap.av.getAlignment().getGroups(); + if (groups != null && !groups.isEmpty()) { sliderPanel.setAllGroupsCheckEnabled(true); } @@ -178,12 +196,14 @@ public class SliderPanel extends GSliderPanel */ public static void hidePIDSlider() { + JInternalFrame PIDSlider = getPIDSlider(); + if (PIDSlider != null) { try { PIDSlider.setClosed(true); - PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } catch (PropertyVetoException ex) { } @@ -195,12 +215,14 @@ public class SliderPanel extends GSliderPanel */ public static void hideConservationSlider() { + JInternalFrame conservationSlider = getConservationSlider(); + if (conservationSlider != null) { try { conservationSlider.setClosed(true); - conservationSlider = null; + Desktop.getInstance().conservationSlider = null; } catch (PropertyVetoException ex) { } @@ -214,58 +236,65 @@ public class SliderPanel extends GSliderPanel { hidePIDSlider(); + JInternalFrame conservationSlider = getConservationSlider(); + if (!conservationSlider.isVisible()) { Desktop.addInternalFrame(conservationSlider, - conservationSlider.getTitle(), 420, 90, false); - conservationSlider - .addInternalFrameListener(new InternalFrameAdapter() - { - @Override - public void internalFrameClosed(InternalFrameEvent e) - { - conservationSlider = null; - } - }); + conservationSlider.getTitle(), true, FRAME_WIDTH, + FRAME_HEIGHT, false, true); + conservationSlider.addInternalFrameListener(new InternalFrameAdapter() + { + @Override + public void internalFrameClosed(InternalFrameEvent e) + { + Desktop.getInstance().conservationSlider = null; + } + }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } } /** - * DOCUMENT ME! + * Method to 'set focus' of the PID slider panel * * @param ap - * DOCUMENT ME! - * @param ccs - * DOCUMENT ME! + * the panel to repaint on change of slider + * @param rs + * the colour scheme to update on change of slider * @param source - * DOCUMENT ME! + * a text description for the panel's title * - * @return DOCUMENT ME! + * @return */ - public static int setPIDSliderSource(AlignmentPanel ap, - ResidueShaderI ccs, String source) + public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs, + String source) { - int threshold = ccs.getThreshold(); + int threshold = rs.getThreshold(); + + SliderPanel sliderPanel = null; + + JInternalFrame PIDSlider = getPIDSlider(); if (PIDSlider == null) { - sliderPanel = new SliderPanel(ap, threshold, false, ccs); - PIDSlider = new JInternalFrame(); + sliderPanel = new SliderPanel(ap, threshold, false, rs); + PIDSlider = Desktop.getInstance().PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { sliderPanel = (SliderPanel) PIDSlider.getContentPane(); - sliderPanel.cs = ccs; - sliderPanel.valueField.setText(String.valueOf(ccs.getThreshold())); + sliderPanel.cs = rs; + sliderPanel.ap = ap; + sliderPanel.valueField.setText(String.valueOf(rs.getThreshold())); + sliderPanel.slider.setValue(rs.getThreshold()); } - PIDSlider - .setTitle(MessageManager.formatMessage( - "label.percentage_identity_threshold", - new String[] { source })); + PIDSlider.setTitle(MessageManager.formatMessage( + "label.percentage_identity_threshold", new String[] + { source == null ? BACKGROUND : source })); if (ap.av.getAlignment().getGroups() != null) { @@ -288,17 +317,19 @@ public class SliderPanel extends GSliderPanel { hideConservationSlider(); + JInternalFrame PIDSlider = getPIDSlider(); + if (!PIDSlider.isVisible()) { - Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90, - false); + Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true, + FRAME_WIDTH, FRAME_HEIGHT, false, true); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); PIDSlider.addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameClosed(InternalFrameEvent e) { - PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -319,13 +350,14 @@ public class SliderPanel extends GSliderPanel { ap.av.setThreshold(percent); } - updateColourScheme(percent, cs); + updateColourScheme(percent, cs, null); if (allGroupsCheck.isSelected()) { - for (SequenceGroup sg : ap.av.getAlignment().getGroups()) + List groups = ap.av.getAlignment().getGroups(); + for (SequenceGroup sg : groups) { - updateColourScheme(percent, sg.getGroupColourScheme()); + updateColourScheme(percent, sg.getGroupColourScheme(), sg); } } @@ -338,8 +370,10 @@ public class SliderPanel extends GSliderPanel * * @param percent * @param scheme + * @param sg */ - protected void updateColourScheme(int percent, ResidueShaderI scheme) + protected void updateColourScheme(int percent, ResidueShaderI scheme, + SequenceGroup sg) { if (scheme == null) { @@ -347,6 +381,20 @@ public class SliderPanel extends GSliderPanel } if (forConservation) { + if (!scheme.conservationApplied() && sg != null) + { + /* + * first time the colour scheme has had Conservation shading applied + * - compute conservation + */ + Conservation c = new Conservation("Group", sg.getSequences(null), + sg.getStartRes(), sg.getEndRes()); + c.calculate(); + c.verdict(false, ap.av.getConsPercGaps()); + sg.cs.setConservation(c); + + } + scheme.setConservationApplied(true); scheme.setConservationInc(percent); } else @@ -415,22 +463,6 @@ public class SliderPanel extends GSliderPanel } } - public static int getConservationValue() - { - return getValue(conservationSlider); - } - - static int getValue(JInternalFrame slider) - { - return slider == null ? 0 : ((SliderPanel) slider.getContentPane()) - .getValue(); - } - - public static int getPIDValue() - { - return getValue(PIDSlider); - } - /** * Answers true if the SliderPanel is for Conservation, false if it is for PID * threshold @@ -451,6 +483,9 @@ public class SliderPanel extends GSliderPanel public String getTitle() { String title = null; + JInternalFrame conservationSlider = getConservationSlider(); + JInternalFrame PIDSlider = getPIDSlider(); + if (isForConservation()) { if (conservationSlider != null) @@ -464,4 +499,63 @@ public class SliderPanel extends GSliderPanel } return title; } + + /** + * Returns the singleton instance of the Conservation slider within current + * application scope, or null if there is none + * + * @return + */ + private static JInternalFrame getConservationSlider() + { + return Desktop.getInstance().conservationSlider; + } + + /** + * Returns the singleton instance of the PID slider within current application + * scope, or null if there is none + * + * @return + */ + private static JInternalFrame getPIDSlider() + { + return Desktop.getInstance().PIDSlider; + } + + /** + * Returns the current value of the Conservation slider, or zero if there is + * no such slider + * + * @param slider + * @return + */ + public static int getConservationValue() + { + return getValue(getConservationSlider()); + } + + /** + * Returns the current value of the PID slider, or zero if there is no such + * slider + * + * @param slider + * @return + */ + public static int getPIDValue() + { + return getValue(getPIDSlider()); + } + + /** + * Returns the current value of the given slider, or zero if {@code slider} is + * null + * + * @param slider + * @return + */ + static int getValue(JInternalFrame slider) + { + return slider == null ? 0 + : ((SliderPanel) slider.getContentPane()).getValue(); + } }