JAL-1384 Create Group in selection popup menu
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Tue, 8 Oct 2013 13:51:01 +0000 (14:51 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Tue, 8 Oct 2013 13:51:01 +0000 (14:51 +0100)
JAL-1388 move Remove Group option to selection menu
JAL-1388 Group editing menu is now context dependent (either 'Edit Group' or 'Edit New Group')

src/jalview/appletgui/APopupMenu.java
src/jalview/gui/PopupMenu.java

index 70804f6..8302282 100755 (executable)
@@ -69,6 +69,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
 
   MenuItem unGroupMenuItem = new MenuItem();
 
+  MenuItem createGroupMenuItem = new MenuItem();
+
   MenuItem nucleotideMenuItem = new MenuItem();
 
   Menu colourMenu = new Menu();
@@ -166,7 +168,11 @@ public class APopupMenu extends java.awt.PopupMenu implements
       displayNonconserved.setState(sg.getShowNonconserved());
       if (!ap.av.getAlignment().getGroups().contains(sg))
       {
-        menu1.remove(unGroupMenuItem);
+        menu1.setLabel("Edit New Group");
+        groupMenu.remove(unGroupMenuItem);
+      } else {
+        menu1.setLabel("Edit Group");
+        groupMenu.remove(createGroupMenuItem);
       }
 
     }
@@ -457,6 +463,11 @@ public class APopupMenu extends java.awt.PopupMenu implements
       unGroupMenuItem_actionPerformed();
     }
 
+    else if (source == createGroupMenuItem)
+    {
+      createGroupMenuItem_actionPerformed();
+    }
+
     else if (source == sequenceName)
     {
       editName();
@@ -730,7 +741,6 @@ public class APopupMenu extends java.awt.PopupMenu implements
 
   private void jbInit() throws Exception
   {
-    groupMenu.setLabel("Group");
     groupMenu.setLabel("Selection");
     sequenceFeature.addActionListener(this);
 
@@ -738,6 +748,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
     unGroupMenuItem.setLabel("Remove Group");
     unGroupMenuItem.addActionListener(this);
 
+    createGroupMenuItem.setLabel("Create Group");
+    createGroupMenuItem.addActionListener(this);
+    
     nucleotideMenuItem.setLabel("Nucleotide");
     nucleotideMenuItem.addActionListener(this);
     conservationMenuItem.addItemListener(this);
@@ -770,10 +783,11 @@ public class APopupMenu extends java.awt.PopupMenu implements
     this.add(revealSeq);
     this.add(revealAll);
     // groupMenu.add(selSeqDetails);
-    groupMenu.add(editGroupName);
     groupMenu.add(editMenu);
     groupMenu.add(outputmenu);
     groupMenu.add(sequenceFeature);
+    groupMenu.add(createGroupMenuItem);
+    groupMenu.add(unGroupMenuItem);
     groupMenu.add(menu1);
 
     colourMenu.add(noColourmenuItem);
@@ -843,7 +857,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
       seqMenu.add(pdb);
     }
     seqMenu.add(repGroup);
-    menu1.add(unGroupMenuItem);
+    menu1.add(editGroupName);
     menu1.add(colourMenu);
     menu1.add(showBoxes);
     menu1.add(showText);
@@ -1027,6 +1041,12 @@ public class APopupMenu extends java.awt.PopupMenu implements
     ap.paintAlignment(true);
   }
 
+  void createGroupMenuItem_actionPerformed()
+  {
+    getGroup(); // implicitly create group
+    refresh();
+  }
+
   public void showColourText_itemStateChanged()
   {
     getGroup().setColourText(showColourText.getState());
index 1a367c5..29370ac 100644 (file)
@@ -89,7 +89,7 @@ public class PopupMenu extends JPopupMenu
   JMenuItem sequenceSelDetails = new JMenuItem();
 
   SequenceI sequence;
-
+  JMenuItem createGroupMenuItem = new JMenuItem();
   JMenuItem unGroupMenuItem = new JMenuItem();
 
   JMenuItem outline = new JMenuItem();
@@ -392,9 +392,10 @@ public class PopupMenu extends JPopupMenu
     }
 
     SequenceGroup sg = ap.av.getSelectionGroup();
+    boolean isDefinedGroup = (sg!=null) ? ap.av.getAlignment().getGroups().contains(sg) : false;
 
     if (sg != null && sg.getSize() > 0)
-    {
+    {      
       groupName.setText("Name: " + sg.getName());
       groupName.setText("Edit name and description of current group.");
 
@@ -520,9 +521,15 @@ public class PopupMenu extends JPopupMenu
       editMenu.setVisible(false);
     }
 
-    if (!ap.av.getAlignment().getGroups().contains(sg))
+    if (!isDefinedGroup)
     {
+      createGroupMenuItem.setVisible(true);
       unGroupMenuItem.setVisible(false);
+      jMenu1.setText("Edit New Group");
+    } else {
+      createGroupMenuItem.setVisible(false);
+      unGroupMenuItem.setVisible(true);
+      jMenu1.setText("Edit Group");
     }
 
     if (seq == null)
@@ -935,6 +942,14 @@ public class PopupMenu extends JPopupMenu
         unGroupMenuItem_actionPerformed();
       }
     });
+    createGroupMenuItem.setText("Create Group");
+    createGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        createGroupMenuItem_actionPerformed();
+      }
+    });
 
     outline.setText("Border colour");
     outline.addActionListener(new java.awt.event.ActionListener()
@@ -1097,6 +1112,8 @@ public class PopupMenu extends JPopupMenu
     groupMenu.add(editMenu);
     groupMenu.add(outputMenu);
     groupMenu.add(sequenceFeature);
+    groupMenu.add(createGroupMenuItem);
+    groupMenu.add(unGroupMenuItem);
     groupMenu.add(jMenu1);
     sequenceMenu.add(sequenceName);
     sequenceMenu.add(sequenceDetails);
@@ -1153,7 +1170,6 @@ public class PopupMenu extends JPopupMenu
     pdbMenu.add(enterPDB);
     pdbMenu.add(discoverPDB);
     jMenu1.add(groupName);
-    jMenu1.add(unGroupMenuItem);
     jMenu1.add(colourMenu);
     jMenu1.add(showBoxes);
     jMenu1.add(showText);
@@ -1726,6 +1742,11 @@ public class PopupMenu extends JPopupMenu
     ap.av.setSelectionGroup(null);
     refresh();
   }
+  void createGroupMenuItem_actionPerformed()
+  {
+    getGroup(); // implicitly creates group - note - should apply defaults / use standard alignment window logic for this
+    refresh();
+  }
 
   /**
    * DOCUMENT ME!