JAL-1713 JAL-3119 JAL-3785 refactored get/set Overview bounds and title
[jalview.git] / src / jalview / gui / OverviewPanel.java
index 6cb4b96..9cfda3a 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.gui;
 import java.awt.BorderLayout;
 import java.awt.Cursor;
 import java.awt.Dimension;
+import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
@@ -66,6 +67,8 @@ public class OverviewPanel extends JPanel
 
   private AlignmentPanel ap;
 
+  private JInternalFrame internalFrame;
+
   protected JCheckBoxMenuItem displayToggle;
 
   protected boolean showHidden = true;
@@ -79,19 +82,23 @@ public class OverviewPanel extends JPanel
    * 
    * @param alPanel
    *          The alignment panel which is shown in the overview panel
-   * @param isShowHidden TODO
+   * @param frame
+   * @param isShowHidden
+   *          TODO
    */
-  public OverviewPanel(AlignmentPanel alPanel, boolean isShowHidden)
+  public OverviewPanel(AlignmentPanel alPanel, JInternalFrame frame,
+          boolean isShowHidden)
   {
     this.av = alPanel.av;
     this.ap = alPanel;
+    this.internalFrame = frame;
 
     showHidden = isShowHidden;
     if (showHidden)
     {
       od = new OverviewDimensionsShowHidden(av.getRanges(),
-            (av.isShowAnnotation()
-                    && av.getAlignmentConservationAnnotation() != null));
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
     }
     else
     {
@@ -112,7 +119,7 @@ public class OverviewPanel extends JPanel
 
     // without this the overview window does not size to fit the overview canvas
     setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
-    
+
     addComponentListener(new ComponentAdapter()
     {
       @Override
@@ -194,37 +201,39 @@ public class OverviewPanel extends JPanel
       @Override
       public void mousePressed(MouseEvent evt)
       {
-         
-       if (Platform.isWinRightButton(evt)) {
-               showPopupMenu(evt);
-               return;
-       }
-        if (SwingUtilities.isRightMouseButton(evt)) {
-               return;
+
+        if (Platform.isWinRightButton(evt))
+        {
+          showPopupMenu(evt);
+          return;
         }
-          // don't do anything if the mouse press is in the overview's box
-          // (wait to see if it's a drag instead)
-          // otherwise update the viewport
-          if (!od.isPositionInBox(evt.getX(), evt.getY()))
-          {
-            draggingBox = false;
+        if (SwingUtilities.isRightMouseButton(evt))
+        {
+          return;
+        }
+        // don't do anything if the mouse press is in the overview's box
+        // (wait to see if it's a drag instead)
+        // otherwise update the viewport
+        if (!od.isPositionInBox(evt.getX(), evt.getY()))
+        {
+          draggingBox = false;
 
-            // display drag cursor at mouse position
-            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+          // display drag cursor at mouse position
+          setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
 
-            od.updateViewportFromMouse(evt.getX(), evt.getY(),
-                    av.getAlignment().getHiddenSequences(),
-                    av.getAlignment().getHiddenColumns());
-            getParent().setCursor(
-                    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
-          }
-          else
-          {
-            draggingBox = true;
-            od.setDragPoint(evt.getX(), evt.getY(),
-                    av.getAlignment().getHiddenSequences(),
-                    av.getAlignment().getHiddenColumns());
-          }
+          od.updateViewportFromMouse(evt.getX(), evt.getY(),
+                  av.getAlignment().getHiddenSequences(),
+                  av.getAlignment().getHiddenColumns());
+          getParent().setCursor(
+                  Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+        }
+        else
+        {
+          draggingBox = true;
+          od.setDragPoint(evt.getX(), evt.getY(),
+                  av.getAlignment().getHiddenSequences(),
+                  av.getAlignment().getHiddenColumns());
+        }
       }
 
       @Override
@@ -321,7 +330,7 @@ public class OverviewPanel extends JPanel
       od.setWidth(getWidth());
       od.setHeight(getHeight() - progressPanel.getHeight());
     }
-    
+
     setPreferredSize(new Dimension(od.getWidth(),
             od.getHeight() + progressPanel.getHeight()));
 
@@ -334,7 +343,6 @@ public class OverviewPanel extends JPanel
     thread.start();
     repaint();
 
-    
   }
 
   @Override
@@ -405,8 +413,7 @@ public class OverviewPanel extends JPanel
        * close the parent frame (which also removes it from the
        * Desktop Windows menu)
        */
-      ((JInternalFrame) SwingUtilities.getAncestorOfClass(
-              JInternalFrame.class, (this))).setClosed(true);
+      internalFrame.setClosed(true);
     } catch (PropertyVetoException e)
     {
       // ignore
@@ -417,9 +424,10 @@ public class OverviewPanel extends JPanel
       oviewCanvas = null;
       ap = null;
       od = null;
+      internalFrame = null;
     }
   }
-  
+
   public boolean isShowHiddenRegions()
   {
     return showHidden;
@@ -429,4 +437,49 @@ public class OverviewPanel extends JPanel
   {
     return oviewCanvas;
   }
+
+  /**
+   * Sets the title of the enclosing frame
+   * 
+   * @param title
+   */
+  public void setTitle(String title)
+  {
+    internalFrame.setTitle(title);
+  }
+
+  /**
+   * Returns the title of the enclosing frame
+   * 
+   * @return title
+   */
+  public String getTitle()
+  {
+    return internalFrame.getTitle();
+  }
+
+  /**
+   * Overridden to set the bounds of the frame holding the Overview panel
+   * 
+   * @param xpos
+   * @param ypos
+   * @param width
+   * @param height
+   */
+  @Override
+  public void setBounds(int xpos, int ypos, int width, int height)
+  {
+    internalFrame.setBounds(xpos, ypos, width, height);
+  }
+
+  /**
+   * Overridden to return the bounds of the enclosing frame
+   * 
+   * @return
+   */
+  @Override
+  public Rectangle getBounds()
+  {
+    return internalFrame.getBounds();
+  }
 }