All colours added, also sequence menu added
authoramwaterhouse <Andrew Waterhouse>
Wed, 15 Dec 2004 17:18:39 +0000 (17:18 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 15 Dec 2004 17:18:39 +0000 (17:18 +0000)
src/jalview/gui/PopupMenu.java

index 458a6be..62d69d0 100755 (executable)
@@ -9,7 +9,6 @@ import java.awt.event.*;
 \r
 public class PopupMenu extends JPopupMenu\r
 {\r
-  JMenuItem residueMenu = new JMenuItem();\r
   JMenu groupMenu = new JMenu();\r
   JMenuItem copyGroup = new JMenuItem();\r
   JMenuItem moveGroup = new JMenuItem();\r
@@ -31,17 +30,28 @@ public class PopupMenu extends JPopupMenu
   protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();\r
   protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();\r
   JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();\r
-  protected JMenuItem conservationColourIncMenuItem = new JMenuItem();\r
   protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();\r
 \r
 \r
-  AlignViewport av;\r
-  SeqPanel seqPanel;\r
+  AlignmentPanel ap;\r
+  JMenu sequenceMenu = new JMenu();\r
+  JMenuItem sequenceName = new JMenuItem();\r
+  JMenu residueMenu = new JMenu();\r
+  JMenuItem annotateResidue = new JMenuItem();\r
 \r
-  public PopupMenu(AlignViewport av, SeqPanel sp)\r
+  SequenceI sequence;\r
+\r
+  public PopupMenu(AlignmentPanel ap, SequenceI seq)\r
   {\r
-    this.av = av;\r
-    seqPanel = sp;\r
+    ///////////////////////////////////////////////////////////\r
+    // If this is activated from the sequence panel, the user may want to\r
+    // edit or annotate a particular residue. Therefore display the residue menu\r
+    //\r
+    // If from the IDPanel, we must display the sequence menu\r
+    //////////////////////////////////////////////////////////\r
+\r
+    this.ap = ap;\r
+    sequence = seq;\r
 \r
     ButtonGroup colours = new ButtonGroup();\r
     colours.add(noColourmenuItem);\r
@@ -59,20 +69,25 @@ public class PopupMenu extends JPopupMenu
     colours.add(BLOSUM62Colour);\r
 \r
     try\r
-    {\r
-      jbInit();\r
-    }\r
+    {     jbInit();   }\r
     catch(Exception e)\r
+    {    e.printStackTrace();    }\r
+\r
+    SequenceGroup sg = ap.av.getRubberbandGroup();\r
+    if(sg!=null)\r
+      groupName.setText( sg.getName() );\r
+\r
+    if(seq!=null)\r
     {\r
-      e.printStackTrace();\r
+      residueMenu.setVisible(false);\r
+      sequenceName.setText( sequence.getName() );\r
     }\r
+    else\r
+      sequenceMenu.setVisible(false);\r
 \r
-    SequenceGroup sg = av.getRubberbandGroup();\r
-    groupName.setText( sg.getName() );\r
   }\r
   private void jbInit() throws Exception\r
   {\r
-    residueMenu.setText("Residue");\r
     groupMenu.setText("Group");\r
     copyGroup.setText("Copy region to new Alignment");\r
     copyGroup.addActionListener(new java.awt.event.ActionListener()\r
@@ -123,8 +138,21 @@ public class PopupMenu extends JPopupMenu
         groupAnnotation_actionPerformed(e);\r
       }\r
     });\r
+    sequenceMenu.setText("Sequence");\r
+    sequenceName.setText("sequenceName");\r
+    sequenceName.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        sequenceName_actionPerformed(e);\r
+      }\r
+    });\r
+    residueMenu.setText("Residue");\r
+    annotateResidue.setText("annotate residue???");\r
+    PIDColour.setFocusPainted(false);\r
     add(groupMenu);\r
-    add(residueMenu);\r
+    this.add(sequenceMenu);\r
+    this.add(residueMenu);\r
     groupMenu.add(defineMenu);\r
     groupMenu.addSeparator();\r
     groupMenu.add(copyGroup);\r
@@ -145,13 +173,14 @@ public class PopupMenu extends JPopupMenu
     defineMenu.add(turnColour);\r
     defineMenu.add(buriedColour);\r
     defineMenu.add(userDefinedColour);\r
-    defineMenu.addSeparator();\r
-    defineMenu.add(conservationMenuItem);\r
-    defineMenu.add(conservationColourIncMenuItem);\r
-    defineMenu.addSeparator();\r
-    defineMenu.add(abovePIDColour);\r
     defineMenu.add(PIDColour);\r
     defineMenu.add(BLOSUM62Colour);\r
