JAL-1713 JAL-3119 JAL-3785 refactored get/set Overview bounds and title
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 12 Dec 2020 14:39:38 +0000 (14:39 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 12 Dec 2020 14:39:38 +0000 (14:39 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/OverviewPanel.java
src/jalview/io/FileLoader.java
src/jalview/project/Jalview2XML.java
test/jalview/gui/AlignmentPanelTest.java

index eed9846..b2dfbca 100644 (file)
@@ -2854,19 +2854,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
     tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
 
-    /*
-     * finally if new view has acquired an Overview window (because
-     * Preferences option to open Overview is selected), set its title
-     */
-    OverviewPanel ov = newap.overviewPanel;
-    if (ov != null)
-    {
-      String ttl = getOverviewTitle();
-      ((JInternalFrame) SwingUtilities
-              .getAncestorOfClass(JInternalFrame.class, ov))
-                      .setTitle(ttl);
-    }
-
     return newap;
   }
 
@@ -3401,10 +3388,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       return alignPanel.overviewPanel;
     }
     JInternalFrame frame = new JInternalFrame();
-    final OverviewPanel overview = new OverviewPanel(alignPanel, showHidden);
+    final OverviewPanel overview = new OverviewPanel(alignPanel, frame, showHidden);
     frame.setContentPane(overview);
-    String overviewTitle = getOverviewTitle();
-    Desktop.addInternalFrame(frame, overviewTitle, true, frame.getWidth(), frame.getHeight(),
+    Desktop.addInternalFrame(frame, "", true, frame.getWidth(), frame.getHeight(),
             true, true);
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
@@ -3426,29 +3412,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     alignPanel.setOverviewPanel(overview);
+    alignPanel.setOverviewTitle(this);
     
     return overview;
   }
 
