added URL display for parameters/options and debugged parameter set switching
authorjprocter <Jim Procter>
Tue, 31 Aug 2010 16:15:31 +0000 (16:15 +0000)
committerjprocter <Jim Procter>
Tue, 31 Aug 2010 16:15:31 +0000 (16:15 +0000)
src/jalview/gui/Desktop.java
src/jalview/gui/WsJobParameters.java

index bf0d052..53fa463 100755 (executable)
@@ -2175,4 +2175,29 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
   }
 
+  /**
+   * start a thread to open a URL in the configured browser. Pops up a warning dialog to the user if there is an exception when calling out to the browser to open the URL.
+   * @param url
+   */
+  public static void showUrl(final String url)
+  {
+    new Thread(new Runnable() {
+      public void run() {
+        try {
+          jalview.util.BrowserLauncher.openURL(url);
+        } catch (Exception ex)
+        {    
+          JOptionPane
+                  .showInternalMessageDialog(
+                          Desktop.desktop,
+                          "Unixers: Couldn't find default web browser."
+                                  + "\nAdd the full path to your browser in Preferences.",
+                          "Web browser not found", JOptionPane.WARNING_MESSAGE);
+
+          ex.printStackTrace();
+        }
+      }
+    }).start();    
+  }
+
 }
index 0e206b4..e7ecc03 100644 (file)
@@ -23,6 +23,7 @@ import java.awt.event.MouseListener;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
 import java.awt.event.WindowStateListener;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.EventObject;
 import java.util.HashSet;
@@ -35,12 +36,15 @@ import java.util.Vector;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
+import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JList;
+import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JSlider;
 import javax.swing.JSplitPane;
@@ -68,7 +72,9 @@ import compbio.metadata.ValueConstrain;
 import compbio.metadata.WrongParameterException;
 import compbio.metadata.ValueConstrain.Type;
 
+import jalview.util.jarInputStreamProvider;
 import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.ParameterUtils;
 import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
 
 /**
@@ -170,6 +176,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
 
   JDialog frame = null;
 
+  /**
+   * shows a modal dialog containing the parameters.
+   * 
+   * @return
+   */
   public boolean showRunDialog()
   {
 
@@ -178,9 +189,12 @@ public class WsJobParameters extends JPanel implements ItemListener,
     frame.setTitle("Edit parameters for " + service.getActionText());
     Rectangle deskr = Desktop.instance.getBounds();
     frame.setBounds(new Rectangle((int) (deskr.getCenterX() - 240),
-            (int) (deskr.getCenterY() - 92), 380, 385));
+            (int) (deskr.getCenterY() - 250), 480, 500));
     frame.setContentPane(this);
-
+    // should recover defaults from user prefs.
+    frame.validate();
+    settingsPanel.setDividerLocation(0.4);
+    jobPanel.setDividerLocation(0.3);
     frame.setVisible(true);
 
     if (response > 0)
@@ -290,7 +304,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
     setsavebuts.add(renmodified, BorderLayout.CENTER);
     setsavebuts.add(deletesetting, BorderLayout.CENTER);
     setsavebuts.add(savmodified, BorderLayout.EAST);
-    SetNamePanel.add(setsavebuts,BorderLayout.EAST);
+    SetNamePanel.add(setsavebuts, BorderLayout.EAST);
     setDetails.add(setDescrView, BorderLayout.CENTER);
     // setDetails.setPreferredSize(new Dimension(360, 100));
     jobParameters.setBorder(new TitledBorder("Parameters"));
@@ -309,7 +323,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
     settingsPanel.setLeftComponent(jobOptionsPanel);
     settingsPanel.setRightComponent(jobParameters);
     settingsPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
-    settingsPanel.setDividerLocation(0.4);
 
     setLayout(new BorderLayout());
     // setPreferredSize(new Dimension(400, 600));
@@ -317,7 +330,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
     jobPanel.setLeftComponent(setDetails);
     jobPanel.setRightComponent(settingsPanel);
     jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
-    jobPanel.setDividerLocation(0.8);
     add(SetNamePanel, BorderLayout.NORTH);
     add(jobPanel, BorderLayout.CENTER);
     JPanel dialogpanel = new JPanel();
