ensure we have valid fontMetrics - (NPE was raised when wrap mode enabled on view...
[jalview.git] / src / jalview / appletgui / AnnotationPanel.java
index f068a3c..a941ef2 100755 (executable)
@@ -41,19 +41,24 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
 
   Vector activeRes;
 
-  static String HELIX = "Helix";
+  final String HELIX = "Helix";
 
-  static String SHEET = "Sheet";
+  final String SHEET = "Sheet";
+  
+  /**
+   * For RNA secondary structure "stems" aka helices
+   */
+  final String STEM = "RNA Helix";
 
-  static String LABEL = "Label";
+  final String LABEL = "Label";
 
-  static String REMOVE = "Remove Annotation";
+  final String REMOVE = "Remove Annotation";
 
-  static String COLOUR = "Colour";
+  final String COLOUR = "Colour";
 
-  static Color HELIX_COLOUR = Color.red.darker();
+  final Color HELIX_COLOUR = Color.red.darker();
 
-  static Color SHEET_COLOUR = Color.green.darker().darker();
+  final Color SHEET_COLOUR = Color.green.darker().darker();
 
   Image image;
 
@@ -113,7 +118,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
    */
   public void actionPerformed(ActionEvent evt)
   {
-    AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+    AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
     if (aa == null)
     {
       return;
@@ -129,8 +134,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
     }
 
     String label = "";
-    if (av.colSel != null && av.colSel.size() > 0
-            && anot[av.colSel.getMin()] != null)
+    if (av.getColumnSelection() != null && av.getColumnSelection().size() > 0
+            && anot[av.getColumnSelection().getMin()] != null)
       label = anot[av.getColumnSelection().getMin()].displayCharacter;
 
     if (evt.getActionCommand().equals(REMOVE))
@@ -158,7 +163,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       {
         int index = av.getColumnSelection().columnAt(i);
 
-        if (!av.colSel.isVisible(index))
+        if (!av.getColumnSelection().isVisible(index))
           continue;
 
         if (anot[index] == null)
@@ -180,7 +185,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       {
         int index = av.getColumnSelection().columnAt(i);
 
-        if (!av.colSel.isVisible(index))
+        if (!av.getColumnSelection().isVisible(index))
           continue;
 
         if (anot[index] == null)
@@ -207,6 +212,13 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
         symbol = "\u03B2";
       }
 
+      // Added by LML to color stems
+      else if (evt.getActionCommand().equals(STEM))
+      {
+        type = 'S';
+        symbol = "\u03C3";
+      }
+
       if (!aa[activeRow].hasIcons)
       {
         aa[activeRow].hasIcons = true;
@@ -228,7 +240,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       {
         int index = av.getColumnSelection().columnAt(i);
 
-        if (!av.colSel.isVisible(index))
+        if (!av.getColumnSelection().isVisible(index))
           continue;
 
         if (anot[index] == null)
@@ -241,6 +253,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       }
     }
 
+    aa[activeRow].validateRangeAndDisplay();
+
     adjustPanelHeight();
     repaint();
 
@@ -260,7 +274,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
 
   public void mousePressed(MouseEvent evt)
   {
-    AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+    AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
     if (aa == null)
     {
       return;
@@ -302,12 +316,23 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       }
 
       PopupMenu pop = new PopupMenu("Structure type");
-      MenuItem item = new MenuItem(HELIX);
-      item.addActionListener(this);
-      pop.add(item);
-      item = new MenuItem(SHEET);
-      item.addActionListener(this);
-      pop.add(item);
+      MenuItem item;
+      /*
+       * Just display the needed structure options
+       */
+      if (av.getAlignment().isNucleotide() == true)
+      {
+        item = new MenuItem(STEM);
+        item.addActionListener(this);
+        pop.add(item);
+      } else {
+        item = new MenuItem(HELIX);
+        item.addActionListener(this);
+        pop.add(item);
+        item = new MenuItem(SHEET);
+        item.addActionListener(this);
+        pop.add(item);
+      }
       item = new MenuItem(LABEL);
       item.addActionListener(this);
       pop.add(item);
@@ -354,11 +379,11 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
   {
     if (graphStretch > -1)
     {
-      av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
+      av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
               - evt.getY();
-      if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
+      if (av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight < 0)
       {
-        av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
+        av.getAlignment().getAlignmentAnnotation()[graphStretch].graphHeight = 0;
       }
       graphStretchY = evt.getY();
       calcPanelHeight();
@@ -373,7 +398,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
 
   public void mouseMoved(MouseEvent evt)
   {
-    AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+    AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
     if (aa == null)
     {
       return;
@@ -398,7 +423,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
 
     int res = evt.getX() / av.getCharWidth() + av.getStartRes();
 
-    if (av.hasHiddenColumns)
+    if (av.hasHiddenColumns())
     {
       res = av.getColumnSelection().adjustForHiddenColumns(res);
     }
@@ -448,7 +473,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
   public int calcPanelHeight()
   {
     // setHeight of panels
-    AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+    AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
     int height = 0;
 
     if (aa != null)
@@ -498,7 +523,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
   {
     if (activeRow == -1)
     {
-      AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+      AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
       if (aa == null)
       {
         return;
@@ -563,8 +588,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
 
   public void fastPaint(int horizontal)
   {
-    if (horizontal == 0 || av.alignment.getAlignmentAnnotation() == null
-            || av.alignment.getAlignmentAnnotation().length < 1)
+    if (horizontal == 0 || av.getAlignment().getAlignmentAnnotation() == null
+            || av.getAlignment().getAlignmentAnnotation().length < 1)
     {
       repaint();
       return;
@@ -617,8 +642,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, Adjustmen
       fm = g.getFontMetrics();
     }
 
-    if ((av.alignment.getAlignmentAnnotation() == null)
-            || (av.alignment.getAlignmentAnnotation().length < 1))
+    if ((av.getAlignment().getAlignmentAnnotation() == null)
+            || (av.getAlignment().getAlignmentAnnotation().length < 1))
     {
       g.setColor(Color.white);
       g.fillRect(0, 0, getSize().width, getSize().height);