Merge develop to Release_2_8_3_Branch
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index d8b0757..beafa8c 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.analysis.AnnotationSorter;
+import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
@@ -94,9 +95,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * Creates a new AlignmentPanel object.
    * 
    * @param af
-   *          DOCUMENT ME!
    * @param av
-   *          DOCUMENT ME!
    */
   public AlignmentPanel(AlignFrame af, final AlignViewport av)
   {
@@ -122,8 +121,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     setScrollValues(0, 0);
 
-    setAnnotationVisible(av.isShowAnnotation());
-
     hscroll.addAdjustmentListener(this);
     vscroll.addAdjustmentListener(this);
 
@@ -141,9 +138,14 @@ public class AlignmentPanel extends GAlignmentPanel implements
     });
     fontChanged();
     adjustAnnotationHeight();
-
+    updateLayout();
   }
 
+  @Override
+  public AlignViewportI getAlignViewport()
+  {
+    return av;
+  }
   public void alignmentChanged()
   {
     av.alignmentChanged(this);
@@ -163,9 +165,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // to prevent drawing old image
     FontMetrics fm = getFontMetrics(av.getFont());
 
-    scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
+    scalePanelHolder.setPreferredSize(new Dimension(10, av.getCharHeight()
             + fm.getDescent()));
-    idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
+    idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av
+            .getCharHeight()
             + fm.getDescent()));
 
     getIdPanel().getIdCanvas().gg = null;
@@ -173,6 +176,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     getAnnotationPanel().adjustPanelHeight();
 
     Dimension d = calculateIdWidth();
+
     d.setSize(d.width + 4, d.height);
     getIdPanel().getIdCanvas().setPreferredSize(d);
     hscrollFillerPanel.setPreferredSize(d);
@@ -181,6 +185,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
       overviewPanel.setBoxPosition();
     }
+    if (this.alignFrame.getSplitViewContainer() != null)
+    {
+      ((SplitFrame) this.alignFrame.getSplitViewContainer()).adjustLayout();
+    }
 
     repaint();
   }
@@ -195,11 +203,21 @@ public class AlignmentPanel extends GAlignmentPanel implements
   public Dimension calculateIdWidth()
   {
     // calculate sensible default width when no preference is available
-
-    int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
-    int maxwidth = Math.max(20,
-            Math.min(afwidth - 200, 2 * afwidth / 3));
-    return calculateIdWidth(maxwidth);
+    Dimension r = null;
+    if (av.getIdWidth() < 0)
+    {
+      int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
+      int maxwidth = Math.max(20, Math.min(afwidth - 200, 2 * afwidth / 3));
+      r = calculateIdWidth(maxwidth);
+      av.setIdWidth(r.width);
+    }
+    else
+    {
+      r = new Dimension();
+      r.width = av.getIdWidth();
+      r.height = 0;
+    }
+    return r;
   }
 
   /**
@@ -339,7 +357,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
           }
         }
       }
-      if (!av.wrapAlignment)
+      if (!av.getWrapAlignment())
       {
         if ((startv = av.getStartRes()) >= start)
         {
@@ -412,7 +430,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void setAnnotationVisible(boolean b)
   {
-    if (!av.wrapAlignment)
+    if (!av.getWrapAlignment())
     {
       annotationSpaceFillerHolder.setVisible(b);
       annotationScroller.setVisible(b);
@@ -488,13 +506,16 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   /**
-   * DOCUMENT ME!
+   * update alignment layout for viewport settings
    * 
    * @param wrap
    *          DOCUMENT ME!
    */
-  public void setWrapAlignment(boolean wrap)
+  public void updateLayout()
   {
+    fontChanged();
+    setAnnotationVisible(av.isShowAnnotation());
+    boolean wrap = av.getWrapAlignment();
     av.startSeq = 0;
     scalePanelHolder.setVisible(!wrap);
     hscroll.setVisible(!wrap);
@@ -605,10 +626,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
       width = av.getColumnSelection().findColumnPosition(width);
     }
 
