Can edit annotation name/description
authoramwaterhouse <Andrew Waterhouse>
Wed, 31 Jan 2007 16:23:19 +0000 (16:23 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 31 Jan 2007 16:23:19 +0000 (16:23 +0000)
src/jalview/appletgui/AnnotationLabels.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/AnnotationPanel.java

index 48cea13..5ee1efe 100755 (executable)
@@ -181,7 +181,7 @@ public class AnnotationLabels
     item.addActionListener(this);\r
     pop.add(item);\r
 \r
-    if (aa[selectedRow].label.equals("Consensus"))\r
+    if (aa[selectedRow]==ap.av.consensus)\r
     {\r
       pop.addSeparator();\r
       final CheckboxMenuItem cbmi = new CheckboxMenuItem(\r
index 1eb72e9..3f26ca8 100755 (executable)
@@ -3118,10 +3118,11 @@ public void showTranslation_actionPerformed(ActionEvent e)
   {
     for (int i = 0; i < annotations.length; i++)
     {
-      if (annotations[i].label.equals("Quality") ||
-          annotations[i].label.equals("Conservation") ||
-          annotations[i].label.equals("Consensus"))
+      if (annotations[i]==viewport.quality ||
+          annotations[i]==viewport.conservation ||
+          annotations[i]==viewport.consensus)
       {
+        System.out.println("COPT HERE");
         continue;
       }
 
index 1176087..a454cf9 100755 (executable)
@@ -40,6 +40,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     MouseMotionListener, ActionListener
 {
     static String ADDNEW = "Add New Row";
+    static String EDITNAME="Edit Label/Description";
     static String HIDE = "Hide This Row";
     static String DELETE = "Delete This Row";
     static String SHOWALL = "Show All Hidden Rows";
@@ -151,23 +152,23 @@ public class AnnotationLabels extends JPanel implements MouseListener,
 
         if (evt.getActionCommand().equals(ADDNEW))
         {
-            String label = JOptionPane.showInputDialog(this,
-                    "Label for annotation");
-
-            if (label == null)
-            {
-                label = "";
-            }
-
-            AlignmentAnnotation newAnnotation = new AlignmentAnnotation(label,
-                    "New description",
+            AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
+                    null,
                     new Annotation[ap.av.alignment.getWidth()]);
 
+            if(!editLabelDescription(newAnnotation))
+              return;
+
             ap.av.alignment.addAnnotation(newAnnotation);
             ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
             if (aa != null)
               dif = aa[aa.length - 1].height;
         }
+        else if(evt.getActionCommand().equals(EDITNAME))
+        {
+          editLabelDescription(aa[selectedRow]);
+          repaint();
+        }
         else if (evt.getActionCommand().equals(HIDE))
         {
             aa[selectedRow].visible = false;
@@ -217,6 +218,52 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         ap.repaint();
     }
 
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param e DOCUMENT ME!
+     */
+    boolean editLabelDescription(AlignmentAnnotation annotation)
+    {
+      JLabel idlabel = new JLabel(  "      Annotation Label ");
+      JLabel desclabel = new JLabel("Annotation Description ");
+      idlabel.setFont(new Font("Courier", Font.PLAIN, 12));
+      desclabel.setFont(new Font("Courier", Font.PLAIN, 12));
+      JTextField id = new JTextField(annotation.label, 40);
+      JTextField description = new JTextField(annotation.description, 40);
+      JPanel panel = new JPanel(new BorderLayout());
+      JPanel panel2 = new JPanel(new BorderLayout());
+      panel2.add(idlabel, BorderLayout.WEST);
+      panel2.add(id, BorderLayout.CENTER);
+      panel.add(panel2, BorderLayout.NORTH);
+      panel2 = new JPanel(new BorderLayout());
+      panel2.add(desclabel, BorderLayout.WEST);
+      panel2.add(description, BorderLayout.CENTER);
+      panel.add(panel2, BorderLayout.SOUTH);
+
+
+       int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+          panel, "Edit Annotation Name/Description",
+          JOptionPane.OK_CANCEL_OPTION );
+
+
+        if (reply != JOptionPane.OK_OPTION )
+        {
+            return false;
+        }
+
+
+        annotation.label = id.getText().trim();
+
+        String text = description.getText().trim();
+        if(text.length()==0)
+          text = null;
+        annotation.description = text;
+
+        return true;
+    }
+
     /**
      * DOCUMENT ME!
      *
@@ -330,8 +377,12 @@ public class AnnotationLabels extends JPanel implements MouseListener,
 
       if(selectedRow>-1)
       {
-        setToolTipText(ap.av.alignment.
-            getAlignmentAnnotation()[selectedRow].description);
+        String desc = ap.av.alignment.
+            getAlignmentAnnotation()[selectedRow].description;
+
+        if (desc != null && !desc.equals("New Description"))
+          setToolTipText(ap.av.alignment.
+                         getAlignmentAnnotation()[selectedRow].description);
 
       }
       repaint();
@@ -365,6 +416,9 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         JMenuItem item = new JMenuItem(ADDNEW);
         item.addActionListener(this);
         pop.add(item);
+        item = new JMenuItem(EDITNAME);
+        item.addActionListener(this);
+        pop.add(item);
         item = new JMenuItem(HIDE);
         item.addActionListener(this);
         pop.add(item);
@@ -378,7 +432,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         item.addActionListener(this);
         pop.add(item);
         // annotation object should be typed
-        if (aa[selectedRow].label.equals("Consensus"))
+        if (aa[selectedRow]==ap.av.consensus)
         {
           pop.addSeparator();
           final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
index 90438d5..e0b36d3 100755 (executable)
@@ -758,7 +758,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                 }\r
             }\r
 \r
-            if (av.updatingConsensus && aa[i].label.equals("Consensus"))\r
+            if (av.updatingConsensus && aa[i]==av.consensus)\r
             {\r
               y += av.charHeight;\r
 \r