Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / gui / IdCanvas.java
index c94dee0..4f4b796 100755 (executable)
@@ -55,17 +55,18 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
   BufferedImage image;
 
-  // Graphics2D gg;
+//  Graphics2D gg;
 
   int imgHeight = 0;
 
-  boolean fastPaint = false;
+  private boolean fastPaint = false;
 
   List<SequenceI> searchResults;
 
   AnnotationPanel ap;
 
   private Font idfont;
+  private boolean allowFastPaint;
 
   /**
    * Creates a new IdCanvas object.
@@ -79,7 +80,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     this.av = av;
     PaintRefresher.Register(this, av.getSequenceSetId());
     av.getRanges().addPropertyChangeListener(this);
-  }
+    }
 
   /**
    * DOCUMENT ME!
@@ -137,6 +138,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     g.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos,
             (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
 
+    // JAL-3253-applet was just hiddenRows here. ccfc48e (gmungoc) added getShowHiddenMarkers test
     if (hiddenRows && av.getShowHiddenMarkers())
     {
       drawMarker(g, av, i, starty, ypos);
@@ -203,7 +205,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     gg.translate(0, -transY);
 
     gg.dispose();
-
+    
     fastPaint = true;
 
     // Call repaint on alignment panel so that repaints from other alignment
@@ -221,44 +223,47 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   @Override
   public void paintComponent(Graphics g)
   {
+    if (av.getAlignPanel().getHoldRepaint())
+    {
+      return;
+    }
     g.setColor(Color.white);
     g.fillRect(0, 0, getWidth(), getHeight());
-
-    if (fastPaint)
+    
+    if (allowFastPaint && 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);
+                BufferedImage.TYPE_INT_RGB);
     }
-
+    
     Graphics2D gg = image.createGraphics();
-
+    
     // Fill in the background
     gg.setColor(Color.white);
     gg.fillRect(0, 0, getWidth(), imgHeight);
-
-    drawIds(gg, av, av.getRanges().getStartSeq(),
-            av.getRanges().getEndSeq(), searchResults);
+    
+    drawIds(gg, av, av.getRanges().getStartSeq(), av.getRanges().getEndSeq(), searchResults);
 
     gg.dispose();
-
+    
     g.drawImage(image, 0, 0, this);
   }
 
@@ -274,13 +279,14 @@ public class IdCanvas extends JPanel implements ViewportListenerI
    * @param endSeq
    * @param selection
    */
-  void drawIds(Graphics2D g, AlignViewport alignViewport,
-          final int startSeq, final int endSeq, List<SequenceI> selection)
+  void drawIds(Graphics2D g, AlignViewport alignViewport, final int startSeq,
+          final int endSeq, List<SequenceI> selection)
   {
     Font font = alignViewport.getFont();
     if (alignViewport.isSeqNameItalics())
     {
-      setIdfont(new Font(font.getName(), Font.ITALIC, font.getSize()));
+      setIdfont(new Font(font.getName(), Font.ITALIC,
+              font.getSize()));
     }
     else
     {
@@ -348,7 +354,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
       g.setColor(currentColor);
 
       int charHeight = alignViewport.getCharHeight();
-      g.fillRect(0, (i - startSeq) * charHeight, getWidth(), charHeight);
+      g.fillRect(0, (i - startSeq) * charHeight,
+              getWidth(), charHeight);
 
       g.setColor(currentTextColor);
 
@@ -360,9 +367,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
         xPos = panelWidth - fm.stringWidth(string) - 4;
       }
 
-      g.drawString(string, xPos,
-              (((i - startSeq) * charHeight) + charHeight)
-                      - (charHeight / 5));
+      g.drawString(string, xPos, (((i - startSeq) * charHeight) + charHeight)
+              - (charHeight / 5));
 
       if (hasHiddenRows && av.getShowHiddenMarkers())
       {
@@ -385,17 +391,31 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     int alignmentWidth = alignViewport.getAlignment().getWidth();
     final int alheight = alignViewport.getAlignment().getHeight();
 
-    /*
+
+    /* (former)
      * assumption: SeqCanvas.calculateWrappedGeometry has been called
+     * 
+     * was based on the fact that SeqCanvas was added as a child prior to IdCanvas, 
+     * and children are processed in order of addition.
+     * 
+     * It's probably fine. But...
+     * 
      */
     SeqCanvas seqCanvas = alignViewport.getAlignPanel()
             .getSeqPanel().seqCanvas;
+    // ...better: let's call it now
+    seqCanvas.calculateWrappedGeometry();
 
     final int charHeight = alignViewport.getCharHeight();
 
     AnnotationLabels labels = null;
     if (alignViewport.isShowAnnotation())
     {
+       // BH when was ap == null?
+      if (ap == null)
+      {
+        ap = new AnnotationPanel(alignViewport);
+      }
       labels = new AnnotationLabels(alignViewport);
     }
 
@@ -448,8 +468,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
    * @param starty
    * @param yoffset
    */
-  void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex,
-          int starty, int yoffset)
+  void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, int starty, int yoffset)
   {
     SequenceI[] hseqs = alignViewport.getAlignment()
             .getHiddenSequences().hiddenSequences;
@@ -492,7 +511,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     /*
      * vertices of the triangle, below or above hidden seqs
      */
-    int[] xPoints = new int[] { getWidth() - charHeight,
+    int[] xPoints = new int[]
+    { getWidth() - charHeight,
         getWidth() - charHeight, getWidth() };
     int yShift = seqIndex - starty;
 
@@ -569,20 +589,34 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   public void propertyChange(PropertyChangeEvent evt)
   {
     String propertyName = evt.getPropertyName();
-    if (propertyName.equals(ViewportRanges.STARTSEQ)
-            || (av.getWrapAlignment()
-                    && propertyName.equals(ViewportRanges.STARTRES)))
+    switch (propertyName)
     {
+    case ViewportRanges.STARTSEQ:
       fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
-    }
-    else if (propertyName.equals(ViewportRanges.STARTRESANDSEQ))
-    {
+      break;
+    case ViewportRanges.STARTRES:
+      if (av.getWrapAlignment())
+      {
+        fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
+      }
+      break;
+    case ViewportRanges.STARTRESANDSEQ:
       fastPaint(((int[]) evt.getNewValue())[1]
               - ((int[]) evt.getOldValue())[1]);
-    }
-    else if (propertyName.equals(ViewportRanges.MOVE_VIEWPORT))
-    {
+      break;
+    case ViewportRanges.MOVE_VIEWPORT:
       repaint();
+      break;
+    default:
     }
   }
+
+  /**
+   * Clears the flag that allows a 'fast paint' on the next repaint, so
+   * requiring a full repaint
+   */
+  public void setNoFastPaint()
+  {
+    allowFastPaint = false;
+  }
 }