From: jprocter Date: Mon, 28 Jun 2010 13:56:13 +0000 (+0000) Subject: drop down selection of different parameter sets X-Git-Tag: Release_2_6~162 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6bfff068aa9c55e54222855df1b1039722660037;p=jalview.git drop down selection of different parameter sets --- diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 36266d1..89028ef 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -14,6 +14,8 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; @@ -66,9 +68,12 @@ import compbio.metadata.ValueConstrain.Type; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; -public class WsJobParameters extends JPanel +public class WsJobParameters extends JPanel implements ItemListener, + ActionListener { - private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 120; + private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,PARAM_CLOSEDHEIGHT=80; + + private static final int OPTSET_HEIGHT = 30; JPanel setDetails = new JPanel(); @@ -76,13 +81,18 @@ public class WsJobParameters extends JPanel JPanel jobOptions = new JPanel(); + JScrollPane jobOptionsPane = new JScrollPane(); + JPanel jobParameters = new JPanel(); JPanel paramButtons = new JPanel(); JPanel paramPanel = new JPanel(); + JLabel modified = new JLabel(); + JButton startjob = new JButton(); + JButton canceljob = new JButton(); JButton exportParams = new JButton(); @@ -97,7 +107,7 @@ public class WsJobParameters extends JPanel JButton editParam = new JButton(); - JLabel setName = new JLabel(); + JComboBox setName = new JComboBox(); JTextArea setDescr = new JTextArea(); @@ -140,35 +150,38 @@ public class WsJobParameters extends JPanel // display in new JFrame attached to parent. validate(); } - int response=-1; - JDialog frame=null; - public boolean showRunDialog() { - - frame = new JDialog( - Desktop.instance, true); - - frame.setTitle("Edit parameters for "+service.getActionText()); + + int response = -1; + + JDialog frame = null; + + public boolean showRunDialog() + { + + frame = new JDialog(Desktop.instance, true); + + 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)); frame.setContentPane(this); frame.setVisible(true); - - if (response>0) + + if (response > 0) { return true; } return false; } - + private void jbInit() { - modified.setText("Job Options Modified"); + modified.setText("*"); modified.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); modified.setForeground(Color.red); - modified.setHorizontalAlignment(SwingConstants.CENTER); - + modified.setHorizontalAlignment(SwingConstants.RIGHT); + exportParams.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); exportParams.setText("Export"); exportParams.setToolTipText("Export parameters to a file"); @@ -251,18 +264,26 @@ public class WsJobParameters extends JPanel }); setDetails.setBorder(new TitledBorder("Details")); - setDetails.setLayout(new GridLayout(2, 1)); + setDetails.setLayout(new BorderLayout()); setDescr.setColumns(40); setDescr.setWrapStyleWord(true); setDescr.setLineWrap(true); - setDescr.setPreferredSize(new Dimension(350, 90)); setDescr.setBackground(getBackground()); setDescr.setEditable(false); - setDetails.add(setName); - setDetails.add(setDescr); - setDetails.setPreferredSize(new Dimension(360, 100)); - settingsPanel.setLayout(new BorderLayout()); - jobOptions.setBorder(new TitledBorder("Options")); + JScrollPane setDescrView = new JScrollPane(); + // setDescrView.setPreferredSize(new Dimension(350, 200)); + setDescrView.getViewport().setView(setDescr); + setName.setEditable(true); + setName.addItemListener(this); + setName.getEditor().addActionListener(this); + modified.setPreferredSize(new Dimension(15, 15)); + JPanel SetNamePanel = new JPanel(); + SetNamePanel.setLayout(new BorderLayout()); + SetNamePanel.add(setName, BorderLayout.WEST); + SetNamePanel.add(modified, BorderLayout.EAST); + setDetails.add(SetNamePanel, BorderLayout.NORTH); + setDetails.add(setDescrView, BorderLayout.CENTER); + // setDetails.setPreferredSize(new Dimension(360, 100)); jobParameters.setBorder(new TitledBorder("Parameters")); jobParameters.setLayout(jparamLayout = new BorderLayout()); paramPane.setPreferredSize(new Dimension(360, 300)); @@ -278,11 +299,16 @@ public class WsJobParameters extends JPanel paramButtons.add(resetParams); paramPane.getViewport().setView(paramList); jobParameters.add(paramPane, BorderLayout.NORTH); - //jobParameters.add(paramButtons, BorderLayout.SOUTH); - settingsPanel.add(modified, BorderLayout.NORTH); - settingsPanel.add(jobOptions, BorderLayout.CENTER); + // jobParameters.add(paramButtons, BorderLayout.SOUTH); + settingsPanel.setLayout(new BorderLayout()); + // settingsPanel.add(modified, BorderLayout.NORTH); + JPanel jobOptionsPanel = new JPanel(); + jobOptionsPanel.setBorder(new TitledBorder("Options")); + jobOptionsPane.getViewport().setView(jobOptions); + jobOptionsPanel.add(jobOptionsPane); + settingsPanel.add(jobOptionsPanel, BorderLayout.NORTH); settingsPanel.add(jobParameters, BorderLayout.SOUTH); - + setLayout(new BorderLayout()); // setPreferredSize(new Dimension(400, 600)); // setSize(new Dimension(400, 600)); @@ -296,16 +322,18 @@ public class WsJobParameters extends JPanel protected void canceljob_actionPerformed(ActionEvent e) { - response=0; - if (frame!=null) { + response = 0; + if (frame != null) + { frame.setVisible(false); } } protected void startjob_actionPerformed(ActionEvent e) { - response=1; - if (frame!=null) { + response = 1; + if (frame != null) + { frame.setVisible(false); } } @@ -347,11 +375,29 @@ public class WsJobParameters extends JPanel } Jws2Instance service; + void initForService(Jws2Instance service, Preset p, List jobArgset) { - this.service=service; + this.service = service; serviceOptions = service.getRunnerConfig(); + // add any presets not already added. + String curname = (p == null ? "" : p.getName()); + PresetManager prman = service.getPresets(); + if (prman != null) + { + List prList = service.getPresets().getPresets(); + if (prList != null) + { + for (Object pr : prList) + { + if (p == null || !curname.equals(((Preset) pr).getName())) + { + setName.addItem(((Preset) pr).getName()); + } + } + } + } updateTable(p, jobArgset); } @@ -399,13 +445,16 @@ public class WsJobParameters extends JPanel } } } - args=null; // no more args to process. + args = null; // no more args to process. } if (p != null) { + if (lastParmSet == null) + { + // initialise setname + setName.addItem(p.getName()); + } setDescr.setText(p.getDescription()); - setName.setText(p.getName()); - setDetails.setVisible(true); // TODO - URL link try { @@ -414,10 +463,17 @@ public class WsJobParameters extends JPanel { e.printStackTrace(); } - // TODO: check if args should be unselected prior to resetting using the preset + // TODO: check if args should be unselected prior to resetting using the + // preset setargs.clear(); - } else { - setDetails.setVisible(false); + } + else + { + if (lastParmSet == null) + { + // first call - so create a dummy name + setName.addItem("Defaults *"); + } } if (jobArgset != null) { @@ -446,27 +502,39 @@ public class WsJobParameters extends JPanel // mdl.setData(setargs); // jobOptions.setLayout(new GridLayout(optSet.size() / 2 + 1, 2)); + jobOptions.setPreferredSize(new Dimension(PARAM_WIDTH, optSet.size() + * OPTSET_HEIGHT)); jobOptions.setLayout(new GridLayout(optSet.size(), 1)); + refreshParamLayout(); // paramPanel.setLayout(new GridLayout(paramSet.size(), 1)); // paramList.va // paramPane.getViewport().validate(); - paramList.setPreferredSize(new Dimension(350, paramSet.size() - * PARAM_HEIGHT)); - paramList.setLayout(new GridLayout(paramSet.size(), 1)); - paramList.validate(); paramPane.validate(); validate(); } + private boolean isModified() + { + return modified.isVisible(); + } + private void argSetModified(boolean b) { - modified.setVisible(b); - if (isVisible()) - { - validate(); - } - + /* + * String setn = (String)setName.getSelectedItem(); if (setn==null) return; + * int p = setName.getSelectedIndex(); if (b) { if (setn.length()<2 || + * setn.lastIndexOf(" *")!=setn.length()-2) { setn = setn+" *"; } } else { + * if (setn.lastIndexOf(" *")==setn.length()-2) { setn = + * setn.substring(0,setn.length()-2); } } // edit the list + * + * Object[] objects = new Object[setName.getItemCount()]; for (int + * i=0;i argSet = new ArrayList(); // recover options and parameters from GUI - for (OptionBox opts: optSet.values()) + for (OptionBox opts : optSet.values()) { Option opt = opts.getOptionIfEnabled(); - if (opt!=null) + if (opt != null) { argSet.add(opt); } } - for (ParamBox parambox: paramSet.values()) + for (ParamBox parambox : paramSet.values()) { Parameter parm = parambox.getParameter(); - if (parm!=null) + if (parm != null) { argSet.add(parm); } } - + return argSet; } + + String lastParmSet = null; + + Hashtable editedParams = new Hashtable(); + + @Override + public void itemStateChanged(ItemEvent e) + { + if (e.getSource() == setName) + { + String setname = (String) setName.getSelectedItem(); + if (setname == null) + { + return; + } + // if modified - warn user - or at least save current edited set. + if (lastParmSet != null) + { + // save current state + Object[] pset; + editedParams.put(lastParmSet, pset = new Object[3]); + pset[0] = lastParmSet; + pset[1] = setDescr.getText(); + pset[2] = getJobParams(); + } + Object[] pset = editedParams.get(setname); + if (pset != null) + { + setDescr.setText((String) pset[1]); + updateTable(null, (List) pset[2]); + lastParmSet = setname; + validate(); + } + else + { + // must be a default preset from service + Preset p = null; + try + { + p = service.getPresets().getPresetByName(setname); + } catch (Exception ex) + { + ex.printStackTrace(); + } + if (p != null) + { + updateTable(p, null); + validate(); + lastParmSet = setname; + } + } + + } + } + + @Override + public void actionPerformed(ActionEvent e) + { + if (e.getSource() == setName) + { + // rename any existing records we know about for this set. + String newname = (String) setName.getSelectedItem(); + System.err.println("Command " + newname + " : " + + e.getActionCommand()); + } + } }