From 842559f239380e94327db76808eef6c4b28fdd89 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 31 Aug 2010 16:15:31 +0000 Subject: [PATCH] added URL display for parameters/options and debugged parameter set switching --- src/jalview/gui/Desktop.java | 25 ++ src/jalview/gui/WsJobParameters.java | 445 +++++++++++++++++++++++++--------- 2 files changed, 356 insertions(+), 114 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bf0d052f8..53fa463 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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(); + } + } diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 0e206b4..e7ecc037 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -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 paramSet = new Hashtable(); 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("

Click to show brief description, and right click to open link for further information.

"); + showDesc.addMouseListener(this); + } + else + { + showDesc.setToolTipText("

Click to show brief description.

"); + } 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 optSet = new Hashtable(); - 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("

"+opt.getDescription()+"

"); + enabled.setToolTipText("

" + opt.getDescription() + + "

"); + // 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 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 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 en = (prl == null) ? null : prl.iterator(); - while (true) - { - if (en != null) - { - if (!en.hasNext()) + Iterator 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