Make sure fontmetrics is not null
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 9c2aac0..bc14d66 100755 (executable)
@@ -148,6 +148,8 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         if (activeRow == -1)\r
         {\r
             AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+            if(aa==null)\r
+              return;\r
 \r
             for (int j = 0; j < aa.length; j++)\r
             {\r
@@ -178,6 +180,8 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         if (activeRow == -1)\r
         {\r
             AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+            if(aa==null)\r
+              return;\r
 \r
             for (int j = 0; j < aa.length; j++)\r
             {\r
@@ -526,7 +530,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
       g.setColor(Color.white);\r
       g.fillRect(0, 0, getWidth(), getHeight());\r
 \r
-      if (fastPaint)\r
+      if (fastPaint && image!=null)\r
       {\r
         g.drawImage(image, 0, 0, this);\r
         fastPaint = false;\r
@@ -604,6 +608,12 @@ public class AnnotationPanel extends JPanel implements MouseListener,
      */\r
     public void drawComponent(Graphics2D g, int startRes, int endRes)\r
     {\r
+      if (fm == null)\r
+        fm = g.getFontMetrics();\r
+\r
+               if(fm==null)\r
+                       fm = g.getFontMetrics();\r
+\r
         g.setColor(Color.white);\r
         g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());\r
 \r
@@ -852,13 +862,17 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         g.fillRect(0, 0, width, y);\r
         g.setColor(new Color(0, 0, 180));\r
 \r
-        int x = 0;\r
+\r
+        int x = 0, height;\r
 \r
         for (int j = sRes; j < eRes; j++)\r
         {\r
             g.setColor(new Color(0, 0, 180));\r
 \r
-            int height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
+            height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
+            if(height>y)\r
+              height = y;\r
+\r
             g.fillRect(x, y - height, av.charWidth, height);\r
             x += av.charWidth;\r
         }\r