JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / gui / OverviewPanel.java
index 5694c3d..a5aaf7c 100755 (executable)
@@ -20,8 +20,6 @@
  */
 package jalview.gui;
 
-import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
 import jalview.renderer.OverviewRenderer;
 import jalview.util.MessageManager;
@@ -63,11 +61,11 @@ public class OverviewPanel extends JPanel
 {
   protected OverviewDimensions od;
 
-  OverviewCanvas canvas;
+  private OverviewCanvas oviewCanvas;
 
-  protected AlignViewportI av;
+  protected AlignViewport av;
 
-  AlignmentViewPanel ap;
+  private AlignmentPanel ap;
 
   protected JCheckBoxMenuItem displayToggle;
 
@@ -77,50 +75,71 @@ public class OverviewPanel extends JPanel
 
   protected ProgressPanel progressPanel;
 
-  private Dimension dim;
-
-  private boolean showProgress = !Platform.isJS(); // Jalview.getInstance().getShowStatus()
-
   /**
    * Creates a new OverviewPanel object.
    * 
    * @param alPanel
    *          The alignment panel which is shown in the overview panel
    */
-  public OverviewPanel(AlignmentViewPanel alPanel, Dimension dim)
+  public OverviewPanel(AlignmentPanel alPanel)
   {
-    this.av = alPanel.getAlignViewport();
+    this.av = alPanel.av;
     this.ap = alPanel;
-    this.dim = dim;
 
     showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
             false);
-    createOverviewDimensions();
+    if (showHidden)
+    {
+      od = new OverviewDimensionsShowHidden(av.getRanges(),
+            (av.isShowAnnotation()
+                    && av.getAlignmentConservationAnnotation() != null));
+    }
+    else
+    {
+      od = new OverviewDimensionsHideHidden(av.getRanges(),
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
+    }
+
     setLayout(new BorderLayout());
     progressPanel = new ProgressPanel(OverviewRenderer.UPDATE,
             MessageManager.getString("label.oview_calc"), getWidth());
-    if (showProgress) // BH 2019
-    {
-      add(progressPanel, BorderLayout.SOUTH);
-    }
-    canvas = new OverviewCanvas(this, od, av,
-            showProgress ? progressPanel : null);
-    canvas.setPreferredSize(canvas.getSize());
-    add(canvas, BorderLayout.CENTER);
+    this.add(progressPanel, BorderLayout.SOUTH);
+    oviewCanvas = new OverviewCanvas(od, av, progressPanel);
+
+    add(oviewCanvas, BorderLayout.CENTER);
 
     av.getRanges().addPropertyChangeListener(this);
 
     // without this the overview window does not size to fit the overview canvas
-    // BH - no,no! - This does not include the progressPanel!
-    // BH the problem was that OverviewCanvas.setPreferredSize() had not been set.
-    // setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
-
+    setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
+    
     addComponentListener(new ComponentAdapter()
     {
       @Override
       public void componentResized(ComponentEvent evt)
       {
-        resizePanel();
+        // Resize is called on the initial display of the overview.
+        // This code adjusts sizes to account for the progress bar if it has not
+        // already been accounted for, which triggers another resize call for
+        // the correct sizing, at which point the overview image is updated.
+        // (This avoids a double recalculation of the image.)
+        if (getWidth() == od.getWidth() && getHeight() == od.getHeight()
+                + progressPanel.getHeight())
+        {
+          updateOverviewImage();
+        }
+        else
+        {
+          if ((getWidth() > 0) && (getHeight() > 0))
+          {
+            od.setWidth(getWidth());
+            od.setHeight(getHeight() - progressPanel.getHeight());
+          }
+
+          setPreferredSize(new Dimension(od.getWidth(),
+                  od.getHeight() + progressPanel.getHeight()));
+        }
       }
 
     });
@@ -176,39 +195,37 @@ 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;
+       }
+        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;
+          // 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
@@ -228,71 +245,14 @@ public class OverviewPanel extends JPanel
 
     });
 
