nullpointer bug fix on consensus thread
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 487b832..afc09cc 100755 (executable)
@@ -71,10 +71,7 @@ public class AnnotationPanel
   public AnnotationPanel(AlignmentPanel ap)
   {
 
-    if (System.getProperty("os.name").startsWith("Mac"))
-    {
-      MAC = true;
-    }
+    MAC = new jalview.util.Platform().isAMac();
 
     ToolTipManager.sharedInstance().registerComponent(this);
     ToolTipManager.sharedInstance().setInitialDelay(0);
@@ -182,10 +179,9 @@ public class AnnotationPanel
     }
     else if (evt.getActionCommand().equals(LABEL))
     {
-      String label = JOptionPane.showInputDialog(this, "Enter Label ",
-                                                 "Enter label",
-                                                 JOptionPane.QUESTION_MESSAGE);
-
+      String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
+      String label = JOptionPane.showInputDialog(this,"Enter label",exMesg);
+      
       if (label == null)
       {
         return;
@@ -205,10 +201,10 @@ public class AnnotationPanel
 
         if (anot[index] == null)
         {
-          anot[index] = new Annotation(label, "", ' ', 0);
+          anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that null exceptions aren't raised elsewhere.
+        } else {
+          anot[index].displayCharacter = label;
         }
-
-        anot[index].displayCharacter = label;
       }
     }
     else if (evt.getActionCommand().equals(COLOUR))
@@ -289,6 +285,46 @@ public class AnnotationPanel
     return;
   }
 
+  private String collectAnnotVals(Annotation[] anot, ColumnSelection columnSelection,
+          String label2)
+  {
+    String collatedInput="";
+    String last="";
+    for (int i = 0; i < columnSelection.size(); i++)
+    {
+      int index = columnSelection.columnAt(i);
+      // always check for current display state - just in case
+      if(!av.colSel.isVisible(index))
+        continue;
+      String tlabel=null;
+      if (anot[index] != null)
+      {
+        if (label2.equals(HELIX) || label2.equals(SHEET) || label2.equals(LABEL))
+        {
+          tlabel = anot[index].description;
+          if (tlabel == null)
+          {
+            if (label2.equals(HELIX) || label2.equals(SHEET))
+            {
+              tlabel = ""+anot[index].secondaryStructure;
+            } else {
+              tlabel = ""+anot[index].displayCharacter;
+            }            
+          }
+        }
+        if (tlabel!=null && !tlabel.equals(last))
+        {
+          if (last.length()>0)
+          {
+            collatedInput+=" ";
+          }
+          collatedInput+=tlabel;
+        }
+      }
+    }
+    return collatedInput;
+  }
+
   /**
    * DOCUMENT ME!
    *
@@ -548,7 +584,8 @@ public class AnnotationPanel
       }
     }
     imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
-
+    if (imgWidth<1)
+      return;
     if (image == null || imgWidth != image.getWidth()
         || image.getHeight(this) != getHeight())
     {