Merge branch 'develop' into features/JAL-845splitPaneMergeDevelop
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index e638cc0..8998f09 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -95,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)
   {
@@ -123,8 +121,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     setScrollValues(0, 0);
 
-    setAnnotationVisible(av.isShowAnnotation());
-
     hscroll.addAdjustmentListener(this);
     vscroll.addAdjustmentListener(this);
 
@@ -142,7 +138,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     });
     fontChanged();
     adjustAnnotationHeight();
-
+    updateLayout();
   }
 
   @Override
@@ -180,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);
@@ -202,11 +199,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;
   }
 
   /**
@@ -495,13 +502,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);
@@ -660,7 +670,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
-
     int oldX = av.getStartRes();
     int oldY = av.getStartSeq();
 
@@ -1158,8 +1167,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
@@ -1320,24 +1328,24 @@ public class AlignmentPanel extends GAlignmentPanel implements
           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++)
@@ -1485,6 +1493,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;
     }