|
From: Pelle B. <pe...@us...> - 2004-04-13 17:46:10
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18861/src/java/org/neuclear/commons/crypto/passphraseagents/swing Modified Files: KeyStoreDialog.java NewAliasDialog.java RunnableQueue.java SimpleDialog.java SwingAgent.java WaitForInput.java Added Files: FileDialog.java SaveKeyStore.java Log Message: Now has save dialog Remembers passphrases Index: SwingAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SwingAgent.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SwingAgent.java 12 Apr 2004 23:50:07 -0000 1.4 --- SwingAgent.java 13 Apr 2004 17:32:05 -0000 1.5 *************** *** 11,14 **** --- 11,15 ---- import javax.swing.*; + import java.io.File; import java.security.PublicKey; *************** *** 16,19 **** --- 17,24 ---- $Id$ $Log$ + Revision 1.5 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + Revision 1.4 2004/04/12 23:50:07 pelle implemented the queue and improved the DefaultSigner *************** *** 59,71 **** try { try { ! System.out.println(dia.getPassPhrase("test")); final BrowsableSigner signer = new DefaultSigner(dia); ! byte sig[] = signer.sign("testdata".getBytes(), new SetPublicKeyCallBack() { ! public void setPublicKey(PublicKey pub) { ! System.out.println("PublicKey:"); ! System.out.println(pub); ! } ! }); ! System.out.println(Base64.encode(sig)); // System.out.println("Getting passphrase... " + new String(dia.getPassPhrase((BrowsableSigner) signer))); // System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test", true))); --- 64,78 ---- try { try { ! // System.out.println(dia.getPassPhrase("test")); final BrowsableSigner signer = new DefaultSigner(dia); ! while (true) { ! byte sig[] = signer.sign("testdata".getBytes(), new SetPublicKeyCallBack() { ! public void setPublicKey(PublicKey pub) { ! System.out.println("PublicKey:"); ! System.out.println(pub); ! } ! }); ! System.out.println(Base64.encode(sig)); ! } // System.out.println("Getting passphrase... " + new String(dia.getPassPhrase((BrowsableSigner) signer))); // System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test", true))); *************** *** 111,114 **** --- 118,142 ---- } + public File getSaveToFileName(String title, String def) throws UserCancellationException { + File file = new File(def); + JFileChooser fc = new JFileChooser(file.getParentFile()); + fc.setFileFilter(new JKSFilter()); + fc.setSelectedFile(file); + fc.setDialogTitle(title); + // Show open dialog; this method does not return until the dialog is closed + fc.showSaveDialog(ksd.getDialog()); + return fc.getSelectedFile(); + } + + class JKSFilter extends javax.swing.filechooser.FileFilter { + public boolean accept(File file) { + String filename = file.getName(); + return filename.endsWith(".jks"); + } + + public String getDescription() { + return "*.jks"; + } + } } --- NEW FILE: SaveKeyStore.java --- package org.neuclear.commons.crypto.passphraseagents.swing; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import org.neuclear.commons.crypto.signers.BrowsableSigner; /* $Id: SaveKeyStore.java,v 1.1 2004/04/13 17:32:05 pelle Exp $ $Log: SaveKeyStore.java,v $ Revision 1.1 2004/04/13 17:32:05 pelle Now has save dialog Remembers passphrases */ /** * User: pelleb * Date: Apr 13, 2004 * Time: 11:55:54 AM */ public class SaveKeyStore implements Runnable { public SaveKeyStore(BrowsableSigner signer) { this.signer = signer; } /** * 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 { signer.save(); } catch (UserCancellationException e) { e.printStackTrace(); } } public static void save(BrowsableSigner signer) { } private final BrowsableSigner signer; } Index: WaitForInput.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/WaitForInput.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WaitForInput.java 12 Apr 2004 15:00:29 -0000 1.1 --- WaitForInput.java 13 Apr 2004 17:32:05 -0000 1.2 *************** *** 6,9 **** --- 6,13 ---- $Id$ $Log$ + Revision 1.2 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + 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. *************** *** 20,23 **** --- 24,29 ---- public Object getResult() throws UserCancellationException { + System.out.println(Thread.currentThread()); + synchronized (monitor) { try { Index: RunnableQueue.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/RunnableQueue.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunnableQueue.java 12 Apr 2004 23:50:07 -0000 1.1 --- RunnableQueue.java 13 Apr 2004 17:32:05 -0000 1.2 *************** *** 1,4 **** --- 1,6 ---- package org.neuclear.commons.crypto.passphraseagents.swing; + import javax.swing.*; + import java.lang.reflect.InvocationTargetException; import java.util.LinkedList; *************** *** 23,26 **** --- 25,32 ---- $Id$ $Log$ + Revision 1.2 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + Revision 1.1 2004/04/12 23:50:07 pelle implemented the queue and improved the DefaultSigner *************** *** 42,46 **** System.out.println("Starting Crypto Agent Event Queue"); while (true) { ! read().run(); } --- 48,58 ---- System.out.println("Starting Crypto Agent Event Queue"); while (true) { ! try { ! SwingUtilities.invokeAndWait(read()); ! } catch (InterruptedException e) { ! e.printStackTrace(); ! } catch (InvocationTargetException e) { ! e.printStackTrace(); ! } } *************** *** 63,70 **** public void queue(Runnable run) { if (thread == null) { ! thread = new Thread(this); thread.start(); } synchronized (monitor) { queue.add(run); monitor.notifyAll(); --- 75,83 ---- public void queue(Runnable run) { if (thread == null) { ! thread = new Thread(this, "Crypto GUI Tasks"); thread.start(); } synchronized (monitor) { + System.out.println("added " + run.getClass().toString()); queue.add(run); monitor.notifyAll(); Index: KeyStoreDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/KeyStoreDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeyStoreDialog.java 12 Apr 2004 23:50:07 -0000 1.2 --- KeyStoreDialog.java 13 Apr 2004 17:32:05 -0000 1.3 *************** *** 7,14 **** --- 7,17 ---- import com.jgoodies.plaf.Options; import org.neuclear.commons.crypto.signers.BrowsableSigner; + import org.neuclear.commons.crypto.signers.DefaultSigner; import org.neuclear.commons.crypto.signers.InvalidPassphraseException; import org.neuclear.commons.crypto.signers.SetPublicKeyCallBack; import javax.swing.*; + import javax.swing.event.ChangeEvent; + import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; *************** *** 24,31 **** --- 27,40 ---- import java.util.Map; import java.util.Vector; + import java.util.prefs.BackingStoreException; + import java.util.prefs.Preferences; /* $Id$ $Log$ + Revision 1.3 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + Revision 1.2 2004/04/12 23:50:07 pelle implemented the queue and improved the DefaultSigner *************** *** 58,66 **** // 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(); list.setBorder(BorderFactory.createLoweredBevelBorder()); --- 67,78 ---- // Likely PlasticXP is not in the class path; ignore. } + prefs = Preferences.userNodeForPackage(DefaultSigner.class); cache = new HashMap(); sign = new JButton("Sign"); sign.setEnabled(false); cancel = new JButton("Cancel"); ! newId = new JButton("New ID ..."); ! save = new JButton("Save ..."); ! remember = new JCheckBox("remember passphrase in current session", prefs.getBoolean(REMEMBER_PASSPHRASE, false)); list = new JList(); list.setBorder(BorderFactory.createLoweredBevelBorder()); *************** *** 116,119 **** --- 128,132 ---- }; passphrase.addKeyListener(validate); + list.addListSelectionListener(new ListSelectionListener() { /** *************** *** 123,127 **** --- 136,146 ---- */ public void valueChanged(ListSelectionEvent e) { + lastSelected = (String) list.getSelectedValue(); + if (remember.isSelected() && cache.containsKey(lastSelected)) + passphrase.setText((String) cache.get(lastSelected)); + else + passphrase.setText(""); sign.setEnabled(validate()); + } *************** *** 130,138 **** --- 149,178 ---- newId.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { + SwingUtilities.invokeLater(nad); } }); + save.addActionListener(new ActionListener() { + /** + * Invoked when an action occurs. + */ + public void actionPerformed(ActionEvent e) { + new Thread(new SaveKeyStore(signer)).start(); + } + + }); + remember.addChangeListener(new ChangeListener() { + /** + * Invoked when the target of the listener has changed its state. + * + * @param e a ChangeEvent object + */ + public void stateChanged(ChangeEvent e) { + cache.clear(); + + } + }); // dialog.show(); *************** *** 150,154 **** 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(); --- 190,194 ---- private Component buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", ! "pref,3dlu,pref, 3dlu, fill:pref:grow, 3dlu, pref, 3dlu, pref, 7dlu, pref"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); *************** *** 161,172 **** 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(); --- 201,214 ---- builder.addLabel("Passphrase:", cc.xy(1, 7)); builder.add(passphrase, cc.xy(3, 7)); + builder.add(remember, cc.xy(3, 9)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGridded(newId); + bb.addGridded(save); bb.addGlue(); bb.addUnrelatedGap(); bb.addGridded(sign); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 11, 3)); return builder.getPanel(); *************** *** 197,201 **** private boolean validate() { ! return (list.getSelectedIndex() > 0 && passphrase.getPassword().length > 0); } --- 239,243 ---- private boolean validate() { ! return (list.getSelectedIndex() >= 0 && passphrase.getPassword().length > 0); } *************** *** 205,211 **** --- 247,256 ---- private BrowsableSigner signer; + private String lastSelected; private final JButton sign; private final JButton cancel; private final JButton newId; + private final JButton save; + private final JCheckBox remember; private final JList list; private final JPasswordField passphrase; *************** *** 214,219 **** --- 259,266 ---- private final Map cache; private final JLabel icon; + private final Preferences prefs; private DialogRunner runner; + class DialogRunner extends WaitForInput { public DialogRunner(BrowsableSigner bs, byte data[], SetPublicKeyCallBack cb) { *************** *** 227,231 **** signer = bs; fillAliasList(); ! passphrase.setText(""); dialog.pack(); dialog.show(); --- 274,285 ---- signer = bs; fillAliasList(); ! list.setSelectedValue(prefs.get(DEFAULT_ALIAS, ""), true); ! if (list.getSelectedIndex() == -1) ! list.setSelectedIndex(0); ! if (remember.isSelected() && cache.containsKey(list.getSelectedValue().toString())) ! passphrase.setText((String) cache.get(list.getSelectedValue())); ! else ! passphrase.setText(""); ! dialog.pack(); dialog.show(); *************** *** 234,237 **** --- 288,301 ---- public void execute() { + if (remember.isSelected()) + cache.put(list.getSelectedValue().toString(), new String(passphrase.getPassword())); + prefs.putBoolean(REMEMBER_PASSPHRASE, remember.isSelected()); + prefs.put(DEFAULT_ALIAS, list.getSelectedValue().toString()); + try { + prefs.flush(); + } catch (BackingStoreException e) { + e.printStackTrace(); + } + dialog.hide(); char phrase[] = passphrase.getPassword(); *************** *** 246,254 **** --- 310,322 ---- } + private final byte data[]; private final SetPublicKeyCallBack cb; private final BrowsableSigner bs; + } + private static final String DEFAULT_ALIAS = "DEFAULT_ALIAS"; + private static final String REMEMBER_PASSPHRASE = "REMEMBER_PASSPHRASE"; } --- NEW FILE: FileDialog.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 javax.swing.*; 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; /* $Id: FileDialog.java,v 1.1 2004/04/13 17:32:05 pelle Exp $ $Log: FileDialog.java,v $ Revision 1.1 2004/04/13 17:32:05 pelle Now has save dialog Remembers passphrases 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. 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 FileDialog { public FileDialog() { 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. } 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"); 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(); cancel.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (passphrase) { passphrase.setText(""); runner.cancel(); } } }); final ActionListener action = new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (passphrase) { if (validate()) { runner.execute(); } } } }; ok.addActionListener(action); passphrase.addActionListener(action); final KeyListener validate = new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { ok.setEnabled(validate()); } public void keyTyped(KeyEvent e) { } }; passphrase.addKeyListener(validate); } 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, 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)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addUnrelatedGap(); bb.addGridded(ok); bb.addGridded(cancel); builder.add(bb.getPanel(), cc.xyw(1, 9, 3)); return builder.getPanel(); } private boolean validate() { return (passphrase.getPassword().length > 0); } 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; } } Index: SimpleDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SimpleDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleDialog.java 12 Apr 2004 15:00:29 -0000 1.2 --- SimpleDialog.java 13 Apr 2004 17:32:05 -0000 1.3 *************** *** 18,21 **** --- 18,25 ---- $Id$ $Log$ + Revision 1.3 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + 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. *************** *** 155,158 **** --- 159,164 ---- dialog.pack(); dialog.show(); + System.out.println(Thread.currentThread()); + } Index: NewAliasDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/NewAliasDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NewAliasDialog.java 12 Apr 2004 15:00:29 -0000 1.3 --- NewAliasDialog.java 13 Apr 2004 17:32:05 -0000 1.4 *************** *** 9,13 **** import javax.swing.*; - import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; --- 9,12 ---- *************** *** 18,21 **** --- 17,24 ---- $Id$ $Log$ + Revision 1.4 2004/04/13 17:32:05 pelle + Now has save dialog + Remembers passphrases + 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. *************** *** 49,64 **** ok.setEnabled(false); cancel = new JButton("Cancel"); alias = new JTextField(); passphrase1 = new JPasswordField(); passphrase2 = new JPasswordField(); ! dialog = new JDialog(agent.getDialog(), true); dialog.setTitle("NeuClear Signing Agent"); ! dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); ! dialog.getContentPane().add(buildPanel()); ! dialog.pack(); ! cancel.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (alias) { --- 52,72 ---- ok.setEnabled(false); cancel = new JButton("Cancel"); + cancel2 = new JButton("Cancel"); alias = new JTextField(); passphrase1 = new JPasswordField(); passphrase2 = new JPasswordField(); ! progress = new JProgressBar(0, 100); ! progress.setIndeterminate(true); ! progress.setVisible(true); dialog = new JDialog(agent.getDialog(), true); dialog.setTitle("NeuClear Signing Agent"); ! dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); ! dialog.hide(); ! regular = buildPanel(); ! process = buildProcessPanel(); ! //setMainPanel(); ! final ActionListener cl = new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { synchronized (alias) { *************** *** 70,74 **** } ! }); final KeyListener validate = new KeyListener() { --- 78,84 ---- } ! }; ! cancel.addActionListener(cl); ! cancel2.addActionListener(cl); final KeyListener validate = new KeyListener() { *************** *** 106,109 **** --- 116,133 ---- } + private void setMainPanel() { + dialog.getContentPane().removeAll(); + dialog.getContentPane().add(regular); + dialog.pack(); + dialog.show(); + } + + private void setProcessPanel() { + dialog.getContentPane().removeAll(); + dialog.getContentPane().add(process); + dialog.pack(); + dialog.show(); + } + private boolean validate() { if (alias.getText().length() == 0) *************** *** 120,124 **** } ! private Component buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ", "pref,3dlu,pref, 3dlu, pref, 3dlu, pref, 7dlu, pref"); --- 144,148 ---- } ! private JPanel buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ", "pref,3dlu,pref, 3dlu, pref, 3dlu, pref, 7dlu, pref"); *************** *** 135,139 **** builder.addLabel("(Repeat) Passphrase:", cc.xy(1, 7)); builder.add(passphrase2, cc.xy(3, 7)); ! ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); --- 159,163 ---- builder.addLabel("(Repeat) Passphrase:", cc.xy(1, 7)); builder.add(passphrase2, cc.xy(3, 7)); ! // builder.add(progress,cc.xyw(1,9,3)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); *************** *** 147,150 **** --- 171,195 ---- } + private JPanel buildProcessPanel() { + FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ", + "pref,3dlu,pref, 7dlu, pref"); + PanelBuilder builder = new PanelBuilder(layout); + CellConstraints cc = new CellConstraints(); + + builder.setDefaultDialogBorder(); + + builder.addSeparator("Creating Keys", cc.xyw(1, 1, 3)); + builder.add(progress, cc.xyw(1, 3, 3)); + ButtonBarBuilder bb = new ButtonBarBuilder(); + bb.addGlue(); + bb.addUnrelatedGap(); + // bb.addGridded(ok); + bb.addGridded(cancel2); + builder.add(bb.getPanel(), cc.xyw(1, 5, 3)); + + return builder.getPanel(); + + } + /** *************** *** 165,205 **** alias.setEnabled(true); passphrase2.setEnabled(true); ! dialog.pack(); ! dialog.show(); ! } private void createAlias() { ! dialog.setEnabled(false); ! passphrase1.setEnabled(false); ! alias.setEnabled(false); ! passphrase2.setEnabled(false); ! 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(); } --- 210,246 ---- alias.setEnabled(true); passphrase2.setEnabled(true); ! setMainPanel(); } private void createAlias() { ! setProcessPanel(); ! new Thread(new GenerateKeyTask(), "Generate Key").start(); ! } + private class GenerateKeyTask implements 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()); + progress.setVisible(false); + agent.updateList(alias.getText()); + dialog.hide(); + } catch (CryptoException e) { + e.printStackTrace(); } ! ! } ! } *************** *** 208,214 **** --- 249,259 ---- private JButton ok; private JButton cancel; + private JButton cancel2; private JTextField alias; private JPasswordField passphrase1; private JPasswordField passphrase2; + private JProgressBar progress; + private JPanel regular; + private JPanel process; } |