Check if colos are null
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 5c6bcf4..b8d35dc 100755 (executable)
@@ -29,6 +29,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
   FontMetrics fm;\r
   int imgWidth=0;\r
 \r
+  boolean fastPaint = false;\r
+\r
+  public static int GRAPH_HEIGHT = 40;\r
 \r
 \r
 \r
@@ -69,7 +72,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
         aa[i].height += 16;\r
 \r
       if (aa[i].isGraph)\r
-        aa[i].height += 50;\r
+        aa[i].height += GRAPH_HEIGHT;\r
 \r
       if(aa[i].height==0)\r
         aa[i].height = 20;\r
@@ -309,7 +312,14 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
 \r
     int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
     if(row>-1 && res<aa[row].annotations.length && aa[row].annotations[res]!=null)\r
+    {\r
       this.setToolTipText(aa[row].annotations[res].description);\r
+      StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +\r
+                                           "  " +\r
+                                           aa[row].annotations[res].description);\r
+      ap.alignFrame.statusBar.setText(text.toString());\r
+    }\r
+\r
 \r
   }\r
   public void mouseClicked(MouseEvent evt) {}\r
@@ -320,27 +330,36 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
     g.setColor(Color.white);\r
     g.fillRect(0,0,getWidth(), getHeight());\r
 \r
+    if(fastPaint)\r
+    {\r
+      g.drawImage(image, 0, 0, this);\r
+      fastPaint = false;\r
+      return;\r
+    }\r
+\r
     imgWidth = (av.endRes-av.startRes+1) *av.charWidth;\r
 \r
     image = new BufferedImage(imgWidth,\r
                                 ap.annotationPanel.getHeight(),\r
                                 BufferedImage.TYPE_INT_RGB);\r
       gg = (Graphics2D) image.getGraphics();\r
-      gg.setColor(Color.white);\r
-      gg.fillRect(0, 0, imgWidth, getHeight());\r
       gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
                           RenderingHints.VALUE_ANTIALIAS_ON);\r
-      fm = gg.getFontMetrics();\r
-      gg.setFont(av.getFont());\r
 \r
+      gg.setFont(av.getFont());\r
+      fm = gg.getFontMetrics();\r
 \r
     drawComponent( gg, av.startRes, av.endRes+1);\r
     g.drawImage( image, 0, 0, this);\r
+\r
   }\r
 \r
   public void fastPaint(int horizontal)\r
 {\r
-  if(image==null || horizontal ==0)\r
+  if( horizontal == 0\r
+     || av.alignment.getAlignmentAnnotation()==null\r
+     || av.alignment.getAlignmentAnnotation().length<1\r
+    )\r
   {\r
     repaint();\r
     return;\r
@@ -366,7 +385,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
 \r
   gg.translate( -transX, 0 );\r
 \r
-  getGraphics().drawImage(image, 0, 0, this);\r
+  fastPaint = true;\r
+  repaint();\r
 }\r
 \r
 \r
@@ -376,6 +396,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
     g.fillRect(0,0,(endRes-startRes) *av.charWidth, getHeight());\r
     if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1)\r
     {\r
+      g.setColor(Color.white);\r
+      g.fillRect(0,0,getWidth(), getHeight());\r
       g.setColor(Color.black);\r
       g.drawString("Alignment has no annotations",20,15);\r
       return;\r
@@ -389,6 +411,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
     int iconOffset = av.charHeight/2;\r
     boolean validRes = false;\r
     //\u03B2 \u03B1\r
+\r
     for(int i=0; i<aa.length; i++)\r
     {\r
       AlignmentAnnotation row = aa[i];\r
@@ -409,7 +432,10 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
 \r
       for(j=startRes; j<endRes; j++)\r
       {\r
-        validRes = row.annotations[j]==null?false:true;\r
+        if(row.annotations.length<=j || row.annotations[j]==null)\r
+        validRes = false;\r
+       else\r
+         validRes = true;\r
 \r
        x = (j-startRes)*av.charWidth;\r
 \r
@@ -432,9 +458,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
 \r
        if(validRes && row.annotations[j].displayCharacter.length()>0)\r
        {\r
-         int charOffset = (av.charWidth -\r
-                            fm.charWidth(row.annotations[j].displayCharacter.\r
-                                         charAt(0))) / 2;\r
+         int charOffset = (av.charWidth - fm.charWidth(row.annotations[j].displayCharacter.charAt(0)))/2;\r
          g.setColor( row.annotations[j].colour);\r
           if(j==0)\r
           {\r
@@ -488,7 +512,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
        if (validRes && row.isGraph)\r
        {\r
          g.setColor(new Color(0,0,180));\r
-         int height = (int)((row.annotations[j].value / row.graphMax)*50);\r
+         int height = (int)((row.annotations[j].value / row.graphMax)*GRAPH_HEIGHT);\r
 \r
          if(row.windowLength>1)\r
          {\r
@@ -502,10 +526,10 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
            }\r
 \r
            total/=row.windowLength;\r
-           height = (int)( (total / row.graphMax) *50);\r
+           height = (int)( (total / row.graphMax) *GRAPH_HEIGHT);\r
 \r
          }\r
-\r
+         g.setColor(row.annotations[j].colour);\r
          g.fillRect(x, y-height, av.charWidth, height );\r
        }\r
 \r
@@ -556,7 +580,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, MouseMotio
     for(int j=0; j<aa.annotations.length; j++)\r
     {\r
       g.setColor(new Color(0, 0, 180));\r
-      int height = (int) ( (aa.annotations[j].value / aa.graphMax) * 50);\r
+      int height = (int) ( (aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT );\r
       g.fillRect(x, y - height, av.charWidth, height);\r
       x+=av.charWidth;\r
     }\r