X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSliderPanel.java;h=b386decc407928215ce507387cf3e4c7dfc556d0;hb=fd7eebe6dcf2346692d718ef91bb468cc12ebf44;hp=7d733c9624deeb331aaaf1449eea486e42df4548;hpb=5abd8cc59e692171861a337e189faaa26dcfff16;p=jalview.git diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 7d733c9..b386dec 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -22,13 +22,12 @@ package jalview.gui; import jalview.datamodel.SequenceGroup; import jalview.jbgui.GSliderPanel; -import jalview.schemes.ColourSchemeI; +import jalview.schemes.CollectionColourSchemeI; import jalview.util.MessageManager; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyVetoException; -import java.util.Iterator; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; @@ -53,7 +52,7 @@ public class SliderPanel extends GSliderPanel boolean forConservation = true; - ColourSchemeI cs; + CollectionColourSchemeI cs; /** * Creates a new SliderPanel object. @@ -64,14 +63,14 @@ public class SliderPanel extends GSliderPanel * DOCUMENT ME! * @param forConserve * DOCUMENT ME! - * @param cs + * @param scheme * DOCUMENT ME! */ public SliderPanel(final AlignmentPanel ap, int value, - boolean forConserve, ColourSchemeI cs) + boolean forConserve, CollectionColourSchemeI scheme) { this.ap = ap; - this.cs = cs; + this.cs = scheme; forConservation = forConserve; undoButton.setVisible(false); applyButton.setVisible(false); @@ -127,7 +126,7 @@ public class SliderPanel extends GSliderPanel * @return DOCUMENT ME! */ public static int setConservationSlider(AlignmentPanel ap, - ColourSchemeI cs, String source) + CollectionColourSchemeI cs, String source) { SliderPanel sp = null; @@ -225,23 +224,24 @@ public class SliderPanel extends GSliderPanel * * @param ap * DOCUMENT ME! - * @param cs + * @param collectionColourScheme * DOCUMENT ME! * @param source * DOCUMENT ME! * * @return DOCUMENT ME! */ - public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs, + public static int setPIDSliderSource(AlignmentPanel ap, + CollectionColourSchemeI collectionColourScheme, String source) { SliderPanel pid = null; - int threshold = cs.getThreshold(); + int threshold = collectionColourScheme.getThreshold(); if (PIDSlider == null) { - pid = new SliderPanel(ap, threshold, false, cs); + pid = new SliderPanel(ap, threshold, false, collectionColourScheme); PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(pid); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -249,8 +249,8 @@ public class SliderPanel extends GSliderPanel else { pid = (SliderPanel) PIDSlider.getContentPane(); - pid.slider.setValue(cs.getThreshold()); - pid.cs = cs; + pid.cs = collectionColourScheme; + pid.slider.setValue(collectionColourScheme.getThreshold()); } PIDSlider @@ -295,47 +295,25 @@ public class SliderPanel extends GSliderPanel } /** - * DOCUMENT ME! + * Updates the colour scheme with the current (identity threshold or + * conservation) percentage value. Also updates all groups if 'apply to all + * groups' is selected. * - * @param i - * DOCUMENT ME! + * @param percent */ - public void valueChanged(int i) + public void valueChanged(int percent) { - if (cs == null) + if (!forConservation) { - return; + ap.av.setThreshold(percent); } - - ColourSchemeI toChange = cs; - Iterator allGroups = null; + updateColourScheme(percent, cs); if (allGroupsCheck.isSelected()) { - allGroups = ap.av.getAlignment().getGroups().listIterator(); - } - - while (toChange != null) - { - if (forConservation) - { - toChange.setConservationInc(i); - } - else + for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { - toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus()); - } - if (allGroups != null && allGroups.hasNext()) - { - while ((toChange = allGroups.next().cs) == null - && allGroups.hasNext()) - { - ; - } - } - else - { - toChange = null; + updateColourScheme(percent, sg.getGroupColourScheme()); } } @@ -343,6 +321,29 @@ public class SliderPanel extends GSliderPanel } /** + * Updates the colour scheme (if not null) with the current (identity + * threshold or conservation) percentage value + * + * @param percent + * @param scheme + */ + protected void updateColourScheme(int percent, CollectionColourSchemeI scheme) + { + if (scheme == null) + { + return; + } + if (forConservation) + { + scheme.setConservationInc(percent); + } + else + { + scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus()); + } + } + + /** * DOCUMENT ME! * * @param b @@ -356,6 +357,25 @@ public class SliderPanel extends GSliderPanel /** * DOCUMENT ME! * + * @param e + * DOCUMENT ME! + */ + @Override + public void valueField_actionPerformed() + { + try + { + int i = Integer.parseInt(valueField.getText()); + slider.setValue(i); + } catch (NumberFormatException ex) + { + valueField.setText(slider.getValue() + ""); + } + } + + /** + * DOCUMENT ME! + * * @param value * DOCUMENT ME! */ @@ -383,4 +403,20 @@ 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); + } + }