X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSliderPanel.java;h=37ab21974dbe015c9305c4b5e118ccc644f9baa7;hb=69b246bd6330f05271ca15a440c8442b03b7db6c;hp=e28778c0325b4a9342526851e1ac829df55a1a2e;hpb=8e1be43e250107a4d86898bd554cf03098fa5957;p=jalview.git diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index e28778c..37ab219 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -20,19 +20,24 @@ */ package jalview.gui; +import jalview.analysis.Conservation; import jalview.datamodel.SequenceGroup; import jalview.jbgui.GSliderPanel; -import jalview.schemes.CollectionColourSchemeI; +import jalview.renderer.ResidueShaderI; import jalview.util.MessageManager; import java.awt.event.ActionEvent; 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; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; /** * DOCUMENT ME! @@ -42,6 +47,8 @@ import javax.swing.event.ChangeListener; */ public class SliderPanel extends GSliderPanel { + private static final String BACKGROUND = "Background"; + static JInternalFrame conservationSlider; static JInternalFrame PIDSlider; @@ -50,7 +57,25 @@ public class SliderPanel extends GSliderPanel boolean forConservation = true; - CollectionColourSchemeI cs; + ResidueShaderI cs; + + /** + * Returns the currently displayed slider panel (or null if none). + * + * @return + */ + public static SliderPanel getSliderPanel() + { + if (conservationSlider != null && conservationSlider.isVisible()) + { + return (SliderPanel) conservationSlider.getContentPane(); + } + if (PIDSlider != null && PIDSlider.isVisible()) + { + return (SliderPanel) PIDSlider.getContentPane(); + } + return null; + } /** * Creates a new SliderPanel object. @@ -65,7 +90,7 @@ public class SliderPanel extends GSliderPanel * DOCUMENT ME! */ public SliderPanel(final AlignmentPanel ap, int value, - boolean forConserve, CollectionColourSchemeI scheme) + boolean forConserve, ResidueShaderI scheme) { this.ap = ap; this.cs = scheme; @@ -75,15 +100,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); } @@ -93,7 +118,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()); } }); @@ -103,172 +128,201 @@ 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 cs - * 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, - CollectionColourSchemeI cs, String source) + ResidueShaderI rs, String source) { - SliderPanel sp = null; + SliderPanel sliderPanel = null; if (conservationSlider == null) { - sp = new SliderPanel(ap, cs.getConservationInc(), true, cs); + sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); conservationSlider = new JInternalFrame(); - conservationSlider.setContentPane(sp); + conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { - sp = (SliderPanel) conservationSlider.getContentPane(); - sp.cs = cs; + sliderPanel = (SliderPanel) conservationSlider.getContentPane(); + 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()) { - sp.setAllGroupsCheckEnabled(true); + sliderPanel.setAllGroupsCheckEnabled(true); + sliderPanel.allGroupsCheck + .setSelected(ap.av.getColourAppliesToAllGroups()); } else { - sp.setAllGroupsCheckEnabled(false); + sliderPanel.setAllGroupsCheckEnabled(false); } - return sp.getValue(); + return sliderPanel.getValue(); } /** - * DOCUMENT ME! + * Hides the PID slider panel if it is shown */ - public static void showConservationSlider() + public static void hidePIDSlider() { - try + if (PIDSlider != null) { - PIDSlider.setClosed(true); - PIDSlider = null; - } catch (Exception ex) + try + { + PIDSlider.setClosed(true); + PIDSlider = null; + } catch (PropertyVetoException ex) + { + } + } + } + + /** + * Hides the conservation slider panel if it is shown + */ + public static void hideConservationSlider() + { + if (conservationSlider != null) { + try + { + conservationSlider.setClosed(true); + conservationSlider = null; + } catch (PropertyVetoException ex) + { + } } + } + + /** + * DOCUMENT ME! + */ + public static void showConservationSlider() + { + hidePIDSlider(); if (!conservationSlider.isVisible()) { Desktop.addInternalFrame(conservationSlider, - conservationSlider.getTitle(), 420, 90, false); - conservationSlider - .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { - @Override - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent e) - { - conservationSlider = null; - } - }); + conservationSlider.getTitle(), true, FRAME_WIDTH, + FRAME_HEIGHT, false, true); + conservationSlider.addInternalFrameListener(new InternalFrameAdapter() + { + @Override + public void internalFrameClosed(InternalFrameEvent e) + { + conservationSlider = null; + } + }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } } /** - * DOCUMENT ME! + * Method to 'set focus' of the PID slider panel * * @param ap - * DOCUMENT ME! - * @param collectionColourScheme - * 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, - CollectionColourSchemeI collectionColourScheme, + public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs, String source) { - SliderPanel pid = null; + int threshold = rs.getThreshold(); - int threshold = collectionColourScheme.getThreshold(); + SliderPanel sliderPanel = null; if (PIDSlider == null) { - pid = new SliderPanel(ap, threshold, false, collectionColourScheme); + sliderPanel = new SliderPanel(ap, threshold, false, rs); PIDSlider = new JInternalFrame(); - PIDSlider.setContentPane(pid); + PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { - pid = (SliderPanel) PIDSlider.getContentPane(); - pid.cs = collectionColourScheme; + sliderPanel = (SliderPanel) PIDSlider.getContentPane(); + 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) { - pid.setAllGroupsCheckEnabled(true); + sliderPanel.setAllGroupsCheckEnabled(true); } else { - pid.setAllGroupsCheckEnabled(false); + sliderPanel.setAllGroupsCheckEnabled(false); } - return pid.getValue(); + return sliderPanel.getValue(); } /** * DOCUMENT ME! + * + * @return */ - public static void showPIDSlider() + public static JInternalFrame showPIDSlider() { - try - { - conservationSlider.setClosed(true); - conservationSlider = null; - } catch (Exception ex) - { - } + hideConservationSlider(); 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 javax.swing.event.InternalFrameAdapter() - { - @Override - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent e) - { - PIDSlider = null; - } - }); + PIDSlider.addInternalFrameListener(new InternalFrameAdapter() + { + @Override + public void internalFrameClosed(InternalFrameEvent e) + { + PIDSlider = null; + } + }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } + return PIDSlider; } /** @@ -284,13 +338,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); } } @@ -303,8 +358,10 @@ public class SliderPanel extends GSliderPanel * * @param percent * @param scheme + * @param sg */ - protected void updateColourScheme(int percent, CollectionColourSchemeI scheme) + protected void updateColourScheme(int percent, ResidueShaderI scheme, + SequenceGroup sg) { if (scheme == null) { @@ -312,6 +369,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 @@ -338,7 +409,7 @@ public class SliderPanel extends GSliderPanel * DOCUMENT ME! */ @Override - public void valueField_actionPerformed(ActionEvent e) + public void valueField_actionPerformed() { try { @@ -387,8 +458,8 @@ public class SliderPanel extends GSliderPanel static int getValue(JInternalFrame slider) { - return slider == null ? 0 : ((SliderPanel) slider.getContentPane()) - .getValue(); + return slider == null ? 0 + : ((SliderPanel) slider.getContentPane()).getValue(); } public static int getPIDValue() @@ -396,4 +467,37 @@ public class SliderPanel extends GSliderPanel return getValue(PIDSlider); } + /** + * Answers true if the SliderPanel is for Conservation, false if it is for PID + * threshold + * + * @return + */ + public boolean isForConservation() + { + return forConservation; + } + + /** + * Answers the title for the slider panel; this may include 'Background' if + * for the alignment, or the group id if for a group + * + * @return + */ + public String getTitle() + { + String title = null; + if (isForConservation()) + { + if (conservationSlider != null) + { + title = conservationSlider.getTitle(); + } + } + else if (PIDSlider != null) + { + title = PIDSlider.getTitle(); + } + return title; + } }