-  /**
-   * Constructs a title for the Overview window including the alignment window's
-   * title, and view name (if applicable)
-   * 
-   * @return
-   */
-  public String getOverviewTitle()
-  {
-    String overviewTitle = MessageManager
-            .formatMessage("label.overview_params", new Object[]
-            { this.getTitle() });
-    String viewName = alignPanel.getViewName();
-    if (viewName != null)
-    {
-      overviewTitle += (" " + viewName);
-    }
-    return overviewTitle;
-  }
-
   @Override
   public void textColour_actionPerformed()
   {
@@ -4915,7 +4883,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     if (index > -1)
     {
+      /*
+       * update current Overview window title (if there is one)
+       * to add view name "Original" if necessary
+       */
+      alignPanel.setOverviewTitle(this);
+      
+      /*
+       * switch panels and set Overview title (if there is one
+       * because it was opened automatically)
+       */
       alignPanel = alignPanels.get(index);
+      alignPanel.setOverviewTitle(this);
+
       viewport = alignPanel.av;
       avc.setViewportAndAlignmentPanel(viewport, alignPanel);
       setMenusFromViewport(viewport);
index 45e4b95..9fb1a23 100644 (file)
  */
 package jalview.gui;
 
-import jalview.analysis.AnnotationSorter;
-import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
-import jalview.bin.Cache;
-import jalview.bin.Jalview;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.SearchResultsI;
-import jalview.datamodel.SequenceFeature;
-import jalview.datamodel.SequenceGroup;
-import jalview.datamodel.SequenceI;
-import jalview.gui.ImageExporter.ImageWriterI;
-import jalview.io.HTMLOutput;
-import jalview.jbgui.GAlignmentPanel;
-import jalview.math.AlignmentDimension;
-import jalview.schemes.ResidueProperties;
-import jalview.structure.StructureSelectionManager;
-import jalview.util.Comparison;
-import jalview.util.ImageMaker;
-import jalview.util.MessageManager;
-import jalview.viewmodel.ViewportListenerI;
-import jalview.viewmodel.ViewportRanges;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Container;
@@ -67,6 +44,29 @@ import java.util.List;
 
 import javax.swing.SwingUtilities;
 
+import jalview.analysis.AnnotationSorter;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.gui.ImageExporter.ImageWriterI;
+import jalview.io.HTMLOutput;
+import jalview.jbgui.GAlignmentPanel;
+import jalview.math.AlignmentDimension;
+import jalview.schemes.ResidueProperties;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.Comparison;
+import jalview.util.ImageMaker;
+import jalview.util.MessageManager;
+import jalview.viewmodel.ViewportListenerI;
+import jalview.viewmodel.ViewportRanges;
+
 /**
  * DOCUMENT ME!
  * 
@@ -122,7 +122,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public AlignmentPanel(AlignFrame af, final AlignViewport av)
   {
-//     setBackground(Color.white);  // BH 2019
+    // setBackground(Color.white); // BH 2019
     alignFrame = af;
     this.av = av;
     setSeqPanel(new SeqPanel(av, this));
@@ -471,8 +471,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
         /*
          * Scroll down to make end of search results visible
          */
-        setScrollValues(ranges.getStartRes(), starts + seqIndex - ends
-                + 1);
+        setScrollValues(ranges.getStartRes(), starts + seqIndex - ends + 1);
       }
       /*
        * Else results are already visible - no need to scroll
@@ -572,7 +571,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
     Dimension e = idPanel.getSize();
     alabels.setSize(new Dimension(e.width, annotationHeight));
 
-
     annotationSpaceFillerHolder.setPreferredSize(new Dimension(
             annotationSpaceFillerHolder.getWidth(), annotationHeight));
     annotationScroller.validate();
@@ -1020,8 +1018,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
      * single graphics context), then reset to (0, scale height)
      */
     alignmentGraphics.translate(alignmentGraphicsOffset, scaleHeight);
-    getSeqPanel().seqCanvas.drawPanelForPrinting(alignmentGraphics, startRes,
-            endRes, startSeq, endSeq - 1);
+    getSeqPanel().seqCanvas.drawPanelForPrinting(alignmentGraphics,
+            startRes, endRes, startSeq, endSeq - 1);
     alignmentGraphics.translate(-alignmentGraphicsOffset, 0);
 
     if (av.isShowAnnotation() && (endSeq == alignmentHeight))
@@ -1065,8 +1063,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * 
    * @throws PrinterException
    */
-  public int printWrappedAlignment(int pageWidth, int pageHeight, int pageNumber,
-          Graphics g) throws PrinterException
+  public int printWrappedAlignment(int pageWidth, int pageHeight,
+          int pageNumber, Graphics g) throws PrinterException
   {
     getSeqPanel().seqCanvas.calculateWrappedGeometry(getWidth(),
             getHeight());
@@ -1118,8 +1116,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     g.translate(idWidth, 0);
 
-    getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth,
-            totalHeight, 0);
+    getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g,
+            pageWidth - idWidth, totalHeight, 0);
 
     if ((pageNumber * pageHeight) < totalHeight)
     {
@@ -1284,13 +1282,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
             String triplet = null;
             if (av.getAlignment().isNucleotide())
             {
-              triplet = ResidueProperties.nucleotideName.get(seq
-                      .getCharAt(column) + "");
+              triplet = ResidueProperties.nucleotideName
+                      .get(seq.getCharAt(column) + "");
             }
             else
             {
-              triplet = ResidueProperties.aa2Triplet.get(seq.getCharAt(column)
-                      + "");
+              triplet = ResidueProperties.aa2Triplet
+                      .get(seq.getCharAt(column) + "");
             }
 
             if (triplet == null)
@@ -1307,7 +1305,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
                 text.append("<area shape=\"rect\" coords=\"")
                         .append((idWidth + column * av.getCharWidth()))
                         .append(",").append(sy).append(",")
-                        .append((idWidth + (column + 1) * av.getCharWidth()))
+                        .append((idWidth
+                                + (column + 1) * av.getCharWidth()))
                         .append(",").append((av.getCharHeight() + sy))
                         .append("\"").append(" onMouseOver=\"toolTip('")
                         .append(seqPos).append(" ").append(triplet);
@@ -1333,7 +1332,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
             }
             if (!Comparison.isGap(seq.getCharAt(column)))
             {
-              List<SequenceFeature> features = seq.findFeatures(column, column);
+              List<SequenceFeature> features = seq.findFeatures(column,
+                      column);
               for (SequenceFeature sf : features)
               {
                 if (sf.isContactFeature())
@@ -1737,4 +1737,30 @@ public class AlignmentPanel extends GAlignmentPanel implements
     return calculationDialog;
   }
 
+  /**
+   * Constructs and sets the title for the Overview window (if there is one),
+   * including the align frame's title, and view name (if applicable). Returns
+   * the title, or null if this panel has no Overview window open.
+   * 
+   * @param alignFrame
+   * @return
+   */
+  public String setOverviewTitle(AlignFrame alignFrame)
+  {
+    if (this.overviewPanel == null)
+    {
+      return null;
+    }
+    String overviewTitle = MessageManager
+            .formatMessage("label.overview_params", new Object[]
+            { alignFrame.getTitle() });
+    String viewName = getViewName();
+    if (viewName != null)
+    {
+      overviewTitle += (" " + viewName);
+    }
+    overviewPanel.setTitle(overviewTitle);
+    return overviewTitle;
+  }
+
 }
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();
+  }
 }
