JAL-3451 JalviewJS embedded mode not resizing
[jalview.git] / src / jalview / gui / SliderPanel.java
index 0a80292..940bab2 100755 (executable)
@@ -21,7 +21,6 @@
 package jalview.gui;
 
 import jalview.analysis.Conservation;
-import jalview.bin.Instance;
 import jalview.datamodel.SequenceGroup;
 import jalview.jbgui.GSliderPanel;
 import jalview.renderer.ResidueShaderI;
@@ -64,10 +63,9 @@ public class SliderPanel extends GSliderPanel
   public static SliderPanel getSliderPanel()
   {
 
-    JInternalFrame conservationSlider = Instance
-            .getDesktop().conservationSlider;
+    JInternalFrame conservationSlider = getConservationSlider();
 
-    JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider;
+    JInternalFrame PIDSlider = getPIDSlider();
 
     if (conservationSlider != null && conservationSlider.isVisible())
     {
@@ -156,14 +154,13 @@ public class SliderPanel extends GSliderPanel
   {
     SliderPanel sliderPanel = null;
 
-    JInternalFrame conservationSlider = Instance
-            .getDesktop().conservationSlider;
+    JInternalFrame conservationSlider = getConservationSlider();
 
     if (conservationSlider == null)
     {
       sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
-      conservationSlider = Instance
-              .getDesktop().conservationSlider = new JInternalFrame();
+      conservationSlider = Desktop
+              .getInstance().conservationSlider = new JInternalFrame();
       conservationSlider.setContentPane(sliderPanel);
       conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
     }
@@ -199,14 +196,14 @@ public class SliderPanel extends GSliderPanel
    */
   public static void hidePIDSlider()
   {
-    JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider;
+    JInternalFrame PIDSlider = getPIDSlider();
 
     if (PIDSlider != null)
     {
       try
       {
         PIDSlider.setClosed(true);
-        Instance.getDesktop().PIDSlider = null;
+        Desktop.getInstance().PIDSlider = null;
       } catch (PropertyVetoException ex)
       {
       }
@@ -218,15 +215,14 @@ public class SliderPanel extends GSliderPanel
    */
   public static void hideConservationSlider()
   {
-    JInternalFrame conservationSlider = Instance
-            .getDesktop().conservationSlider;
+    JInternalFrame conservationSlider = getConservationSlider();
 
     if (conservationSlider != null)
     {
       try
       {
         conservationSlider.setClosed(true);
-        Instance.getDesktop().conservationSlider = null;
+        Desktop.getInstance().conservationSlider = null;
       } catch (PropertyVetoException ex)
       {
       }
@@ -240,8 +236,7 @@ public class SliderPanel extends GSliderPanel
   {
     hidePIDSlider();
 
-    JInternalFrame conservationSlider = Instance
-            .getDesktop().conservationSlider;
+    JInternalFrame conservationSlider = getConservationSlider();
 
     if (!conservationSlider.isVisible())
     {
@@ -253,7 +248,7 @@ public class SliderPanel extends GSliderPanel
         @Override
         public void internalFrameClosed(InternalFrameEvent e)
         {
-          Instance.getDesktop().conservationSlider = null;
+          Desktop.getInstance().conservationSlider = null;
         }
       });
       conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
@@ -279,12 +274,12 @@ public class SliderPanel extends GSliderPanel
 
     SliderPanel sliderPanel = null;
 
-    JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider;
+    JInternalFrame PIDSlider = getPIDSlider();
 
     if (PIDSlider == null)
     {
       sliderPanel = new SliderPanel(ap, threshold, false, rs);
-      PIDSlider = Instance.getDesktop().PIDSlider = new JInternalFrame();
+      PIDSlider = Desktop.getInstance().PIDSlider = new JInternalFrame();
       PIDSlider.setContentPane(sliderPanel);
       PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
     }
@@ -322,7 +317,7 @@ public class SliderPanel extends GSliderPanel
   {
     hideConservationSlider();
 
-    JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider;
+    JInternalFrame PIDSlider = getPIDSlider();
 
     if (!PIDSlider.isVisible())
     {
@@ -334,7 +329,7 @@ public class SliderPanel extends GSliderPanel
         @Override
         public void internalFrameClosed(InternalFrameEvent e)
         {
-          Instance.getDesktop().PIDSlider = null;
+          Desktop.getInstance().PIDSlider = null;
         }
       });
       PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
@@ -468,22 +463,6 @@ public class SliderPanel extends GSliderPanel
     }
   }
 
-  public static int getConservationValue()
-  {
-    return getValue(Instance.getDesktop().conservationSlider);
-  }
-
-  static int getValue(JInternalFrame slider)
-  {
-    return slider == null ? 0
-            : ((SliderPanel) slider.getContentPane()).getValue();
-  }
-
-  public static int getPIDValue()
-  {
-    return getValue(Instance.getDesktop().PIDSlider);
-  }
-
   /**
    * Answers true if the SliderPanel is for Conservation, false if it is for PID
    * threshold
@@ -504,9 +483,8 @@ public class SliderPanel extends GSliderPanel
   public String getTitle()
   {
     String title = null;
-    JInternalFrame conservationSlider = Instance
-            .getDesktop().conservationSlider;
-    JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider;
+    JInternalFrame conservationSlider = getConservationSlider();
+    JInternalFrame PIDSlider = getPIDSlider();
 
     if (isForConservation())
     {
@@ -521,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();
+  }
 }