Check row.annotations is not null
[jalview.git] / src / jalview / appletgui / AnnotationPanel.java
index daa68d1..614498c 100755 (executable)
@@ -60,7 +60,7 @@ public class AnnotationPanel
 \r
     this.ap = ap;\r
     av = ap.av;\r
-    this.setLayout(null);\r
+    setLayout(null);\r
     adjustPanelHeight();\r
 \r
     addMouseMotionListener(new MouseMotionAdapter()\r
@@ -131,9 +131,6 @@ public class AnnotationPanel
     }\r
 \r
     this.setSize(getSize().width, height);\r
-    if(ap!=null)\r
-       ap.annotationScroller.setSize(getSize().width, height);\r
-\r
 \r
     repaint();\r
 \r
@@ -211,6 +208,8 @@ public class AnnotationPanel
 \r
   public void paint(Graphics g)\r
   {\r
+\r
+\r
     imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;\r
 \r
     if (image == null || imgWidth != image.getWidth(this))\r
@@ -230,6 +229,8 @@ public class AnnotationPanel
     }\r
 \r
     drawComponent(gg, av.startRes, av.endRes + 1);\r
+    g.setColor(Color.white);\r
+    g.fillRect(0, 0, getSize().width, getSize().height);\r
     g.drawImage(image, 0, 0, this);\r
   }\r
 \r
@@ -291,14 +292,14 @@ public class AnnotationPanel
           g.setColor(Color.white);\r
           g.fillRect(0, 0, getSize().width, getSize().height);\r
           g.setColor(Color.black);\r
-          g.drawString("Alignment has no annotations", 20, 15);\r
+          if(av.validCharWidth)\r
+            g.drawString("Alignment has no annotations", 20, 15);\r
 \r
           return;\r
       }\r
 \r
       AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
 \r
-      int j;\r
       int x = 0;\r
       int y = 0;\r
       char lastSS;\r
@@ -361,8 +362,8 @@ public class AnnotationPanel
               x = (column - startRes) * av.charWidth;\r
 \r
 \r
-              if (validRes &&\r
-                      (row.annotations[column].displayCharacter.length() > 0))\r
+              if (av.validCharWidth && validRes &&\r
+                        (row.annotations[column].displayCharacter.length() > 0))\r
               {\r
                 int charOffset = (av.charWidth -\r
                     fm.charWidth(row.annotations[column].displayCharacter.charAt(\r
@@ -466,6 +467,9 @@ public class AnnotationPanel
           column++;\r
           }\r
 \r
+          if(column>=row.annotations.length)\r
+              column = row.annotations.length-1;\r
+\r
           x += av.charWidth;\r
 \r
           if (row.hasIcons)\r
@@ -510,8 +514,8 @@ public class AnnotationPanel
               case 'E':\r
                   g.setColor(SHEET_COLOUR);\r
 \r
-                  if (row.annotations.length > endRes\r
-                      && row.annotations[endRes].secondaryStructure != 'E')\r
+                  if (row.annotations[endRes] ==null\r
+                        || row.annotations[endRes].secondaryStructure != 'E')\r
                   {\r
                     g.fillRect(lastSSX, y + 4 + iconOffset,\r
                                x - lastSSX - 4, 7);\r
@@ -623,7 +627,7 @@ public class AnnotationPanel
 \r
     ////Draw origin\r
     if(min<0)\r
-      y2 = (int)(y - (0-min / range)*graphHeight);\r
+      y2 = y - (int)((0-min / range)*graphHeight);\r
 \r
     g.setColor(Color.gray);\r
     g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);\r
@@ -671,7 +675,7 @@ public class AnnotationPanel
     y1 = y2 = y;\r
 \r
     if(min<0)\r
-      y2 = (int)(y - (0-min / (range))*aa.graphHeight);\r
+      y2 = y -(int)( (0-min / (range))*aa.graphHeight);\r
 \r
     g.setColor(Color.gray);\r
 \r