Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6720/src/java/org/neuclear/commons/crypto/passphraseagents/swing Modified Files: NewAliasDialog.java SimpleDialog.java SwingAgent.java Added Files: KeyStoreDialog.java WaitForInput.java Log Message: Now have a slightly better way of handling the waiting for input using the WaitForInput class. This will later be put into a command queue for execution. --- NEW FILE: KeyStoreDialog.java --- package org.neuclear.commons.crypto.passphraseagents.swing; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.plaf.Options; import org.neuclear.commons.crypto.signers.BrowsableSigner; import org.neuclear.commons.crypto.signers.InvalidPassphraseException; import org.neuclear.commons.crypto.signers.SetPublicKeyCallBack; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.net.URL; import java.security.KeyStoreException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Vector; /* $Id: KeyStoreDialog.java,v 1.1 2004/04/12 15:00:29 pelle Exp $ $Log: KeyStoreDialog.java,v $ Revision 1.1 2004/04/12 15:00:29 pelle Now have a slightly better way of handling the waiting for input using the WaitForInput class. This will later be put into a command queue for execution. Revision 1.2 2004/04/09 22:56:44 pelle SwingAgent now manages key creation as well through the NewAliasDialog. Many small uservalidation features have also been added. Revision 1.1 2004/04/07 17:22:08 pelle Added support for the new improved interactive signing model. A new Agent is also available with SwingAgent. The XMLSig classes have also been updated to support this. */ /** * User: pelleb * Date: Apr 7, 2004 * Time: 9:55:37 AM */ public class KeyStoreDialog { public KeyStoreDialog() { try { UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } cache = new HashMap(); sign = new JButton("Sign"); sign.setEnabled(false); cancel = new JButton("Cancel"); newId = new JButton("New ..."); list = new JList(new String[]{"bob", "carol", "alice"}); list.setBorder(BorderFactory.createLoweredBevelBorder()); passphrase = new JPasswordField(); final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); if (imageurl != null) icon = new JLabel(new ImageIcon(imageurl)); else icon = new JLabel("NeuClear"); dialog = new JDialog(); dialog.setTitle("NeuClear Signing Agent"); dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dialog.getContentPane().add(buildPanel()); dialog.pack(); nad = new NewAliasDialog(this); cancel.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (passphrase) { passphrase.setText(""); dialog.hide(); runner.cancel(); } } }); final ActionListener action = new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (passphrase) { if (validate()) { runner.execute(); } } } }; sign.addActionListener(action); passphrase.addActionListener(action); final KeyListener validate = new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { sign.setEnabled(validate()); } public void keyTyped(KeyEvent e) { } }; passphrase.addKeyListener(validate); list.addListSelectionListener(new ListSelectionListener() { /** * Called whenever the value of the selection changes. * * @param e the event that characterizes the change. */ public void valueChanged(ListSelectionEvent e) { sign.setEnabled(validate()); } }); newId.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { SwingUtilities.invokeLater(nad); } }); // dialog.show(); } void updateList(String alias) { if (alias != null) { fillAliasList(); list.setSelectedValue(alias, true); dialog.pack(); } } private Component buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", "pref,3dlu,pref, 3dlu, fill:pref:grow, 3dlu, pref, 7dlu, pref"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.setDefaultDialogBorder(); builder.add(icon, cc.xyw(1, 5, 1, CellConstraints.LEFT, CellConstraints.TOP)); builder.addSeparator("Identities", cc.xyw(1, 3, 3)); builder.add(list, cc.xyw(3, 5, 1)); builder.addLabel("Passphrase:", cc.xy(1, 7)); builder.add(passphrase, cc.xy(3, 7)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGridded(newId); bb.addGlue(); bb.addUnrelatedGap(); bb.addGridded(sign); bb.addGridded(cancel); builder.add(bb.getPanel(), cc.xyw(1, 9, 3)); return builder.getPanel(); } private void fillAliasList() { try { Iterator iter = signer.iterator(); Vector vector = new Vector(); while (iter.hasNext()) { Object o = iter.next(); vector.add(o); } list.setListData(vector); } catch (KeyStoreException e) { e.printStackTrace(); } } BrowsableSigner getSigner() { return signer; } JDialog getDialog() { return dialog; } private boolean validate() { return (list.getSelectedIndex() > 0 && passphrase.getPassword().length > 0); } WaitForInput createSigningTask(BrowsableSigner bs, byte data[], SetPublicKeyCallBack cb) { return new DialogRunner(bs, data, cb); } private BrowsableSigner signer; private final JButton sign; private final JButton cancel; private final JButton newId; private final JList list; private final JPasswordField passphrase; private final JDialog dialog; private final NewAliasDialog nad; private final Map cache; private final JLabel icon; private DialogRunner runner; class DialogRunner extends WaitForInput { public DialogRunner(BrowsableSigner bs, byte data[], SetPublicKeyCallBack cb) { this.data = data; this.cb = cb; this.bs = bs; } public void run() { runner = this; signer = bs; fillAliasList(); passphrase.setText(""); dialog.pack(); dialog.show(); sign.setEnabled(false); } public void execute() { dialog.hide(); char phrase[] = passphrase.getPassword(); passphrase.setText(""); try { //Todo handle when an alias hasnt been selected setResult(signer.sign(list.getSelectedValue().toString(), phrase, data, cb)); } catch (InvalidPassphraseException e) { run(); } } private final byte data[]; private final SetPublicKeyCallBack cb; private final BrowsableSigner bs; } } Index: SwingAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SwingAgent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SwingAgent.java 9 Apr 2004 22:56:44 -0000 1.2 --- SwingAgent.java 12 Apr 2004 15:00:29 -0000 1.3 *************** *** 1,8 **** package org.neuclear.commons.crypto.passphraseagents.swing; - import com.jgoodies.forms.builder.ButtonBarBuilder; - import com.jgoodies.forms.builder.PanelBuilder; - import com.jgoodies.forms.layout.CellConstraints; - import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.plaf.Options; import org.neuclear.commons.crypto.Base64; --- 1,4 ---- *************** *** 15,36 **** import javax.swing.*; - import javax.swing.event.ListSelectionEvent; - import javax.swing.event.ListSelectionListener; - import java.awt.*; - import java.awt.event.ActionEvent; - import java.awt.event.ActionListener; - import java.awt.event.KeyEvent; - import java.awt.event.KeyListener; - import java.net.URL; - import java.security.KeyStoreException; import java.security.PublicKey; import java.util.HashMap; - import java.util.Iterator; import java.util.Map; - import java.util.Vector; /* $Id$ $Log$ Revision 1.2 2004/04/09 22:56:44 pelle SwingAgent now manages key creation as well through the NewAliasDialog. --- 11,25 ---- import javax.swing.*; import java.security.PublicKey; import java.util.HashMap; import java.util.Map; /* $Id$ $Log$ + Revision 1.3 2004/04/12 15:00:29 pelle + Now have a slightly better way of handling the waiting for input using the WaitForInput class. + This will later be put into a command queue for execution. + Revision 1.2 2004/04/09 22:56:44 pelle SwingAgent now manages key creation as well through the NewAliasDialog. *************** *** 56,304 **** // Likely PlasticXP is not in the class path; ignore. } cache = new HashMap(); - sign = new JButton("Sign"); - sign.setEnabled(false); - cancel = new JButton("Cancel"); - newId = new JButton("New ..."); - list = new JList(new String[]{"bob", "carol", "alice"}); - list.setBorder(BorderFactory.createLoweredBevelBorder()); - passphrase = new JPasswordField(); - final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); - if (imageurl != null) - icon = new JLabel(new ImageIcon(imageurl)); - else - icon = new JLabel("NeuClear"); - - dialog = new JDialog(); - dialog.setTitle("NeuClear Signing Agent"); - dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - dialog.getContentPane().add(buildPanel()); - dialog.pack(); - nad = new NewAliasDialog(this); - - cancel.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent actionEvent) { - synchronized (passphrase) { - passphrase.setText(""); - isCancel = true; - passphrase.notifyAll(); - } - - } - }); - - final ActionListener action = new ActionListener() { - public void actionPerformed(final ActionEvent actionEvent) { - synchronized (passphrase) { - if (validate()) { - isCancel = false; - passphrase.notifyAll(); - } - } - - } - }; - sign.addActionListener(action); - passphrase.addActionListener(action); - final KeyListener validate = new KeyListener() { - public void keyPressed(KeyEvent e) { - - } - - public void keyReleased(KeyEvent e) { - sign.setEnabled(validate()); - - } - - public void keyTyped(KeyEvent e) { - - } - }; - passphrase.addKeyListener(validate); - list.addListSelectionListener(new ListSelectionListener() { - /** - * Called whenever the value of the selection changes. - * - * @param e the event that characterizes the change. - */ - public void valueChanged(ListSelectionEvent e) { - sign.setEnabled(validate()); - } - - }); - - newId.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent actionEvent) { - SwingUtilities.invokeLater(nad); - } - }); - - - // dialog.show(); - - - } - - void updateList(String alias) { - if (alias != null) { - fillAliasList(); - list.setSelectedValue(alias, true); - dialog.pack(); - } - } - - private Component buildPanel() { - FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", - "pref,3dlu,pref, 3dlu, fill:pref:grow, 3dlu, pref, 7dlu, pref"); - PanelBuilder builder = new PanelBuilder(layout); - CellConstraints cc = new CellConstraints(); - - builder.setDefaultDialogBorder(); - - builder.add(icon, cc.xyw(1, 5, 1, CellConstraints.LEFT, CellConstraints.TOP)); - builder.addSeparator("Identities", cc.xyw(1, 3, 3)); - builder.add(list, cc.xyw(3, 5, 1)); - builder.addLabel("Passphrase:", cc.xy(1, 7)); - builder.add(passphrase, cc.xy(3, 7)); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGridded(newId); - bb.addGlue(); - bb.addUnrelatedGap(); - bb.addGridded(sign); - bb.addGridded(cancel); - builder.add(bb.getPanel(), cc.xyw(1, 9, 3)); - - return builder.getPanel(); - } - - /** - * The User is asked to pick a name by the PassPhraseAgent. The PassPhraseAgent can query the given signer for - * a list of included aliases or even create a new keypair. - * - * @return - * @throws org.neuclear.commons.crypto.passphraseagents.UserCancellationException - * - */ - public byte[] sign(BrowsableSigner signer, byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { - synchronized (passphrase) {//We dont want multiple agents popping up at the same time - this.signer = signer; - fillAliasList(); - - // if (cache.containsKey(name)) - // passphrase.setText((String) cache.get(name)); - // else - passphrase.setText(""); - isCancel = true; - // if (incorrect) - // System.err.println("Incorrect passphrase"); - // incorrectLabel.setVisible(incorrect); - // nameLabel.setVisible(true); - // - // nameLabel.setText(name); - dialog.pack(); - dialog.show(); - sign.setEnabled(false); - // dialog.setVisible(true); - try { - passphrase.wait(); - } catch (InterruptedException e) { - ; - } - dialog.hide(); - // dialog.setVisible(false); - final String phrase = passphrase.getText(); - // if (remember.getState()) - // cache.put(name, phrase); - passphrase.setText(""); - try { - //Todo handle when an alias hasnt been selected - return signer.sign(list.getSelectedValue().toString(), phrase.toCharArray(), data, callback); - } catch (InvalidPassphraseException e) { - return sign(signer, data, callback); - } - } - } - - private void fillAliasList() { - try { - - Iterator iter = signer.iterator(); - Vector vector = new Vector(); - while (iter.hasNext()) { - Object o = iter.next(); - vector.add(o); - } - list.setListData(vector); - } catch (KeyStoreException e) { - e.printStackTrace(); - } - } - - /** - * Retrieve the PassPhrase for a given name/alias - * - * @param name - * @return - */ - public char[] getPassPhrase(String name) throws UserCancellationException { - - return getPassPhrase(name, false); - } - - public char[] getPassPhrase(String name, boolean incorrect) throws UserCancellationException { - synchronized (passphrase) {//We dont want multiple agents popping up at the same time - if (cache.containsKey(name)) - passphrase.setText((String) cache.get(name)); - else - passphrase.setText(""); - isCancel = true; - // if (incorrect) - // System.err.println("Incorrect passphrase"); - // incorrectLabel.setVisible(incorrect); - // nameLabel.setVisible(true); - // - // nameLabel.setText(name); - dialog.pack(); - dialog.setVisible(true); - try { - passphrase.wait(); - } catch (InterruptedException e) { - ; - } - dialog.setVisible(false); - if (isCancel) - throw new UserCancellationException(name); - final String phrase = passphrase.getText(); - // if (remember.getState()) - // cache.put(name, phrase); - passphrase.setText(""); - return phrase.toCharArray(); - } - } - - BrowsableSigner getSigner() { - return signer; - } - - JDialog getDialog() { - return dialog; - } - - private boolean validate() { - return (list.getSelectedIndex() > 0 && passphrase.getPassword().length > 0); } private BrowsableSigner signer; - private final JButton sign; - private final JButton cancel; - private final JButton newId; - private final JList list; - private final JPasswordField passphrase; - private final JDialog dialog; private final NewAliasDialog nad; private final Map cache; private boolean isCancel; - private final JLabel icon; public static void main(final String[] args) { --- 45,60 ---- // Likely PlasticXP is not in the class path; ignore. } + ksd = new KeyStoreDialog(); + simple = new SimpleDialog(); + nad = new NewAliasDialog(ksd); cache = new HashMap(); } private BrowsableSigner signer; private final NewAliasDialog nad; + private final SimpleDialog simple; + private final KeyStoreDialog ksd; private final Map cache; private boolean isCancel; public static void main(final String[] args) { *************** *** 327,330 **** --- 83,116 ---- } + /** + * Retrieve the PassPhrase for a given name/alias + * + * @param name + * @return + */ + public char[] getPassPhrase(String name) throws UserCancellationException { + return getPassPhrase(name, false); + } + + public char[] getPassPhrase(String name, boolean incorrect) throws UserCancellationException { + WaitForInput waiter = simple.createGetPassphraseTask(name, incorrect); + new Thread(waiter).start(); + return (char[]) waiter.getResult(); + } + + /** + * The User is asked to pick a name by the PassPhraseAgent. The PassPhraseAgent can query the given signer for + * a list of included aliases or even create a new keypair. + * + * @return + * @throws org.neuclear.commons.crypto.passphraseagents.UserCancellationException + * + */ + public byte[] sign(BrowsableSigner signer, byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { + WaitForInput waiter = ksd.createSigningTask(signer, data, callback); + new Thread(waiter).start(); + return (byte[]) waiter.getResult(); + } + } Index: NewAliasDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/NewAliasDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NewAliasDialog.java 9 Apr 2004 22:56:44 -0000 1.2 --- NewAliasDialog.java 12 Apr 2004 15:00:29 -0000 1.3 *************** *** 18,21 **** --- 18,25 ---- $Id$ $Log$ + Revision 1.3 2004/04/12 15:00:29 pelle + Now have a slightly better way of handling the waiting for input using the WaitForInput class. + This will later be put into a command queue for execution. + Revision 1.2 2004/04/09 22:56:44 pelle SwingAgent now manages key creation as well through the NewAliasDialog. *************** *** 34,38 **** */ public class NewAliasDialog implements Runnable { ! public NewAliasDialog(SwingAgent agent) { try { UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); --- 38,42 ---- */ public class NewAliasDialog implements Runnable { ! public NewAliasDialog(KeyStoreDialog agent) { try { UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); *************** *** 173,188 **** ok.setEnabled(false); cancel.setEnabled(true); ! try { ! System.out.println("Generating Key"); ! agent.getSigner().createKeyPair(alias.getText(), passphrase1.getPassword()); ! agent.updateList(alias.getText()); ! } catch (CryptoException e) { ! e.printStackTrace(); ! } ! dialog.hide(); } ! private SwingAgent agent; private JDialog dialog; private JButton ok; --- 177,208 ---- ok.setEnabled(false); cancel.setEnabled(true); ! new Thread(new Runnable() { ! /** ! * When an object implementing interface <code>Runnable</code> is used ! * to create a thread, starting the thread causes the object's ! * <code>run</code> method to be called in that separately executing ! * thread. ! * <p/> ! * The general contract of the method <code>run</code> is that it may ! * take any action whatsoever. ! * ! * @see Thread#run() ! */ ! public void run() { ! try { ! System.out.println("Generating Key"); ! agent.getSigner().createKeyPair(alias.getText(), passphrase1.getPassword()); ! agent.updateList(alias.getText()); ! dialog.hide(); ! } catch (CryptoException e) { ! e.printStackTrace(); ! } ! ! } ! }).start(); } ! private KeyStoreDialog agent; private JDialog dialog; private JButton ok; Index: SimpleDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SimpleDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleDialog.java 9 Apr 2004 22:56:44 -0000 1.1 --- SimpleDialog.java 12 Apr 2004 15:00:29 -0000 1.2 *************** *** 6,11 **** import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.plaf.Options; - import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; - import org.neuclear.commons.crypto.signers.BrowsableSigner; import javax.swing.*; --- 6,9 ---- *************** *** 20,23 **** --- 18,25 ---- $Id$ $Log$ + Revision 1.2 2004/04/12 15:00:29 pelle + Now have a slightly better way of handling the waiting for input using the WaitForInput class. + This will later be put into a command queue for execution. + Revision 1.1 2004/04/09 22:56:44 pelle SwingAgent now manages key creation as well through the NewAliasDialog. *************** *** 36,40 **** */ public class SimpleDialog { ! public SimpleDialog(SwingAgent agent) { try { UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); --- 38,42 ---- */ public class SimpleDialog { ! public SimpleDialog() { try { UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel"); *************** *** 43,50 **** // Likely PlasticXP is not in the class path; ignore. } - this.agent = agent; ok = new JButton("Open"); ok.setEnabled(false); cancel = new JButton("Cancel"); passphrase = new JPasswordField(); final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); --- 45,52 ---- // Likely PlasticXP is not in the class path; ignore. } ok = new JButton("Open"); ok.setEnabled(false); cancel = new JButton("Cancel"); + alias = new JLabel(); passphrase = new JPasswordField(); final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); *************** *** 64,69 **** synchronized (passphrase) { passphrase.setText(""); ! isCancel = true; ! passphrase.notifyAll(); } --- 66,70 ---- synchronized (passphrase) { passphrase.setText(""); ! runner.cancel(); } *************** *** 75,80 **** synchronized (passphrase) { if (validate()) { ! isCancel = false; ! passphrase.notifyAll(); } } --- 76,80 ---- synchronized (passphrase) { if (validate()) { ! runner.execute(); } } *************** *** 110,115 **** builder.setDefaultDialogBorder(); ! builder.add(icon, cc.xyw(1, 5, 1, CellConstraints.LEFT, CellConstraints.TOP)); builder.addSeparator("Enter passphrase", cc.xyw(1, 3, 3)); builder.addLabel("Passphrase:", cc.xy(1, 7)); builder.add(passphrase, cc.xy(3, 7)); --- 110,117 ---- builder.setDefaultDialogBorder(); ! builder.add(icon, cc.xyw(1, 1, 1, CellConstraints.LEFT, CellConstraints.TOP)); builder.addSeparator("Enter passphrase", cc.xyw(1, 3, 3)); + builder.addLabel("open:", cc.xy(1, 5)); + builder.add(alias, cc.xy(3, 5)); builder.addLabel("Passphrase:", cc.xy(1, 7)); builder.add(passphrase, cc.xy(3, 7)); *************** *** 125,173 **** } - /** - * Retrieve the PassPhrase for a given name/alias - * - * @param name - * @return - */ - public char[] getPassPhrase(String name) throws UserCancellationException { - - return getPassPhrase(name, false); - } - - public char[] getPassPhrase(String name, boolean incorrect) throws UserCancellationException { - synchronized (passphrase) {//We dont want multiple agents popping up at the same time - isCancel = true; - // if (incorrect) - // System.err.println("Incorrect passphrase"); - // incorrectLabel.setVisible(incorrect); - // nameLabel.setVisible(true); - // - // nameLabel.setText(name); - dialog.pack(); - dialog.setVisible(true); - try { - passphrase.wait(); - } catch (InterruptedException e) { - ; - } - dialog.setVisible(false); - if (isCancel) - throw new UserCancellationException(name); - final String phrase = passphrase.getText(); - // if (remember.getState()) - // cache.put(name, phrase); - passphrase.setText(""); - return phrase.toCharArray(); - } - } - - BrowsableSigner getSigner() { - return signer; - } - - JDialog getDialog() { - return dialog; - } private boolean validate() { --- 127,130 ---- *************** *** 175,188 **** } ! private BrowsableSigner signer; private final JButton ok; private final JButton cancel; private final JPasswordField passphrase; private final JDialog dialog; - private boolean isCancel; - private SwingAgent agent; private final JLabel icon; } --- 132,172 ---- } ! WaitForInput createGetPassphraseTask(final String name, final boolean incorrect) { ! return new DialogRunner(name, incorrect); ! } private final JButton ok; private final JButton cancel; + private final JLabel alias; private final JPasswordField passphrase; private final JDialog dialog; private final JLabel icon; + private DialogRunner runner; + class DialogRunner extends WaitForInput { + public DialogRunner(final String alias, final boolean incorrect) { + this.req = alias; + this.incorrect = incorrect; + } + + public void run() { + runner = this; + alias.setText(req); + dialog.pack(); + dialog.show(); + } + + public void execute() { + dialog.hide(); + final char[] phrase = passphrase.getPassword(); + // if (remember.getState()) + // cache.put(name, phrase); + passphrase.setText(""); + setResult(phrase); + } + + private final String req; + private final boolean incorrect; + } } --- NEW FILE: WaitForInput.java --- package org.neuclear.commons.crypto.passphraseagents.swing; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; /* $Id: WaitForInput.java,v 1.1 2004/04/12 15:00:29 pelle Exp $ $Log: WaitForInput.java,v $ Revision 1.1 2004/04/12 15:00:29 pelle Now have a slightly better way of handling the waiting for input using the WaitForInput class. This will later be put into a command queue for execution. */ /** * User: pelleb * Date: Apr 10, 2004 * Time: 3:13:10 PM */ public abstract class WaitForInput implements Runnable { public Object getResult() throws UserCancellationException { synchronized (monitor) { try { monitor.wait(); } catch (InterruptedException e) { ; } if (cancelled) throw new UserCancellationException("User Cancelled"); return result; } } protected void setResult(Object result) { this.result = result; synchronized (monitor) { monitor.notifyAll(); } } protected void cancel() { cancelled = true; synchronized (monitor) { monitor.notifyAll(); } } private Object result; private boolean cancelled = false; private final Object monitor = new Object(); } |