index 78ef1ad..480a26e 100755 (executable)
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
-import javax.swing.JInternalFrame;
 import javax.swing.SwingUtilities;
 
 import jalview.api.ComplexAlignFile;
@@ -42,7 +41,6 @@ import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
-import jalview.gui.OverviewPanel;
 import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.project.Jalview2XML;
 import jalview.schemes.ColourSchemeI;
@@ -484,20 +482,12 @@ public class FileLoader implements Runnable
               // that perform queries to find the 'current working alignment'
               Desktop.addInternalFrame(alignFrame, title,
                       AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
-              
-              OverviewPanel ov = alignFrame.alignPanel.getOverviewPanel();
-              if (ov != null)
-              {
-                /*
-                 * Overview automatically opened with alignment
-                 * - set its title now alignFrame title has been set
-                 */
-                String ttl = alignFrame.getOverviewTitle();
-                ((JInternalFrame) SwingUtilities
-                        .getAncestorOfClass(JInternalFrame.class, ov))
-                                .setTitle(ttl);
-              }
 
+              /*
+               * for an Overview automatically opened with alignment,
+               * set its title now alignFrame title has been set
+               */
+              alignFrame.alignPanel.setOverviewTitle(alignFrame);
             }
 
             try
index 2c8793c..2ae81d9 100644 (file)
@@ -1453,10 +1453,8 @@ public class Jalview2XML
       if (ov != null)
       {
         Overview overview = new Overview();
-        JInternalFrame frame = (JInternalFrame) SwingUtilities
-                .getAncestorOfClass(JInternalFrame.class, ov);
-        overview.setTitle(frame.getTitle());
-        Rectangle bounds = frame.getBounds();
+        overview.setTitle(ov.getTitle());
+        Rectangle bounds = ov.getBounds();
         overview.setXpos(bounds.x);
         overview.setYpos(bounds.y);
         overview.setWidth(bounds.width);
@@ -4074,10 +4072,8 @@ public class Jalview2XML
     {
       OverviewPanel overviewPanel = af
               .openOverviewPanel(overview.isShowHidden());
-      JInternalFrame frame = (JInternalFrame) SwingUtilities
-              .getAncestorOfClass(JInternalFrame.class, overviewPanel);
-      frame.setTitle(overview.getTitle());
-      frame.setBounds(overview.getXpos(), overview.getYpos(),
+      overviewPanel.setTitle(overview.getTitle());
+      overviewPanel.setBounds(overview.getXpos(), overview.getYpos(),
               overview.getWidth(), overview.getHeight());
       Color gap = new Color(overview.getGapColour());
       Color residue = new Color(overview.getResidueColour());
index 8871249..a6bce20 100644 (file)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
 
 import java.awt.Dimension;
 import java.awt.Font;
@@ -283,4 +284,43 @@ public class AlignmentPanelTest
     Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
     assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
   }
-}
+  @Test(groups = "Functional")
+  public void testSetOverviewTitle()
+  {
+    OverviewPanel ov1 = this.af.openOverviewPanel(true);
+    String alignFrameTitle = af.getTitle();
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
+    
+    /*
+     * on New View, existing overview should get " Original" added to title
+     * and new view's overview should get " View 1" added
+     */
+    af.newView_actionPerformed(null);
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
+    OverviewPanel ov2 = this.af.openOverviewPanel(true);
+    assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
+  }
+  
+  @Test(groups = "Functional")
+  public void testSetOverviewTitle_automaticOverview()
+  {
+    Cache.setProperty("SHOW_OVERVIEW",  "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
+    assertNotNull(ov1);
+    String alignFrameTitle = alignFrame.getTitle();
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
+    
+    /*
+     * on New View, existing overview should get " Original" added to title
+     * and new view's automatic overview should have " View 1" added
+     */
+    alignFrame.newView_actionPerformed(null);
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
+    OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
+    assertNotNull(ov2);
+    assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
+  }
+}
\ No newline at end of file