@@ -335,40 +347,42 @@ public class WsJobParameters extends JPanel implements ItemListener,
   protected void deleteSetting_actionPerformed(ActionEvent e)
   {
     String setname = (String) setName.getSelectedItem();
-    int p=setName.getSelectedIndex();
-    if (_getUserPreset(setname)!=null)
+    int p = setName.getSelectedIndex();
+    if (_getUserPreset(setname) != null)
     {
       _deleteUserPreset(setname);
-      
+
     }
-    if (p>0 && p+1==setName.getItemCount())
+    if (p > 0 && p + 1 == setName.getItemCount())
     {
       p--;
     }
     setName.setSelectedIndex(p);
-    
+
   }
 
   protected void renModified_actionPerformed(ActionEvent e)
   {
-    if (curSetName==null || _getUserPreset(lastSetName)==null) {
-      System.err.println("can't rename - names unchanged or original name not a preset.");
+    if (curSetName == null || _getUserPreset(lastSetName) == null)
+    {
+      System.err
+              .println("can't rename - names unchanged or original name not a preset.");
       return;
     }
     _deleteUserPreset(lastSetName);
-    lastSetName=curSetName;
+    lastSetName = curSetName;
     savModified_actionPerformed(e);
-    curSetName=null;
+    curSetName = null;
     boolean setd = settingDialog;
-    settingDialog=true;
+    settingDialog = true;
     syncSetNamesWithStore();
-    settingDialog=setd;
+    settingDialog = setd;
   }
 
   protected void savModified_actionPerformed(ActionEvent e)
   {
     _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams());
-    curSetName=null;
+    curSetName = null;
     initArgSetModified(); // reset the modification state
   }
 
@@ -525,8 +539,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
         {
           if (arg instanceof Option)
           {
-            System.out.println("Setting option " + arg.getName() + " with "
-                    + arg.getDefaultValue());
+//            System.out.println("Setting option "
+//                    + System.identityHashCode(arg) + ":" + arg.getName()
+//                    + " with " + arg.getDefaultValue());
             selectOption((Option) arg, arg.getDefaultValue());
           }
         }
@@ -629,7 +644,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
     if (isServicePreset(nm))
     {
       nm = "User " + nm;
+      String tnm=nm;
       renamed = true;
+      int i=0;
+      while (_getUserPreset(tnm)!=null)
+      {
+        tnm = nm+" ("+(++i)+")";
+      }
+      if (i>0)
+      {
+        nm = tnm;
+      }
     }
     // if ()
     // if nm exists in user's preset store then savmodified will update an
@@ -722,7 +747,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
   Map<String, ParamBox> paramSet = new Hashtable<String, ParamBox>();
 
   public class ParamBox extends JPanel implements ChangeListener,
