annotation might have been deleted
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index 63d7c53..783c905 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";
@@ -66,6 +67,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     {
         this.ap = ap;
         av = ap.av;
+        ToolTipManager.sharedInstance().registerComponent(this);
 
         java.net.URL url = getClass().getResource("/images/idwidth.gif");
         Image temp = null;
@@ -150,40 +152,30 @@ 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;
 
-            if (aa[selectedRow].label.equals("Conservation"))
-            {
-                ap.av.showConservation = false;
-            }
-
             if (aa[selectedRow].label.equals("Quality"))
             {
-                ap.av.showQuality = false;
-            }
-
-            if (aa[selectedRow].label.equals("Consensus"))
-            {
-                ap.av.showIdentity = false;
+                ap.av.quality = null;
             }
 
             dif = aa[selectedRow].height * -1;
@@ -209,7 +201,8 @@ public class AnnotationLabels extends JPanel implements MouseListener,
           new AnnotationExporter().exportAnnotations(
               ap,
               new AlignmentAnnotation[]
-              {aa[selectedRow]}
+              {aa[selectedRow]},
+              null
               );
         }
         else if (evt.getActionCommand().equals(COPYCONS_SEQ))
@@ -217,7 +210,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
           SequenceI cons=av.getConsensusSeq();
           if (cons!=null)
             copy_annotseqtoclipboard(cons);
-          
+
         }
 
         ap.annotationPanel.adjustPanelHeight();
@@ -225,6 +218,35 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         ap.repaint();
     }
 
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @param e DOCUMENT ME!
+     */
+    boolean editLabelDescription(AlignmentAnnotation annotation)
+    {
+      EditNameDialog dialog = new EditNameDialog(annotation.label,
+                                                 annotation.description,
+                                                 "       Annotation Name ",
+                                                 "Annotation Description ",
+                                                 "Edit Annotation Name/Description");
+
+      if (!dialog.accept)
+      {
+        return false;
+      }
+
+        annotation.label = dialog.getName();
+
+        String text = dialog.getDescription();
+        if(text.length()==0)
+          text = null;
+        annotation.description = text;
+
+        return true;
+    }
+
     /**
      * DOCUMENT ME!
      *
@@ -334,6 +356,19 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     {
       resizePanel = evt.getY()<10;
 
+      getSelectedRow(evt.getY() - scrollOffset);
+
+      if(selectedRow>-1
+         && ap.av.alignment.getAlignmentAnnotation().length>selectedRow)
+      {
+        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 +400,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 +416,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(
@@ -387,8 +425,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
           cbmi.addActionListener(new ActionListener()
               {public void actionPerformed(ActionEvent e)
                {
-                 ap.av.setIgnoreGapsConsensus(cbmi.getState());
-                 ap.repaint();
+                 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
                }
               });
           pop.add(cbmi);
@@ -411,7 +448,11 @@ public class AnnotationLabels extends JPanel implements MouseListener,
       SequenceI [] dseqs=new SequenceI[] { sq.getDatasetSequence()};
       if (dseqs[0]==null) {
         dseqs[0] = new Sequence(sq);
-        dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sq.getSequence()));
+        dseqs[0].setSequence(
+            jalview.analysis.AlignSeq.extractGaps(
+                jalview.util.Comparison.GapChars,
+                sq.getSequenceAsString()));
+
         sq.setDatasetSequence(dseqs[0]);
       }
       Alignment ds=new Alignment(dseqs);
@@ -442,7 +483,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
                             region[1]});
         }
       }
-      
+
       Desktop.jalviewClipboard = new Object[]{ seqs,
           ds, // what is the dataset of a consensus sequence ? need to flag sequence as special.
           hiddenColumns};