From: gmungoc Date: Fri, 4 Oct 2019 09:52:42 +0000 (+0100) Subject: JAL-3253 extract methods for getConservation/PIDSlider X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=60541afc96ff3a4f5b79b78009922f373cbc29c3;p=jalview.git JAL-3253 extract methods for getConservation/PIDSlider --- diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 31ad083..940bab2 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -63,10 +63,9 @@ public class SliderPanel extends GSliderPanel public static SliderPanel getSliderPanel() { - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = getConservationSlider(); - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = getPIDSlider(); if (conservationSlider != null && conservationSlider.isVisible()) { @@ -155,8 +154,7 @@ public class SliderPanel extends GSliderPanel { SliderPanel sliderPanel = null; - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = getConservationSlider(); if (conservationSlider == null) { @@ -198,7 +196,7 @@ public class SliderPanel extends GSliderPanel */ public static void hidePIDSlider() { - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = getPIDSlider(); if (PIDSlider != null) { @@ -217,8 +215,7 @@ public class SliderPanel extends GSliderPanel */ public static void hideConservationSlider() { - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = getConservationSlider(); if (conservationSlider != null) { @@ -239,8 +236,7 @@ public class SliderPanel extends GSliderPanel { hidePIDSlider(); - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = getConservationSlider(); if (!conservationSlider.isVisible()) { @@ -278,7 +274,7 @@ public class SliderPanel extends GSliderPanel SliderPanel sliderPanel = null; - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = getPIDSlider(); if (PIDSlider == null) { @@ -321,7 +317,7 @@ public class SliderPanel extends GSliderPanel { hideConservationSlider(); - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = getPIDSlider(); if (!PIDSlider.isVisible()) { @@ -467,22 +463,6 @@ public class SliderPanel extends GSliderPanel } } - public static int getConservationValue() - { - return getValue(Desktop.getInstance().conservationSlider); - } - - static int getValue(JInternalFrame slider) - { - return slider == null ? 0 - : ((SliderPanel) slider.getContentPane()).getValue(); - } - - public static int getPIDValue() - { - return getValue(Desktop.getInstance().PIDSlider); - } - /** * Answers true if the SliderPanel is for Conservation, false if it is for PID * threshold @@ -503,9 +483,8 @@ public class SliderPanel extends GSliderPanel public String getTitle() { String title = null; - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame conservationSlider = getConservationSlider(); + JInternalFrame PIDSlider = getPIDSlider(); if (isForConservation()) { @@ -520,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(); + } }