-    av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av.charWidth)) - 1);
+    av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av
+            .getCharWidth())) - 1);
 
-    hextent = getSeqPanel().seqCanvas.getWidth() / av.charWidth;
-    vextent = getSeqPanel().seqCanvas.getHeight() / av.charHeight;
+    hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
+    vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
 
     if (hextent > width)
     {
@@ -652,7 +674,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
-
     int oldX = av.getStartRes();
     int oldY = av.getStartSeq();
 
@@ -859,7 +880,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
   {
     int idWidth = getVisibleIdWidth(false);
     FontMetrics fm = getFontMetrics(av.getFont());
-    int scaleHeight = av.charHeight + fm.getDescent();
+    int scaleHeight = av.getCharHeight() + fm.getDescent();
 
     pg.setColor(Color.white);
     pg.fillRect(0, 0, pwidth, pheight);
@@ -949,7 +970,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       }
 
       pg.setColor(currentColor);
-      pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
+      pg.fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth,
               av.getCharHeight());
 
       pg.setColor(currentTextColor);
@@ -966,7 +987,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       pg.drawString(
               seq.getDisplayId(av.getShowJVSuffix()),
               xPos,
-              (((i - startSeq) * av.charHeight) + av.getCharHeight())
+              (((i - startSeq) * av.getCharHeight()) + av.getCharHeight())
                       - (av.getCharHeight() / 5));
     }
 
@@ -981,7 +1002,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
       // draw annotation - need to offset for current scroll position
       int offset = -getAlabels().getScrollOffset();
       pg.translate(0, offset);
-      pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
+      pg.translate(-idWidth - 3, (endSeq - startSeq) * av.getCharHeight()
+              + 3);
       getAlabels().drawComponent(pg, idWidth);
       pg.translate(idWidth + 3, 0);
       getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av,
@@ -1012,7 +1034,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
   public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
           int pi) throws PrinterException
   {
-
     int annotationHeight = 0;
     AnnotationLabels labels = null;
     if (av.isShowAnnotation())
@@ -1021,13 +1042,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
       labels = new AnnotationLabels(av);
     }
 
-    int hgap = av.charHeight;
-    if (av.scaleAboveWrapped)
+    int hgap = av.getCharHeight();
+    if (av.getScaleAboveWrapped())
     {
-      hgap += av.charHeight;
+      hgap += av.getCharHeight();
     }
 
-    int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
+    int cHeight = av.getAlignment().getHeight() * av.getCharHeight() + hgap
             + annotationHeight;
 
     int idWidth = getVisibleIdWidth(false);
@@ -1071,18 +1092,19 @@ public class AlignmentPanel extends GAlignmentPanel implements
           xPos = idWidth - fm.stringWidth(string) - 4;
         }
         pg.drawString(string, xPos,
-                ((i * av.charHeight) + ypos + av.charHeight)
-                        - (av.charHeight / 5));
+                ((i * av.getCharHeight()) + ypos + av.getCharHeight())
+                        - (av.getCharHeight() / 5));
       }
       if (labels != null)
       {
         pg.translate(-3, ypos
-                + (av.getAlignment().getHeight() * av.charHeight));
+ + (av.getAlignment().getHeight() * av.getCharHeight()));
 
         pg.setFont(av.getFont());
         labels.drawComponent(pg, idWidth);
         pg.translate(+3, -ypos
-                - (av.getAlignment().getHeight() * av.charHeight));
+                        - (av.getAlignment().getHeight() * av
+                                .getCharHeight()));
       }
 
       ypos += cHeight;
@@ -1149,8 +1171,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     if (alignFrame != null && !headless)
     {
       alignFrame.setProgressBar(MessageManager.formatMessage(
-              "status.saving_file",
-              new String[]
+              "status.saving_file", new Object[]
               { type.getLabel() }), progress);
     }
     try
@@ -1225,9 +1246,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
       maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
     }
 
-    int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
+    int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight())
             + getScalePanel().getHeight();