+    defineMenu.addSeparator();\r
+    defineMenu.add(abovePIDColour);\r
+    defineMenu.add(conservationMenuItem);\r
+\r
+    sequenceMenu.add(sequenceName);\r
+    residueMenu.add(annotateResidue);\r
 \r
     noColourmenuItem.setText("None");\r
     noColourmenuItem.setSelected(true);\r
@@ -163,7 +192,6 @@ public class PopupMenu extends JPopupMenu
       }\r
     });\r
 \r
-    clustalColour.setEnabled(false);\r
     clustalColour.setSelected(false);\r
     clustalColour.setText("Clustalx colours");\r
     clustalColour.addActionListener(new java.awt.event.ActionListener()\r
@@ -229,7 +257,6 @@ public class PopupMenu extends JPopupMenu
         buriedColour_actionPerformed(e);\r
       }\r
     });\r
-    abovePIDColour.setEnabled(false);\r
     abovePIDColour.setText("Above PID threshold only");\r
     abovePIDColour.addActionListener(new java.awt.event.ActionListener()\r
     {\r
@@ -246,8 +273,7 @@ public class PopupMenu extends JPopupMenu
         userDefinedColour_actionPerformed(e);\r
       }\r
     });\r
-    PIDColour.setEnabled(false);\r
-    PIDColour.setText("By PID");\r
+    PIDColour.setText("Percentage Identity");\r
     PIDColour.addActionListener(new java.awt.event.ActionListener()\r
     {\r
       public void actionPerformed(ActionEvent e)\r
@@ -255,7 +281,7 @@ public class PopupMenu extends JPopupMenu
         PIDColour_actionPerformed(e);\r
       }\r
     });\r
-    BLOSUM62Colour.setText("By BLOSUM62 score");\r
+    BLOSUM62Colour.setText("BLOSUM62 score");\r
     BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()\r
     {\r
       public void actionPerformed(ActionEvent e)\r
@@ -272,28 +298,20 @@ public class PopupMenu extends JPopupMenu
      }\r
    });\r
 \r
-    conservationColourIncMenuItem.setEnabled(false);\r
-    conservationColourIncMenuItem.setText("Conservation Colour Increment");\r
-    conservationColourIncMenuItem.addActionListener(new java.awt.event.ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        conservationColourIncMenuItem_actionPerformed(e);\r
-      }\r
-    });\r
 \r
 \r
   }\r
 \r
   void refresh()\r
   {\r
-    seqPanel.seqCanvas.paintFlag=true;\r
-    seqPanel.repaint();\r
+    ap.seqPanel.seqCanvas.paintFlag=true;\r
+    ap.seqPanel.repaint();\r
   }\r
 \r
   protected void clustalColour_actionPerformed(ActionEvent e)\r
   {\r
-\r
+    getGroup().cs = new ClustalxColourScheme();\r
+    refresh();\r
   }\r
 \r
   protected void zappoColour_actionPerformed(ActionEvent e)\r
@@ -340,10 +358,6 @@ public class PopupMenu extends JPopupMenu
   }\r
 \r
 \r
