more efficient group URL generation.
authorjprocter <Jim Procter>
Fri, 26 Mar 2010 12:18:16 +0000 (12:18 +0000)
committerjprocter <Jim Procter>
Fri, 26 Mar 2010 12:18:16 +0000 (12:18 +0000)
src/jalview/gui/PopupMenu.java

index 457638a..341aac2 100755 (executable)
@@ -632,13 +632,14 @@ public class PopupMenu extends JPopupMenu
         }
         // and try and make the groupURL!
         
-        Object[] urlset = urlLink.makeUrls(ids,seqstr, "FromJalview"+System.currentTimeMillis(),false);
+        Object[] urlset = urlLink.makeUrlStubs(ids,seqstr, "FromJalview"+System.currentTimeMillis(),false);
         if (urlset!=null)
         {
-          System.out.println(urlLink.getGroupURLType() +" "+((String[])urlset[3])[0]);
+          int type = urlLink.getGroupURLType() & 3;
+          //System.out.println(urlLink.getGroupURLType() +" "+((String[])urlset[3])[0]);
           // first two bits ofurlLink type bitfield are sequenceids and sequences
           // TODO: FUTURE: ensure the groupURL menu structure can be generalised
-          addshowLink(linkMenus[urlLink.getGroupURLType() & 3], label + "("+(usingNames ? "Names" : ltarget)+")", ((String[])urlset[3])[0]);
+          addshowLink(linkMenus[type], label + (((type & 1)==1) ? ("("+(usingNames ? "Names" : ltarget)+")") : ""), urlLink, urlset);
           addMenu = true;
         }
       }
@@ -688,7 +689,37 @@ public class PopupMenu extends JPopupMenu
 
     linkMenu.add(item);
   }
+  /**
+   * add a late bound groupURL item to the given linkMenu
+   * 
+   * @param linkMenu
+   * @param label -
+   *                menu label string
+   * @param urlgenerator GroupURLLink used to generate URL  
+   * @param urlstub Object array returned from the makeUrlStubs function.
+   */
+  private void addshowLink(JMenu linkMenu, String label, final GroupUrlLink urlgenerator, final Object[] urlstub)
+  {
+    JMenuItem item = new JMenuItem(label);
+    item.setToolTipText("open URL ("+urlgenerator.getUrl_prefix()+"..) ("+urlgenerator.getNumberInvolved(urlstub)+" seqs)"); // TODO: put in info about what is being sent.
+    item.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        new Thread(new Runnable()
+        {
 
+          public void run()
+          {
+            showLink(urlgenerator.constructFrom(urlstub));
+          }
+
+        }).start();
+      }
+    });
+
+    linkMenu.add(item);
+  }
   /**
    * DOCUMENT ME!
    * 
@@ -1376,12 +1407,13 @@ public class PopupMenu extends JPopupMenu
 
     sg.setName(dialog.getName());
     sg.setDescription(dialog.getDescription());
+    refresh();
   }
 
   /**
-   * DOCUMENT ME!
+   * Get selection group - adding it to the alignment if necessary. 
    * 
-   * @return DOCUMENT ME!
+   * @return sequence group to operate on
    */
   SequenceGroup getGroup()
   {
@@ -1552,6 +1584,7 @@ public class PopupMenu extends JPopupMenu
     }
 
     ap.av.hideSequence(hseqs);
+    // refresh(); TODO: ? needed ?
     ap.av.sendSelection();
   }