-          ActionListener
+          ActionListener, MouseListener
   {
     JButton showDesc = new JButton();
 
@@ -748,6 +773,8 @@ public class WsJobParameters extends JPanel implements ItemListener,
 
     final WsJobParameters pmdialogbox;
 
+    final URL finfo;
+
     public ParamBox(final WsJobParameters pmlayout, Parameter parm)
     {
       pmdialogbox = pmlayout;
@@ -766,6 +793,16 @@ public class WsJobParameters extends JPanel implements ItemListener,
       // string.setMinimumSize(new Dimension(140,80));
       // string.setMaximumSize(new Dimension(280,80));
       final ParamBox me = this;
+      finfo = parm.getFurtherDetails();
+      if (finfo != null)
+      {
+        showDesc.setToolTipText("<html><p>Click to show brief description, and right click to open link for further information.</p></html>");
+        showDesc.addMouseListener(this);
+      }
+      else
+      {
+        showDesc.setToolTipText("<html><p>Click to show brief description.</p></html>");
+      }
       showDesc.addActionListener(new ActionListener()
       {
 
@@ -889,22 +926,23 @@ public class WsJobParameters extends JPanel implements ItemListener,
 
     public Parameter getParameter()
     {
+      Parameter prm = ParameterUtils.copyParameter(parameter);
       try
       {
         if (choice)
         {
-          parameter.setDefaultValue((String) choicebox.getSelectedItem());
+          prm.setDefaultValue((String) choicebox.getSelectedItem());
         }
         else
         {
-          parameter.setDefaultValue(valueField.getText());
+          prm.setDefaultValue(valueField.getText());
         }
       } catch (WrongParameterException e)
       {
         e.printStackTrace();
         return null;
       }
-      return parameter;
+      return prm;
     }
 
     public Object updateSliderFromValueField()
@@ -1024,16 +1062,58 @@ public class WsJobParameters extends JPanel implements ItemListener,
       }
       pmdialogbox.argSetModified(this, !notmod);
     }
+
+    public void mouseClicked(MouseEvent e)
+    {
+      if (javax.swing.SwingUtilities.isRightMouseButton(e))
+      {
+        Desktop.showUrl(finfo.toString());
+      }
+    }
+
+    public void mousePressed(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseReleased(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseEntered(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseExited(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
   }
 
   Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
 
-  public class OptionBox extends JPanel implements ActionListener
+  public class OptionBox extends JPanel implements MouseListener,
+          ActionListener
   {
     JComboBox val = new JComboBox();
 
     JCheckBox enabled = new JCheckBox();
 
+    JLabel optlabel = new JLabel();
+
+    URL linkImageURL = getClass().getResource("/images/link.gif");
+
+    final URL finfo;
+
+    boolean hasLink = false;
+
     Option option;
 
     public OptionBox(Option opt)
@@ -1042,9 +1122,24 @@ public class WsJobParameters extends JPanel implements ItemListener,
       setLayout(new BorderLayout());
       enabled.setSelected(opt.isRequired()); // TODO: lock required options
       enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
+      enabled.setText("");
       enabled.setText(opt.getName());
-      enabled.setToolTipText(opt.getDescription());
       enabled.addActionListener(this);
+      finfo = option.getFurtherDetails();
+      if (finfo != null)
+      {
+        hasLink = true;
+        // optlabel.setToolTipText("<html><p>"+opt.getDescription()+"</p><img src=\""+linkImageURL+"\"/></html>");
+        enabled.setToolTipText("<html><p>" + opt.getDescription()
+                + "</p><img src=\"" + linkImageURL + "\"/></html>");
+        // optlabel.addMouseListener(this);
+        enabled.addMouseListener(this);
+      }
+      else
+      {
+        // optlabel.setToolTipText(opt.getDescription());
+        enabled.setToolTipText(opt.getDescription());
+      }
       add(enabled, BorderLayout.NORTH);
       if (opt.getPossibleValues().size() > 1)
       {
@@ -1099,9 +1194,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
       }
       try
       {
+        Option opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
+
         if (val.getSelectedItem() != null)
         {
-          option.setDefaultValue((String) val.getSelectedItem());
+          opt.setDefaultValue((String) val.getSelectedItem());
         }
       } catch (WrongParameterException e)
       {
@@ -1129,6 +1226,39 @@ public class WsJobParameters extends JPanel implements ItemListener,
       }
       argSetModified(this, !notmod);
     }
+
+    public void mouseClicked(MouseEvent e)
+    {
+      if (javax.swing.SwingUtilities.isRightMouseButton(e))
+      {
+        showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
+      }
+    }
+
+    public void mousePressed(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseReleased(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseEntered(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    public void mouseExited(MouseEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
   }
 
   private OptionBox addOption(Option opt)
@@ -1143,6 +1273,26 @@ public class WsJobParameters extends JPanel implements ItemListener,
     return cb;
   }
 
+  public static void showUrlPopUp(JComponent invoker, final String finfo,
+          int x, int y)
+  {
+
+    JPopupMenu mnu = new JPopupMenu();
+    JMenuItem mitem = new JMenuItem("View " + finfo);
+    mitem.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        Desktop.showUrl(finfo);
+
+      }
+    });
+    mnu.add(mitem);
+    mnu.show(invoker, x, y);
+  }
+
   protected void refreshParamLayout()
   {
     int s = 100;
@@ -1184,104 +1334,149 @@ public class WsJobParameters extends JPanel implements ItemListener,
     for (Jws2Discoverer.Jws2Instance service : disc.getServices())
     {
       lastserv = service;
-      if (p < args.length && service.serviceType.equalsIgnoreCase(args[p]))
+      if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
       {
-        break;
-      }
-    }
-    if (lastserv != null)
-    {
-      List<Preset> prl = null;
-      Preset pr = null;
-      if (++p < args.length)
-      {
-        PresetManager prman = lastserv.getPresets();
-        if (prman != null)
+        if (lastserv != null)
         {
-          pr = prman.getPresetByName(args[p]);
-          if (pr == null)
+          List<Preset> prl = null;
+          Preset pr = null;
+          if (++p < args.length)
           {
-            // just grab the last preset.
-            prl = prman.getPresets();
+            PresetManager prman = lastserv.getPresets();
+            if (prman != null)
+            {
+              pr = prman.getPresetByName(args[p]);
+              if (pr == null)
+              {
+                // just grab the last preset.
+                prl = prman.getPresets();
+              }
+            }
+          } else {
+            PresetManager prman = lastserv.getPresets();
+            if (prman!=null) {
+              prl = prman.getPresets();
+            }
           }
-        }
-      }
-      Iterator<Preset> en = (prl == null) ? null : prl.iterator();
-      while (true)
-      {
-        if (en != null)
-        {
-          if (!en.hasNext())
+          Iterator<Preset> en = (prl == null) ? null : prl.iterator();
+          while (en!=null && en.hasNext())
           {
-            en = prl.iterator();
-          }
-          pr = en.next();
-        }
-        WsJobParameters pgui = new WsJobParameters(lastserv, pr);
-        JFrame jf = new JFrame("Parameters for " + lastserv.getActionText());
-        JPanel cont = new JPanel();
-        // jf.setPreferredSize(new Dimension(600, 800));
-        cont.add(pgui);
-        jf.add(cont);
-        final Thread thr = Thread.currentThread();
-        jf.addWindowListener(new WindowListener()
-        {
+            if (en != null)
+            {
+              if (!en.hasNext())
+              {
+                en = prl.iterator();
+              }
+              pr = en.next();
+            }
+            {
+              System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
+              List<Option> rg = lastserv.getRunnerConfig().getOptions();
+              for (Option o : rg)
+              {
+                try
+                {
+                  Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
+                } catch (Exception e)
+                {
+                  System.err.println("Failed to copy " + o.getName());
+                  e.printStackTrace();
+                } catch (Error e)
+                {
+                  System.err.println("Failed to copy " + o.getName());
+                  e.printStackTrace();
+                }
+              }
+            }
+            {
+              System.out.println("Testing param dupes:");
+              List<Parameter> rg = lastserv.getRunnerConfig()
+                      .getParameters();
+              for (Parameter o : rg)
+              {
+                try
+                {
+                  Parameter cpy = jalview.ws.jws2.ParameterUtils
+                          .copyParameter(o);
+                } catch (Exception e)
+                {
+                  System.err.println("Failed to copy " + o.getName());
+                  e.printStackTrace();
+                } catch (Error e)
+                {
+                  System.err.println("Failed to copy " + o.getName());
+                  e.printStackTrace();
+                }
+              }
+            }
+            WsJobParameters pgui = new WsJobParameters(lastserv, pr);
+            JFrame jf = new JFrame("Parameters for "
+                    + lastserv.getActionText());
+            JPanel cont = new JPanel();
+            // jf.setPreferredSize(new Dimension(600, 800));
+            cont.add(pgui);
+            jf.add(cont);
+            final Thread thr = Thread.currentThread();
+            jf.addWindowListener(new WindowListener()
+            {
 
-          public void windowActivated(WindowEvent e)
-          {
-            // TODO Auto-generated method stub
+              public void windowActivated(WindowEvent e)
+              {
+                // TODO Auto-generated method stub
 
-          }
+              }
 
-          public void windowClosed(WindowEvent e)
-          {
-          }
+              public void windowClosed(WindowEvent e)
+              {
+              }
 
-          public void windowClosing(WindowEvent e)
-          {
-            thr.interrupt();
+              public void windowClosing(WindowEvent e)
+              {
+                thr.interrupt();
 
-          }
+              }
 
-          public void windowDeactivated(WindowEvent e)
-          {
-            // TODO Auto-generated method stub
+              public void windowDeactivated(WindowEvent e)
+              {
+                // TODO Auto-generated method stub
 
-          }
+              }
 
-          public void windowDeiconified(WindowEvent e)
-          {
-            // TODO Auto-generated method stub
+              public void windowDeiconified(WindowEvent e)
+              {
+                // TODO Auto-generated method stub
 
-          }
+              }
 
-          public void windowIconified(WindowEvent e)
-          {
-            // TODO Auto-generated method stub
+              public void windowIconified(WindowEvent e)
+              {
+                // TODO Auto-generated method stub
 
-          }
+              }
 
-          public void windowOpened(WindowEvent e)
-          {
-            // TODO Auto-generated method stub
+              public void windowOpened(WindowEvent e)
+              {
+                // TODO Auto-generated method stub
 
-          }
+              }
 
-        });
-        jf.setVisible(true);
-        boolean inter = false;
-        while (!inter)
-        {
-          try
-          {
-            Thread.sleep(10000);
-          } catch (Exception e)
-          {
-            inter = true;
+            });
+            jf.setVisible(true);
+            boolean inter = false;
+            while (!inter)
+            {
+              try
+              {
+                Thread.sleep(10000);
+              } catch (Exception e)
+              {
+                inter = true;
+              }
+              ;
+            }
+            jf.dispose();
           }
-          ;
         }
-        jf.dispose();
       }
     }
   }
@@ -1333,11 +1528,24 @@ public class WsJobParameters extends JPanel implements ItemListener,
     pset[0] = storeSetName;
     pset[1] = descr;
     pset[2] = jobParams;
+    //writeParam("Saving " + storeSetName + ": ", jobParams);
+  }
+
+  private void writeParam(String nm, List<Argument> params)
+  {
+    for (Argument p : params)
+    {
+      System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
+              + p.getName() + " Value: " + p.getDefaultValue());
+    }
   }
 
   private Object[] _getUserPreset(String setName)
   {
-    return editedParams.get(setName);
+    Object[] pset = editedParams.get(setName);
+    //if (pset != null)
+    //  writeParam("Retrieving " + setName + ": ", (List<Argument>) pset[2]);
+    return pset;
   }
 
   /**
@@ -1374,7 +1582,8 @@ public class WsJobParameters extends JPanel implements ItemListener,
   {
     settingDialog = true;
     syncSetNamesWithStore();
-    // updateTable(null,null);
+    // updateTable(null,null); // first reset to defaults
+
     Object[] pset = _getUserPreset(nextPreset);
     if (pset != null)
     {
@@ -1433,15 +1642,20 @@ public class WsJobParameters extends JPanel implements ItemListener,
       }
       if (curSetName == null || !setname.equals(curSetName))
       {
-        if (isModified()
-                && javax.swing.JOptionPane.showConfirmDialog(this,
-                        "Parameter set is modifed - save ?",
-                        "Save changes ?",
-                        javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+        settingDialog = true;
+        if (isModified())
         {
-          savModified_actionPerformed(null);
+          System.out.println("Prompting for "+setname);
+          if (javax.swing.JOptionPane.showConfirmDialog(this,
+                  "Parameter set is modifed - save ?", "Save changes ?",
+                  javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+          {
+            System.out.println("Saving for "+setname);
+            savModified_actionPerformed(null);
+          }
         }
         reInitDialog(setname);
+
       }
     }
   }
@@ -1465,9 +1679,12 @@ public class WsJobParameters extends JPanel implements ItemListener,
       {
         // rename any existing records we know about for this set.
         String newname = (String) e.getActionCommand();
-        String msg=null;
-        if (isServicePreset(newname)) {
-          JOptionPane.showConfirmDialog(this, "Invalid name - preset already exists.", "Invalid name", JOptionPane.OK_OPTION);
+        String msg = null;
+        if (isServicePreset(newname))
+        {
+          JOptionPane.showConfirmDialog(this,
+                  "Invalid name - preset already exists.", "Invalid name",
+                  JOptionPane.OK_OPTION);
           return;
         }
         curSetName = newname;