-    // /*
-    // * Javascript does not call componentResized on initial display,
-    // * so do the update here
-    // */
-    // if (Platform.isJS())
-    // {
-    // updateOverviewImage();
-    // }
-  }
-
-  protected void resizePanel()
-  {
-    int ph = (progressPanel.getParent() == null ? 0
-            : progressPanel.getHeight());
-    // Resize is called on the initial display of the overview.
-    // This code adjusts sizes to account for the progress bar if it has not
-    // already been accounted for, which triggers another resize call for
-    // the correct sizing, at which point the overview image is updated.
-    // (This avoids a double recalculation of the image.)
-    if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + ph)
-    {
-      if (canvas.lastMiniMe == null)
-      {
-        updateOverviewImage();
-      }
-    }
-    else
-    {
-      int w = getWidth();
-      int h = getHeight();
-      if ((w > 0) && (h > 0))
-      {
-        if (dim != null)
-        {
-          dim.setSize(w, h - ph);
-        }
-        od.setWidth(w);
-        od.setHeight(h - ph);
-        updateOverviewImage();
-      }
-      // BH 2019.07.29 this is unnecessary -- it is what layout managers are
-      // for:
-      // setPreferredSize(new Dimension(od.getWidth(), od.getHeight() +
-      // ph));
-    }
-  }
-
-  /**
-   * Create the appropriate type of OverViewDimensions, with the desired size.
-   */
-  private void createOverviewDimensions()
-  {
-    boolean showAnnotation = (av.isShowAnnotation()
-            && av.getAlignmentConservationAnnotation() != null);
-    if (showHidden)
-    {
-      od = new OverviewDimensionsShowHidden(av.getRanges(), showAnnotation,
-              dim);
-    }
-    else
+    /*
+     * Javascript does not call componentResized on initial display,
+     * so do the update here
+     */
+    if (Platform.isJS())
     {
-      od = new OverviewDimensionsHideHidden(av.getRanges(), showAnnotation,
-              dim);
+      updateOverviewImage();
     }
-
   }
 
   /*
@@ -325,32 +285,31 @@ public class OverviewPanel extends JPanel
    */
   protected void toggleHiddenColumns()
   {
-    showHidden = !showHidden;
-    createOverviewDimensions();
-    canvas.resetOviewDims(od);
+    if (showHidden)
+    {
+      showHidden = false;
+      od = new OverviewDimensionsHideHidden(av.getRanges(),
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
+    }
+    else
+    {
+      showHidden = true;
+      od = new OverviewDimensionsShowHidden(av.getRanges(),
+              (av.isShowAnnotation()
+                      && av.getAlignmentConservationAnnotation() != null));
+    }
+    oviewCanvas.resetOviewDims(od);
     updateOverviewImage();
     setBoxPosition();
   }
 
   /**
-   * Updates the overview image when the related alignment panel is updated.
-   * 
-   * Cases:
-   * 
-   * AlignFrame.setFeatureGroupState
-   * 
-   * AlignmentPanel.paintAlignment(true,...) (117 references)
-   * 
-   * OverviewPanel..componentResized() OverviewPanel.toggleHiddenColumns()
-   * 
-   * PopupMenu for action.reveal_sequences, action.reveal_all
-   * 
-   * SliderPanel.mouseReleased()
-   * 
+   * Updates the overview image when the related alignment panel is updated
    */
   public void updateOverviewImage()
   {
-    if (canvas == null)
+    if (oviewCanvas == null)
     {
       /*
        * panel has been disposed
@@ -358,36 +317,37 @@ public class OverviewPanel extends JPanel
       return;
     }
 
-    int ph = (progressPanel.getParent() == null ? 0
-            : progressPanel.getHeight());
-
     if ((getWidth() > 0) && (getHeight() > 0))
     {
       od.setWidth(getWidth());
-      od.setHeight(getHeight() - ph);
+      od.setHeight(getHeight() - progressPanel.getHeight());
     }
+    
+    setPreferredSize(new Dimension(od.getWidth(),
+            od.getHeight() + progressPanel.getHeight()));
 
-    setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + ph));
-
-    if (canvas.restartDraw())
+    if (oviewCanvas.restartDraw())
     {
       return;
     }
 
     Thread thread = new Thread(this);
     thread.start();
+    repaint();
+
+    
   }
 
   @Override
   public void run()
   {
-    if (canvas != null)
+    if (oviewCanvas != null)
     {
-      setBoxPosition();
-      canvas.draw(av.isShowSequenceFeatures(),
+      oviewCanvas.draw(av.isShowSequenceFeatures(),
               (av.isShowAnnotation()
                       && av.getAlignmentConservationAnnotation() != null),
-              ap.getFeatureRenderer());
+              ap.getSeqPanel().seqCanvas.getFeatureRenderer());
+      setBoxPosition();
     }
   }
 
@@ -400,7 +360,6 @@ public class OverviewPanel extends JPanel
   {
     if (od != null)
     {
-      od.updateBox();
       int oldX = od.getBoxX();
       int oldY = od.getBoxY();
       int oldWidth = od.getBoxWidth();
@@ -441,15 +400,14 @@ public class OverviewPanel extends JPanel
         av.getRanges().removePropertyChangeListener(this);
       }
 
-      canvas.dispose();
+      oviewCanvas.dispose();
 
       /*
        * close the parent frame (which also removes it from the
        * Desktop Windows menu)
        */
-      ((JInternalFrame) SwingUtilities
-              .getAncestorOfClass(JInternalFrame.class, (this)))
-                      .setClosed(true);
+      ((JInternalFrame) SwingUtilities.getAncestorOfClass(
+              JInternalFrame.class, (this))).setClosed(true);
     } catch (PropertyVetoException e)
     {
       // ignore
@@ -457,7 +415,7 @@ public class OverviewPanel extends JPanel
     {
       progressPanel = null;
       av = null;
-      canvas = null;
+      oviewCanvas = null;
       ap = null;
       od = null;
     }