From: jprocter Date: Thu, 2 Sep 2010 10:03:24 +0000 (+0000) Subject: re-implemented user prefs logic - still need to debug option change detection. X-Git-Tag: Release_2_6~78 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=665d91c5c801d65dd514b893543ac3a0c7642935;p=jalview.git re-implemented user prefs logic - still need to debug option change detection. --- diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index e7ecc037..c64dce0 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -118,13 +118,13 @@ public class WsJobParameters extends JPanel implements ItemListener, JPanel jobParameters = new JPanel(); - JButton savmodified = new JButton(); + JButton createpref = new JButton(); - JButton renmodified = new JButton(); + JButton deletepref = new JButton(); - JButton deletesetting = new JButton(); + JButton revertpref = new JButton(); - JButton revertsetting = new JButton(); + JButton updatepref = new JButton(); JButton startjob = new JButton(); @@ -219,43 +219,42 @@ public class WsJobParameters extends JPanel implements ItemListener, private void jbInit() { - savmodified = makeButton("Save", "Not implemented yet :) ", + updatepref = makeButton("Update", "Update the stored user preference", new ActionListener() { public void actionPerformed(ActionEvent e) { - savModified_actionPerformed(e); + update_actionPerformed(e); } }); - renmodified = makeButton("Rename", "Not implemented yet :) ", + deletepref = makeButton("Delete", "Delete the user preference", new ActionListener() { public void actionPerformed(ActionEvent e) { - renModified_actionPerformed(e); + delete_actionPerformed(e); } }); - deletesetting = makeButton("Delete", "Not implemented yet :) ", + createpref = makeButton("Create", "Create a new preference", new ActionListener() { public void actionPerformed(ActionEvent e) { - deleteSetting_actionPerformed(e); + create_actionPerformed(e); } }); - revertsetting = makeButton("Revert", "Undo changes to parameters.", - new ActionListener() + revertpref = makeButton("Revert", + "Undo all changes to the current set", new ActionListener() { public void actionPerformed(ActionEvent e) { - revertSetting_actionPerformed(e); + revert_actionPerformed(e); } }); - startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); startjob.setText("Start"); startjob.setToolTipText("Start Job"); @@ -292,18 +291,20 @@ public class WsJobParameters extends JPanel implements ItemListener, setName.addItemListener(this); setName.getEditor().addActionListener(this); SetNamePanel.setLayout(new BorderLayout()); + SetNamePanel.setMinimumSize(new Dimension(300, 35)); SetNamePanel.add(setName, BorderLayout.WEST); // initial button visibility - deletesetting.setVisible(false); - revertsetting.setVisible(false); - renmodified.setVisible(false); - savmodified.setVisible(false); + updatepref.setVisible(false); + deletepref.setVisible(false); + revertpref.setVisible(false); + createpref.setVisible(false); JPanel setsavebuts = new JPanel(); + setsavebuts.setMinimumSize(new Dimension(150, 35)); setsavebuts.setLayout(new FlowLayout()); - setsavebuts.add(revertsetting, BorderLayout.CENTER); - setsavebuts.add(renmodified, BorderLayout.CENTER); - setsavebuts.add(deletesetting, BorderLayout.CENTER); - setsavebuts.add(savmodified, BorderLayout.EAST); + setsavebuts.add(createpref, BorderLayout.CENTER); + setsavebuts.add(updatepref, BorderLayout.CENTER); + setsavebuts.add(revertpref, BorderLayout.EAST); + setsavebuts.add(deletepref, BorderLayout.EAST); SetNamePanel.add(setsavebuts, BorderLayout.EAST); setDetails.add(setDescrView, BorderLayout.CENTER); // setDetails.setPreferredSize(new Dimension(360, 100)); @@ -338,52 +339,53 @@ public class WsJobParameters extends JPanel implements ItemListener, add(dialogpanel, BorderLayout.SOUTH); } - protected void revertSetting_actionPerformed(ActionEvent e) + protected void revert_actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub + reInitDialog(lastParmSet); } - protected void deleteSetting_actionPerformed(ActionEvent e) + protected void update_actionPerformed(ActionEvent e) { - String setname = (String) setName.getSelectedItem(); - int p = setName.getSelectedIndex(); - if (_getUserPreset(setname) != null) + if (isUserPreset) { - _deleteUserPreset(setname); - - } - if (p > 0 && p + 1 == setName.getItemCount()) - { - p--; + String curname = ((String) setName.getSelectedItem()).trim(); + if (curname.length() > 0 && !curname.equals(lastParmSet)) + { + _deleteUserPreset(lastParmSet); + } + _storeCurrentPreset(curname); + lastParmSet = curname; + isUserPreset = true; + initArgSetModified(); } - setName.setSelectedIndex(p); - } - protected void renModified_actionPerformed(ActionEvent e) + protected void delete_actionPerformed(ActionEvent e) { - if (curSetName == null || _getUserPreset(lastSetName) == null) + if (isUserPreset) { - System.err - .println("can't rename - names unchanged or original name not a preset."); - return; + // delete current preset's saved entry + _deleteUserPreset(lastParmSet); } - _deleteUserPreset(lastSetName); - lastSetName = curSetName; - savModified_actionPerformed(e); - curSetName = null; - boolean setd = settingDialog; - settingDialog = true; - syncSetNamesWithStore(); - settingDialog = setd; + reInitDialog(null); // service default } - protected void savModified_actionPerformed(ActionEvent e) + protected void create_actionPerformed(ActionEvent e) { - _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams()); - curSetName = null; - initArgSetModified(); // reset the modification state + String curname = ((String) setName.getSelectedItem()).trim(); + if (curname.length() > 0) + { + _storeCurrentPreset(curname); + lastParmSet = curname; + isUserPreset = true; + initArgSetModified(); + } + else + { + // TODO: show warning + System.err.println("Invalid name. Not saved."); + } } protected void canceljob_actionPerformed(ActionEvent e) @@ -455,8 +457,27 @@ public class WsJobParameters extends JPanel implements ItemListener, } } } - updateTable(p, jobArgset); - initArgSetModified(); + // TODO: if initial jobArgset matches a given user setting or preset then + // should recover setting accordingly + // updateTable(p, jobArgset); + if (p != null) + { + reInitDialog(p.getName()); + initArgSetModified(); + } + else + { + if (jobArgset != null && jobArgset.size() > 0) + { + curSetName = "Supplied Settings"; + updateTable(p, jobArgset); + } + else + { + curSetName = null; + reInitDialog(null); + } + } settingDialog = false; } @@ -497,6 +518,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } if (p != null) { + isUserPreset = false; // initialise setname setName.setSelectedItem(lastSetName = p.getName()); setDescr.setText(lastDescrText = p.getDescription()); @@ -516,6 +538,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { if (lastParmSet == null) { + isUserPreset = false; // first call - so create a dummy name setName.setSelectedItem(lastSetName = SVC_DEF); } @@ -539,9 +562,9 @@ public class WsJobParameters extends JPanel implements ItemListener, { if (arg instanceof Option) { -// System.out.println("Setting option " -// + System.identityHashCode(arg) + ":" + arg.getName() -// + " with " + arg.getDefaultValue()); + // System.out.println("Setting option " + // + System.identityHashCode(arg) + ":" + arg.getName() + // + " with " + arg.getDefaultValue()); selectOption((Option) arg, arg.getDefaultValue()); } } @@ -571,9 +594,35 @@ public class WsJobParameters extends JPanel implements ItemListener, { curSetName = null; modifiedElements.clear(); - renmodified.setVisible(false); - savmodified.setVisible(false); + updateButtonDisplay(); + } + + private void updateButtonDisplay() + { + boolean _update = false, _create = false, _delete = false, _revert = false; + if (modifiedElements.size() > 0) + { + // set modified + _revert = true; + _update = isUserPreset; // can only update user presets + if (!isUserPreset || modifiedElements.containsKey(setName)) + { + // name modified - can create new preset + _create = true; + } + } + else + { + // set unmodified + } + // can still delete a user preset + _delete = isUserPreset; + createpref.setVisible(_create); + updatepref.setVisible(_update); + deletepref.setVisible(_delete); + revertpref.setVisible(_revert); + validate(); } private void argSetModified(Object modifiedElement, boolean b) @@ -592,36 +641,11 @@ public class WsJobParameters extends JPanel implements ItemListener, modifiedElements.put(modifiedElement, modifiedElement); } // set mod status based on presence of elements in table - if (modifiedElements.size() > 0) - { - makeSetNameValid(); - savmodified.setVisible(true); - revertsetting.setVisible(false); - } - else - { - revertsetting.setVisible(false); - deletesetting - .setVisible(!isServicePreset((String) setName - .getSelectedItem()) - && _getUserPreset((String) setName.getSelectedItem()) != null); - savmodified.setVisible(false); - } - // special reveal if setName has been modified - if (modifiedElements.get(setName) != null) - { - if (curSetName != null && lastSetName != null - && !lastSetName.equals(curSetName)) - { - renmodified.setVisible(!isServicePreset(lastSetName)); - } - } - else + if (b && modifiedElements.size() > 0) { - // setname isn't in modlist - so don't rename - renmodified.setVisible(false); + makeSetNameValid(!isUserPreset); } - validate(); + updateButtonDisplay(); } private boolean isServicePreset(String selectedItem) @@ -634,7 +658,7 @@ public class WsJobParameters extends JPanel implements ItemListener, * check if the current set name is a valid set name for saving, if not, then * fix it. */ - private void makeSetNameValid() + private void makeSetNameValid(boolean newuserset) { boolean stn = settingDialog; boolean renamed = false; @@ -644,22 +668,21 @@ 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) + } + String tnm = nm; + if (newuserset) + { + int i = 0; + while (_getUserPreset(tnm) != null) { - tnm = nm+" ("+(++i)+")"; + tnm = nm + " (" + (++i) + ")"; } - if (i>0) + if (i > 0) { nm = tnm; } } - // if () - // if nm exists in user's preset store then savmodified will update an - // existing user defined preset - // if nm doesn't exist, then the button will create a new preset. boolean makeupdate = false; // sync the gui with the preset database @@ -669,22 +692,12 @@ public class WsJobParameters extends JPanel implements ItemListener, if (snm.equals(nm)) { makeupdate = true; - setName.setSelectedIndex(i); + // setName.setSelectedIndex(i); } } - - if (_getUserPreset(nm) != null) - { - savmodified.setText("Update"); - } - else + if (!makeupdate) { - if (renamed) - { - setName.addItem(nm); - setName.setSelectedIndex(setName.getItemCount() - 1); - } - savmodified.setText("Save"); + setName.setSelectedItem(curSetName = nm); } settingDialog = stn; } @@ -1182,7 +1195,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } else { - initVal = null; + initVal = (initEnabled) ? option.getDefaultValue() : null; } } @@ -1220,9 +1233,18 @@ public class WsJobParameters extends JPanel implements ItemListener, private void checkIfModified() { boolean notmod = (initEnabled == enabled.isSelected()); - if (enabled.isSelected() && initVal != null) + if (enabled.isSelected()) + { + if (initVal != null) + { + notmod |= initVal.equals(val.getSelectedItem()); + } else { + notmod |= false; + } + } + else { - notmod |= initVal.equals(val.getSelectedItem()); + notmod |= initVal == null; } argSetModified(this, !notmod); } @@ -1352,14 +1374,17 @@ public class WsJobParameters extends JPanel implements ItemListener, prl = prman.getPresets(); } } - } else { + } + else + { PresetManager prman = lastserv.getPresets(); - if (prman!=null) { + if (prman != null) + { prl = prman.getPresets(); } } Iterator en = (prl == null) ? null : prl.iterator(); - while (en!=null && en.hasNext()) + while (en != null && en.hasNext()) { if (en != null) { @@ -1370,7 +1395,9 @@ public class WsJobParameters extends JPanel implements ItemListener, pr = en.next(); } { - System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName()); + System.out.println("Testing opts dupes for " + + lastserv.getHost() + " : " + + lastserv.getActionText() + ":" + pr.getName()); List