-  protected void conservationColourIncMenuItem_actionPerformed(ActionEvent e)\r
- {\r
-\r
-}\r
 /*\r
 public void conservationColourIncMenuItem_actionPerformed(ActionEvent e)\r
 {\r
@@ -358,6 +372,11 @@ frame.setMaximizable(false);
 \r
   protected void abovePIDColour_actionPerformed(ActionEvent e)\r
   {\r
+    SliderPanel sp = new SliderPanel(ap, 70, false, getGroup().cs );\r
+    JInternalFrame frame = new JInternalFrame();\r
+    frame.setContentPane(sp);\r
+    Desktop.addInternalFrame(frame, "Percentage Identity Threshold", 400,90);\r
+    frame.setMaximizable(false);\r
 \r
   }\r
 \r
@@ -365,7 +384,7 @@ frame.setMaximizable(false);
   protected void userDefinedColour_actionPerformed(ActionEvent e)\r
   {\r
     JInternalFrame frame = new JInternalFrame();\r
-    UserDefinedColours chooser = new UserDefinedColours( frame, seqPanel.parent, getGroup());\r
+    UserDefinedColours chooser = new UserDefinedColours( frame, ap, getGroup());\r
     frame.setContentPane(chooser);\r
     Desktop.addInternalFrame(frame,"User defined colours", 450,540 );\r
     frame.setResizable(false);\r
@@ -381,7 +400,7 @@ frame.setMaximizable(false);
 \r
   protected void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
   {\r
-    getGroup().cs = new Blosum62ColourScheme(av);\r
+    getGroup().cs = new Blosum62ColourScheme(ap.av);\r
     refresh();\r
   }\r
 \r
@@ -424,44 +443,10 @@ frame.setMaximizable(false);
     sg.setName(reply);\r
     groupName.setText(reply);\r
   }\r
-  /*  public void deleteSelectedMenuItem_actionPerformed(ActionEvent e)\r
-    {\r
-      addHistoryItem("delete selection");\r
-\r
-      for (int i=0;i < viewport.getSelection().size(); i++)\r
-              viewport.getAlignment().deleteSequence(viewport.getSelection().sequenceAt(i));\r
-\r
-      viewport.getSelection().clear();\r
-      viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight());\r
-      alignPanel.RefreshPanels();\r
-    }\r
-\r
-    public void moveSelectedMenuItem_actionPerformed(ActionEvent e)\r
-    {\r
-      copySelectedMenuItem_actionPerformed(null);\r
-      deleteSelectedMenuItem_actionPerformed(null);\r
-      alignPanel.repaint();\r
-    }\r
-\r
-    public void copySelectedMenuItem_actionPerformed(ActionEvent e)\r
-    {\r
-      if(viewport.getSelection().size()==0)\r
-        return;\r
 \r
-     SequenceI[] s = new Sequence[viewport.getSelection().size()];\r
-     for (int i=0; i < viewport.getSelection().size(); i++) {\r
-       s[i] = new Sequence(viewport.getSelection().sequenceAt(i));\r
-      }\r
-      AlignFrame af = new AlignFrame(new Alignment(s));\r
-      int newHeight = s.length * af.viewport.getCharHeight() + 200;\r
-      if(newHeight>500)\r
-        newHeight=500;\r
-      Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight);\r
-    }\r
-*/\r
   protected void copyGroup_actionPerformed(ActionEvent e)\r
   {\r
-    SequenceGroup sg = av.getRubberbandGroup();\r
+    SequenceGroup sg = ap.av.getRubberbandGroup();\r
 \r
     SequenceI[] s = new Sequence[sg.sequences.size()];\r
      for (int i=0; i < sg.sequences.size(); i++)\r
@@ -474,22 +459,43 @@ frame.setMaximizable(false);
      if (newHeight > 500)\r
        newHeight = 500;\r
      Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight);\r
-  }\r
+   }\r
 \r
   protected  void moveGroup_actionPerformed(ActionEvent e)\r
   {\r
+    SequenceGroup sg = ap.av.getRubberbandGroup();\r
+\r
+    SequenceI[] s = new Sequence[sg.sequences.size()];\r
+\r
+     for (int i=0; i < sg.sequences.size(); i++)\r
+       s[i] = new Sequence( sg.getSequenceAt(i));\r
+\r
+     AlignFrame af = new AlignFrame(new Alignment(s));\r
+     int newHeight = s.length * af.viewport.getCharHeight() + 200;\r
+     if(newHeight>500)\r
+       newHeight=500;\r
+     Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight);\r
+\r
+\r
+     for (int i=0; i < sg.sequences.size(); i++)\r
+       ap.av.alignment.deleteSequence(sg.getSequenceAt(i));\r
+\r
+\r
+     ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight());\r
+     ap.RefreshPanels();\r
+\r
 \r
   }\r
 \r
   protected void deleteSequences_actionPerformed(ActionEvent e)\r
   {\r
-    SequenceGroup sg = av.getRubberbandGroup();\r
+    SequenceGroup sg = ap.av.getRubberbandGroup();\r
     for (int i=0;i < sg.sequences.size(); i++)\r
-            av.getAlignment().deleteSequence(sg.getSequenceAt(i));\r
+            ap.av.getAlignment().deleteSequence(sg.getSequenceAt(i));\r
 \r
-    av.alignment.deleteGroup(sg);\r
-    av.resetSeqLimits(seqPanel.seqCanvas.getHeight());\r
-    seqPanel.parent.RefreshPanels();\r
+    ap.av.alignment.deleteGroup(sg);\r
+    ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight());\r
+    ap.seqPanel.parent.RefreshPanels();\r
 \r
   }\r
 \r
@@ -517,10 +523,30 @@ frame.setMaximizable(false);
 \r
   SequenceGroup getGroup()\r
   {\r
-    SequenceGroup sg = av.getRubberbandGroup();\r
+    SequenceGroup sg = ap.av.getRubberbandGroup();\r
 \r
     // this method won't add a new group if it already exists\r
-    av.alignment.addGroup(sg);\r
+    ap.av.alignment.addGroup(sg);\r
     return sg;\r
   }\r
+\r
+  void sequenceName_actionPerformed(ActionEvent e)\r
+  {\r
+    String id = sequence.getName();\r
+    String s = (String)JOptionPane.showInternalInputDialog(\r
+                ap,\r
+                "Edit sequence name",\r
+                "Edit sequence name",\r
+                JOptionPane.PLAIN_MESSAGE,\r
+                null,\r
+                null,\r
+                id);\r
+\r
+    if(s!=null)\r
+    {\r
+      sequence.setName(s);\r
+      ap.RefreshPanels();\r
+    }\r
+\r
+  }\r
 }\r