JAL-3253 extract methods for getConservation/PIDSlider
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 4 Oct 2019 09:52:42 +0000 (10:52 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 4 Oct 2019 09:52:42 +0000 (10:52 +0100)
src/jalview/gui/SliderPanel.java

index 31ad083..940bab2 100755 (executable)
@@ -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();
+  }
 }