-    int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
+    int width = getVisibleIdWidth(false) + (maxwidth * av.getCharWidth());
 
     if (av.getWrapAlignment())
     {
@@ -1283,7 +1304,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // ////////////////////////////////////////////
     int idWidth = getVisibleIdWidth(false);
     FontMetrics fm = getFontMetrics(av.getFont());
-    int scaleHeight = av.charHeight + fm.getDescent();
+    int scaleHeight = av.getCharHeight() + fm.getDescent();
 
     // Gen image map
     // ////////////////////////////////
@@ -1302,33 +1323,32 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
         for (s = 0; s < sSize; s++)
         {
-          sy = s * av.charHeight + scaleHeight;
+          sy = s * av.getCharHeight() + scaleHeight;
 
           SequenceI seq = av.getAlignment().getSequenceAt(s);
-          SequenceFeature[] features = seq.getDatasetSequence()
-                  .getSequenceFeatures();
+          SequenceFeature[] features = seq.getSequenceFeatures();
           SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
           for (res = 0; res < alwidth; res++)
           {
             text = new StringBuffer();
-            Object obj = null;
+            String triplet = null;
             if (av.getAlignment().isNucleotide())
             {
-              obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
+              triplet = ResidueProperties.nucleotideName.get(seq
+                      .getCharAt(res)
                       + "");
             }
             else
             {
-              obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
+              triplet = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
                       + "");
             }
 
-            if (obj == null)
+            if (triplet == null)
             {
               continue;
             }
 
-            String triplet = obj.toString();
             int alIndex = seq.findPosition(res);
             gSize = groups.length;
             for (g = 0; g < gSize; g++)
@@ -1336,9 +1356,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
               if (text.length() < 1)
               {
                 text.append("<area shape=\"rect\" coords=\""
-                        + (idWidth + res * av.charWidth) + "," + sy + ","
-                        + (idWidth + (res + 1) * av.charWidth) + ","
-                        + (av.charHeight + sy) + "\""
+                        + (idWidth + res * av.getCharWidth()) + "," + sy
+                        + "," + (idWidth + (res + 1) * av.getCharWidth())
+                        + ","
+                        + (av.getCharHeight() + sy) + "\""
                         + " onMouseOver=\"toolTip('" + alIndex + " "
                         + triplet);
               }
@@ -1355,9 +1376,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
               if (text.length() < 1)
               {
                 text.append("<area shape=\"rect\" coords=\""
-                        + (idWidth + res * av.charWidth) + "," + sy + ","
-                        + (idWidth + (res + 1) * av.charWidth) + ","
-                        + (av.charHeight + sy) + "\""
+                        + (idWidth + res * av.getCharWidth()) + "," + sy
+                        + "," + (idWidth + (res + 1) * av.getCharWidth())
+                        + ","
+                        + (av.getCharHeight() + sy) + "\""
                         + " onMouseOver=\"toolTip('" + alIndex + " "
                         + triplet);
               }
@@ -1433,10 +1455,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
     int chunkWidth = getSeqPanel().seqCanvas
             .getWrappedCanvasWidth(seqPanelWidth);
 
-    int hgap = av.charHeight;
-    if (av.scaleAboveWrapped)
+    int hgap = av.getCharHeight();
+    if (av.getScaleAboveWrapped())
     {
-      hgap += av.charHeight;
+      hgap += av.getCharHeight();
     }
 
     int annotationHeight = 0;
@@ -1445,7 +1467,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       annotationHeight = getAnnotationPanel().adjustPanelHeight();
     }
 
-    int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
+    int cHeight = av.getAlignment().getHeight() * av.getCharHeight() + hgap
             + annotationHeight;
 
     int maxwidth = av.getAlignment().getWidth();
@@ -1474,6 +1496,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
               .getStructureSelectionManager();
       ssm.removeStructureViewerListener(getSeqPanel(), null);
       ssm.removeSelectionListener(getSeqPanel());
+      ssm.removeCommandListener(av);
+      ssm.removeStructureViewerListener(getSeqPanel(), null);
+      ssm.removeSelectionListener(getSeqPanel());
       av.setAlignment(null);
       av = null;
     }