Make sure fontmetrics is not null
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 8a262d9..bc14d66 100755 (executable)
@@ -92,6 +92,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
     public void adjustPanelHeight()\r
     {\r
         // setHeight of panels\r
+        image = null;\r
         AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
         int height = 0;\r
 \r
@@ -147,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
@@ -177,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
@@ -332,7 +337,10 @@ public class AnnotationPanel extends JPanel implements MouseListener,
 \r
         for (int i = 0; i < aa.length; i++)\r
         {\r
-            height += aa[i].height;\r
+            if (aa[i].visible)\r
+            {\r
+              height += aa[i].height;\r
+            }\r
 \r
             if (evt.getY() < height)\r
             {\r
@@ -522,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
@@ -600,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
@@ -634,6 +648,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                 continue;\r
             }\r
 \r
+\r
             if (row.isGraph)\r
             {\r
                 // this is so that we draw the characters below the graph\r
@@ -841,19 +856,23 @@ public class AnnotationPanel extends JPanel implements MouseListener,
     }\r
 \r
     // used by overview window\r
-    public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y)\r
+    public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)\r
     {\r
         g.setColor(Color.white);\r
         g.fillRect(0, 0, width, y);\r
         g.setColor(new Color(0, 0, 180));\r
 \r
-        int x = 0;\r
 \r
-        for (int j = 0; j < aa.annotations.length; j++)\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