edit label/displayChar contains existing character(s) of sites to be edited
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 0fb84b0..149f432 100755 (executable)
@@ -182,10 +182,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 +204,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 +288,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!
    *