JAL-3099 use Alignment.getVisibleWidth() where wanted
[jalview.git] / src / jalview / gui / IdCanvas.java
index 052c527..9ff0652 100755 (executable)
@@ -83,7 +83,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     this.av = av;
     PaintRefresher.Register(this, av.getSequenceSetId());
     av.getRanges().addPropertyChangeListener(this);
-  }
+    }
 
   /**
    * DOCUMENT ME!
@@ -204,7 +204,11 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     gg.translate(0, -transY);
 
     fastPaint = true;
-    repaint();
+
+    // Call repaint on alignment panel so that repaints from other alignment
+    // panel components can be aggregated. Otherwise performance of the overview
+    // window and others may be adversely affected.
+    av.getAlignPanel().repaint();
   }
 
   /**
@@ -216,41 +220,43 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   @Override
   public void paintComponent(Graphics g)
   {
+    super.paintComponent(g);
+
     g.setColor(Color.white);
     g.fillRect(0, 0, getWidth(), getHeight());
-
+    
     if (fastPaint)
     {
       fastPaint = false;
       g.drawImage(image, 0, 0, this);
-
+    
       return;
     }
-
+    
     int oldHeight = imgHeight;
-
+    
     imgHeight = getHeight();
     imgHeight -= (imgHeight % av.getCharHeight());
-
+    
     if (imgHeight < 1)
     {
       return;
     }
-
+    
     if (oldHeight != imgHeight || image.getWidth(this) != getWidth())
     {
-      image = new BufferedImage(getWidth(), imgHeight,
-              BufferedImage.TYPE_INT_RGB);
+       image = new BufferedImage(getWidth(), imgHeight,
+                BufferedImage.TYPE_INT_RGB);
     }
-
+    
     gg = (Graphics2D) image.getGraphics();
-
+    
     // Fill in the background
     gg.setColor(Color.white);
     gg.fillRect(0, 0, getWidth(), imgHeight);
-
+    
     drawIds(av.getRanges().getStartSeq(), av.getRanges().getEndSeq());
-
+    
     g.drawImage(image, 0, 0, this);
   }
 
@@ -266,8 +272,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   {
     if (av.isSeqNameItalics())
     {
-      setIdfont(new Font(av.getFont().getName(), Font.ITALIC, av.getFont()
-              .getSize()));
+      setIdfont(new Font(av.getFont().getName(), Font.ITALIC,
+              av.getFont().getSize()));
     }
     else
     {
@@ -323,9 +329,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
         currentColor = Color.black;
         currentTextColor = Color.white;
       }
-      else if ((av.getSelectionGroup() != null)
-              && av.getSelectionGroup().getSequences(null)
-                      .contains(sequence))
+      else if ((av.getSelectionGroup() != null) && av.getSelectionGroup()
+              .getSequences(null).contains(sequence))
       {
         currentColor = Color.lightGray;
         currentTextColor = Color.black;
@@ -369,15 +374,9 @@ public class IdCanvas extends JPanel implements ViewportListenerI
    */
   protected void drawIdsWrapped(int starty, boolean hasHiddenRows)
   {
-    int maxwidth = av.getAlignment().getWidth();
+    int maxwidth = av.getAlignment().getVisibleWidth();
     int alheight = av.getAlignment().getHeight();
 
-    if (av.hasHiddenColumns())
-    {
-      maxwidth = av.getAlignment().getHiddenColumns()
-              .findColumnPosition(maxwidth) - 1;
-    }
-
     int annotationHeight = 0;
 
     if (av.isShowAnnotation())
@@ -444,7 +443,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   void drawMarker(int i, int starty, int yoffset)
   {
 
-    SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
+    SequenceI[] hseqs = av.getAlignment()
+            .getHiddenSequences().hiddenSequences;
     // Use this method here instead of calling hiddenSeq adjust
     // 3 times.
     int hSize = hseqs.length;
@@ -479,32 +479,36 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     if (below)
     {
       gg.fillPolygon(
-              new int[] { getWidth() - av.getCharHeight(),
+              new int[]
+              { getWidth() - av.getCharHeight(),
                   getWidth() - av.getCharHeight(), getWidth() },
-              new int[] {
-                  (i - starty) * av.getCharHeight() + yoffset,
+              new int[]
+              { (i - starty) * av.getCharHeight() + yoffset,
                   (i - starty) * av.getCharHeight() + yoffset
                           + av.getCharHeight() / 4,
-                  (i - starty) * av.getCharHeight() + yoffset }, 3);
+                  (i - starty) * av.getCharHeight() + yoffset },
+              3);
     }
     if (above)
     {
       gg.fillPolygon(
-              new int[] { getWidth() - av.getCharHeight(),
+              new int[]
+              { getWidth() - av.getCharHeight(),
                   getWidth() - av.getCharHeight(), getWidth() },
-              new int[] {
-                  (i - starty + 1) * av.getCharHeight() + yoffset,
+              new int[]
+              { (i - starty + 1) * av.getCharHeight() + yoffset,
                   (i - starty + 1) * av.getCharHeight() + yoffset
                           - av.getCharHeight() / 4,
-                  (i - starty + 1) * av.getCharHeight() + yoffset }, 3);
+                  (i - starty + 1) * av.getCharHeight() + yoffset },
+              3);
 
     }
   }
 
   void setHiddenFont(SequenceI seq)
   {
-    Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
-            .getSize());
+    Font bold = new Font(av.getFont().getName(), Font.BOLD,
+            av.getFont().getSize());
 
     if (av.isReferenceSeq(seq) || av.isHiddenRepSequence(seq))
     {
@@ -555,10 +559,19 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   {
     String propertyName = evt.getPropertyName();
     if (propertyName.equals(ViewportRanges.STARTSEQ)
-            || (av.getWrapAlignment() && propertyName
-                    .equals(ViewportRanges.STARTRES)))
+            || (av.getWrapAlignment()
+                    && propertyName.equals(ViewportRanges.STARTRES)))
     {
       fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
     }
+    else if (propertyName.equals(ViewportRanges.STARTRESANDSEQ))
+    {
+      fastPaint(((int[]) evt.getNewValue())[1]
+              - ((int[]) evt.getOldValue())[1]);
+    }
+    else if (propertyName.equals(ViewportRanges.MOVE_VIEWPORT))
+    {
+      repaint();
+    }
   }
 }