|
From: Pelle B. <pe...@us...> - 2004-04-14 00:11:33
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4424/src/java/org/neuclear/commons/crypto/passphraseagents/swing Modified Files: KeyStoreDialog.java NewAliasDialog.java SaveKeyStore.java SimpleDialog.java SwingAgent.java WaitForInput.java Added Files: MessageLabel.java NewPassphraseDialog.java Log Message: Added a MessageLabel for handling errors, validation and info Save works well now. It's pretty much there I think. Index: SwingAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SwingAgent.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SwingAgent.java 13 Apr 2004 18:14:02 -0000 1.6 --- SwingAgent.java 14 Apr 2004 00:10:52 -0000 1.7 *************** *** 17,20 **** --- 17,25 ---- $Id$ $Log$ + Revision 1.7 2004/04/14 00:10:52 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.6 2004/04/13 18:14:02 pelle added open dialog to swing agent and interactive agent *************** *** 56,59 **** --- 61,65 ---- ksd = new KeyStoreDialog(); simple = new SimpleDialog(); + np = new NewPassphraseDialog(); queue = new RunnableQueue(); fc = new JFileChooser(); *************** *** 63,66 **** --- 69,73 ---- private final SimpleDialog simple; + private final NewPassphraseDialog np; private final KeyStoreDialog ksd; private final RunnableQueue queue; *************** *** 127,131 **** public File getSaveToFileName(String title, String def) throws UserCancellationException { prepFileChooser(def, title); ! fc.showSaveDialog(ksd.getDialog()); return fc.getSelectedFile(); } --- 134,140 ---- public File getSaveToFileName(String title, String def) throws UserCancellationException { prepFileChooser(def, title); ! int result = fc.showSaveDialog(ksd.getFrame()); ! if (result == JFileChooser.CANCEL_OPTION) ! throw new UserCancellationException(title); return fc.getSelectedFile(); } *************** *** 133,140 **** public File getOpenFileName(String title, String def) throws UserCancellationException { prepFileChooser(def, title); ! fc.showOpenDialog(ksd.getDialog()); return fc.getSelectedFile(); } private void prepFileChooser(String def, String title) { File file = new File(def); --- 142,157 ---- public File getOpenFileName(String title, String def) throws UserCancellationException { prepFileChooser(def, title); ! int result = fc.showOpenDialog(ksd.getFrame()); ! if (result == JFileChooser.CANCEL_OPTION) ! throw new UserCancellationException(title); return fc.getSelectedFile(); } + public char[] getNewPassPhrase(String name) throws UserCancellationException { + WaitForInput waiter = np.createGetNewPassphraseTask(name); + queue.queue(waiter); + return (char[]) waiter.getResult(); + } + private void prepFileChooser(String def, String title) { File file = new File(def); Index: SaveKeyStore.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SaveKeyStore.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SaveKeyStore.java 13 Apr 2004 17:32:05 -0000 1.1 --- SaveKeyStore.java 14 Apr 2004 00:10:52 -0000 1.2 *************** *** 1,10 **** --- 1,19 ---- package org.neuclear.commons.crypto.passphraseagents.swing; + import org.neuclear.commons.LowLevelException; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import org.neuclear.commons.crypto.signers.BrowsableSigner; + import org.neuclear.commons.crypto.signers.DefaultSigner; + + import java.io.IOException; /* $Id$ $Log$ + Revision 1.2 2004/04/14 00:10:52 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.1 2004/04/13 17:32:05 pelle Now has save dialog *************** *** 19,24 **** */ public class SaveKeyStore implements Runnable { ! public SaveKeyStore(BrowsableSigner signer) { this.signer = signer; } --- 28,35 ---- */ public class SaveKeyStore implements Runnable { ! public SaveKeyStore(BrowsableSigner signer, MessageLabel message, boolean force) { this.signer = signer; + this.message = message; + this.force = force; } *************** *** 36,51 **** public void run() { try { ! signer.save(); } catch (UserCancellationException e) { ! e.printStackTrace(); } } ! public static void save(BrowsableSigner signer) { } private final BrowsableSigner signer; ! } --- 47,77 ---- public void run() { try { ! if (signer instanceof DefaultSigner) ! ((DefaultSigner) signer).save(force); ! else ! signer.save(); ! message.info("KeyStore saved"); } catch (UserCancellationException e) { ! message.info("Save Cancelled"); ! } catch (IOException e) { ! message.error("Problem Saving KeyStore: " + e.getLocalizedMessage()); ! } catch (LowLevelException e) { ! message.error("Problem Saving KeyStore: " + e.getCause().getLocalizedMessage()); ! } catch (Exception e) { ! message.error("Problem Saving KeyStore: " + e.getLocalizedMessage()); } } ! public static void save(BrowsableSigner signer, MessageLabel message) { ! new Thread(new SaveKeyStore(signer, message, false)).start(); ! } + public static void saveAs(BrowsableSigner signer, MessageLabel message) { + new Thread(new SaveKeyStore(signer, message, true)).start(); } private final BrowsableSigner signer; ! private final MessageLabel message; ! private final boolean force; } Index: WaitForInput.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/WaitForInput.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WaitForInput.java 13 Apr 2004 17:32:05 -0000 1.2 --- WaitForInput.java 14 Apr 2004 00:10:52 -0000 1.3 *************** *** 6,9 **** --- 6,14 ---- $Id$ $Log$ + Revision 1.3 2004/04/14 00:10:52 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.2 2004/04/13 17:32:05 pelle Now has save dialog *************** *** 52,55 **** --- 57,62 ---- } + abstract void execute(); + private Object result; private boolean cancelled = false; --- NEW FILE: MessageLabel.java --- package org.neuclear.commons.crypto.passphraseagents.swing; import javax.swing.*; import java.awt.*; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: MessageLabel.java,v 1.1 2004/04/14 00:10:51 pelle Exp $ $Log: MessageLabel.java,v $ Revision 1.1 2004/04/14 00:10:51 pelle Added a MessageLabel for handling errors, validation and info Save works well now. It's pretty much there I think. */ /** * User: pelleb * Date: Apr 13, 2004 * Time: 9:34:50 PM */ public class MessageLabel extends JLabel { public MessageLabel() { orig = getBackground(); setText(" "); setOpaque(false); } public void info(String message) { setOpaque(true); setBackground(INFO); setText(message); } public void invalid(String message) { setOpaque(true); setBackground(INVALID); setText(message); } public void invalidPassphrase() { invalid("Incorrect Passphrase. Please try again..."); } public void error(String message) { setOpaque(true); setBackground(ERROR); setText(message); } public void error(Exception e) { if (e.getCause() == null) error(e.getLocalizedMessage()); else error(e.getCause().getLocalizedMessage()); } public void clear() { setBackground(orig); setText(" "); setOpaque(false); } private final Color orig; public static final Color INFO = new Color(200, 200, 200); public static final Color ERROR = Color.RED; public static final Color INVALID = Color.PINK; } Index: KeyStoreDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/KeyStoreDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** KeyStoreDialog.java 13 Apr 2004 17:32:05 -0000 1.3 --- KeyStoreDialog.java 14 Apr 2004 00:10:51 -0000 1.4 *************** *** 33,36 **** --- 33,41 ---- $Id$ $Log$ + Revision 1.4 2004/04/14 00:10:51 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.3 2004/04/13 17:32:05 pelle Now has save dialog *************** *** 73,76 **** --- 78,82 ---- cancel = new JButton("Cancel"); newId = new JButton("New ID ..."); + message = new MessageLabel(); save = new JButton("Save ..."); remember = new JCheckBox("remember passphrase in current session", prefs.getBoolean(REMEMBER_PASSPHRASE, false)); *************** *** 78,92 **** 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() { --- 84,101 ---- list.setBorder(BorderFactory.createLoweredBevelBorder()); passphrase = new JPasswordField(); + frame = new JFrame(); + final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); ! if (imageurl != null) { ! final ImageIcon icon = new ImageIcon(imageurl); ! frame.setIconImage(icon.getImage()); ! this.icon = new JLabel(icon); ! } else icon = new JLabel("NeuClear"); ! frame.setTitle("NeuClear Signing Agent"); ! frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); ! frame.getContentPane().add(buildPanel()); ! frame.pack(); nad = new NewAliasDialog(this); cancel.addActionListener(new ActionListener() { *************** *** 94,98 **** synchronized (passphrase) { passphrase.setText(""); ! dialog.hide(); runner.cancel(); } --- 103,107 ---- synchronized (passphrase) { passphrase.setText(""); ! frame.hide(); runner.cancel(); } *************** *** 136,139 **** --- 145,150 ---- */ public void valueChanged(ListSelectionEvent e) { + if (list.getModel().getSize() == 0) + return; lastSelected = (String) list.getSelectedValue(); if (remember.isSelected() && cache.containsKey(lastSelected)) *************** *** 159,163 **** */ public void actionPerformed(ActionEvent e) { ! new Thread(new SaveKeyStore(signer)).start(); } --- 170,174 ---- */ public void actionPerformed(ActionEvent e) { ! SaveKeyStore.saveAs(signer, message); } *************** *** 184,188 **** fillAliasList(); list.setSelectedValue(alias, true); ! dialog.pack(); } } --- 195,202 ---- fillAliasList(); list.setSelectedValue(alias, true); ! message.info(alias + " added"); ! frame.pack(); ! SaveKeyStore.save(signer, message); ! } } *************** *** 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(); --- 204,208 ---- private Component buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", ! "pref,3dlu,pref, 3dlu, fill:pref:grow, 3dlu, pref, 3dlu, pref,3dlu, pref, 7dlu, pref"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); *************** *** 197,205 **** 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)); builder.add(remember, cc.xy(3, 9)); ButtonBarBuilder bb = new ButtonBarBuilder(); --- 211,221 ---- builder.add(icon, cc.xyw(1, 5, 1, CellConstraints.LEFT, CellConstraints.TOP)); + icon.setLabelFor(list); builder.addSeparator("Identities", cc.xyw(1, 3, 3)); builder.add(list, cc.xyw(3, 5, 1)); ! builder.addLabel("Passphrase:", cc.xy(1, 7)).setLabelFor(passphrase); builder.add(passphrase, cc.xy(3, 7)); builder.add(remember, cc.xy(3, 9)); + builder.add(message, cc.xyw(1, 11, 3)); ButtonBarBuilder bb = new ButtonBarBuilder(); *************** *** 210,214 **** bb.addGridded(sign); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 11, 3)); return builder.getPanel(); --- 226,230 ---- bb.addGridded(sign); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 13, 3)); return builder.getPanel(); *************** *** 234,239 **** } ! JDialog getDialog() { ! return dialog; } --- 250,255 ---- } ! JFrame getFrame() { ! return frame; } *************** *** 252,259 **** private final JButton newId; private final JButton save; private final JCheckBox remember; private final JList list; private final JPasswordField passphrase; ! private final JDialog dialog; private final NewAliasDialog nad; private final Map cache; --- 268,276 ---- private final JButton newId; private final JButton save; + private final MessageLabel message; private final JCheckBox remember; private final JList list; private final JPasswordField passphrase; ! private final JFrame frame; private final NewAliasDialog nad; private final Map cache; *************** *** 268,271 **** --- 285,289 ---- this.cb = cb; this.bs = bs; + this.invalid = false; } *************** *** 274,287 **** 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(); sign.setEnabled(false); } --- 292,313 ---- signer = bs; fillAliasList(); ! if (list.getModel().getSize() > 0) { ! list.setSelectedValue(prefs.get(DEFAULT_ALIAS, ""), true); ! if (list.getSelectedIndex() == -1) ! list.setSelectedIndex(0); ! if (remember.isSelected() && (list.getSelectedIndex() != -1) ! && cache.containsKey(list.getSelectedValue())) ! passphrase.setText((String) cache.get(list.getSelectedValue())); ! else ! passphrase.setText(""); ! } else passphrase.setText(""); ! if (invalid) ! message.invalidPassphrase(); ! else ! message.clear(); ! passphrase.requestFocus(); ! frame.pack(); ! frame.show(); sign.setEnabled(false); } *************** *** 298,309 **** } - 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(); } --- 324,339 ---- } char phrase[] = passphrase.getPassword(); passphrase.setText(""); try { ! final byte[] sig = signer.sign(list.getSelectedValue().toString(), phrase, data, cb); ! invalid = false; ! frame.hide(); ! setResult(sig); } catch (InvalidPassphraseException e) { + invalid = true; run(); + } catch (Exception e) { + message.error(e); } *************** *** 314,317 **** --- 344,348 ---- private final SetPublicKeyCallBack cb; private final BrowsableSigner bs; + private boolean invalid = false; } --- NEW FILE: NewPassphraseDialog.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: NewPassphraseDialog.java,v 1.1 2004/04/14 00:10:51 pelle Exp $ $Log: NewPassphraseDialog.java,v $ Revision 1.1 2004/04/14 00:10:51 pelle Added a MessageLabel for handling errors, validation and info Save works well now. It's pretty much there I think. 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. 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 NewPassphraseDialog { public NewPassphraseDialog() { 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("Save"); ok.setEnabled(false); cancel = new JButton("Cancel"); alias = new JLabel(); passphrase = new JPasswordField(); passphrase2 = 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"); message = new MessageLabel(); 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); passphrase2.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); passphrase2.addKeyListener(validate); } private Component buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow ", "pref,3dlu,pref, 3dlu, fill:pref:grow, 3dlu, pref,3dlu, pref,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 new passphrase", cc.xyw(1, 3, 3)); builder.addLabel("name:", cc.xy(1, 5)).setLabelFor(alias); builder.add(alias, cc.xy(3, 5)); builder.addLabel("Passphrase:", cc.xy(1, 7)).setLabelFor(passphrase); builder.add(passphrase, cc.xy(3, 7)); builder.addLabel("Repeat Passphrase:", cc.xy(1, 9)).setLabelFor(passphrase2); builder.add(passphrase2, cc.xy(3, 9)); builder.add(message, cc.xyw(1, 11, 3)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addUnrelatedGap(); bb.addGridded(ok); bb.addGridded(cancel); builder.add(bb.getPanel(), cc.xyw(1, 13, 3)); return builder.getPanel(); } private boolean validate() { char[] p1 = passphrase.getPassword(); char[] p2 = passphrase2.getPassword(); if (p1 == null || p2 == null || p1.length == 0 || p2.length == 0) { message.invalid("Please enter your new matching passphrases"); return false; } if (p1.length != p2.length) { message.invalid("Both passphrases must be the same"); return false; } message.clear(); return true;//new String(p1).equals(new String(p2)); } public WaitForInput createGetNewPassphraseTask(String name) { return new NewPassPhraseRunner(name); } private final JButton ok; private final JButton cancel; private final JLabel alias; private final JPasswordField passphrase; private final JPasswordField passphrase2; private final JDialog dialog; private final JLabel icon; private final MessageLabel message; private WaitForInput runner; class NewPassPhraseRunner extends WaitForInput { public NewPassPhraseRunner(final String alias) { this.req = alias; } public void run() { runner = this; ok.setEnabled(false); alias.setText(req); dialog.pack(); dialog.show(); System.out.println(Thread.currentThread()); } public void execute() { dialog.hide(); final char[] phrase = passphrase.getPassword(); passphrase.setText(""); setResult(phrase); } private final String req; } } Index: SimpleDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SimpleDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SimpleDialog.java 13 Apr 2004 17:32:05 -0000 1.3 --- SimpleDialog.java 14 Apr 2004 00:10:52 -0000 1.4 *************** *** 18,21 **** --- 18,26 ---- $Id$ $Log$ + Revision 1.4 2004/04/14 00:10:52 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.3 2004/04/13 17:32:05 pelle Now has save dialog *************** *** 54,57 **** --- 59,63 ---- alias = new JLabel(); passphrase = new JPasswordField(); + message = new MessageLabel(); final URL imageurl = this.getClass().getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); if (imageurl != null) *************** *** 108,112 **** 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(); --- 114,118 ---- 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(); *************** *** 116,123 **** 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(); --- 122,131 ---- 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)).setLabelFor(alias); builder.add(alias, cc.xy(3, 5)); ! builder.addLabel("Passphrase:", cc.xy(1, 7)).setLabelFor(passphrase); builder.add(passphrase, cc.xy(3, 7)); + builder.add(message, cc.xyw(1, 9, 3)); + ButtonBarBuilder bb = new ButtonBarBuilder(); *************** *** 126,130 **** bb.addGridded(ok); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 9, 3)); return builder.getPanel(); --- 134,138 ---- bb.addGridded(ok); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 11, 3)); return builder.getPanel(); *************** *** 140,143 **** --- 148,152 ---- } + private final JButton ok; private final JButton cancel; *************** *** 146,150 **** private final JDialog dialog; private final JLabel icon; ! private DialogRunner runner; class DialogRunner extends WaitForInput { --- 155,160 ---- private final JDialog dialog; private final JLabel icon; ! private final MessageLabel message; ! private WaitForInput runner; class DialogRunner extends WaitForInput { *************** *** 157,160 **** --- 167,172 ---- runner = this; alias.setText(req); + if (incorrect) + message.invalid("You entered an invalid passphrase. Try again..."); dialog.pack(); dialog.show(); Index: NewAliasDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/NewAliasDialog.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NewAliasDialog.java 13 Apr 2004 17:32:05 -0000 1.4 --- NewAliasDialog.java 14 Apr 2004 00:10:51 -0000 1.5 *************** *** 17,20 **** --- 17,25 ---- $Id$ $Log$ + Revision 1.5 2004/04/14 00:10:51 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.4 2004/04/13 17:32:05 pelle Now has save dialog *************** *** 57,64 **** 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); --- 62,71 ---- passphrase1 = new JPasswordField(); passphrase2 = new JPasswordField(); + message = new MessageLabel(); + progress = new JProgressBar(0, 100); progress.setIndeterminate(true); progress.setVisible(true); ! dialog = new JDialog(agent.getFrame(), true); dialog.setTitle("NeuClear Signing Agent"); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); *************** *** 131,144 **** private boolean validate() { ! if (alias.getText().length() == 0) return false; char[] p1 = passphrase1.getPassword(); char[] p2 = passphrase2.getPassword(); ! if (p1 == null || p2 == null) ! return false; ! if (p1.length != p2.length) return false; ! if (p1.length == 0) return false; return true;//new String(p1).equals(new String(p2)); } --- 138,156 ---- private boolean validate() { ! if (alias.getText().length() == 0) { ! message.invalid("Please enter your new Identity Name"); return false; + } char[] p1 = passphrase1.getPassword(); char[] p2 = passphrase2.getPassword(); ! if (p1 == null || p2 == null || p1.length == 0 || p2.length == 0) { ! message.invalid("Please enter your new matching passphrases"); return false; ! } ! if (p1.length != p2.length) { ! message.invalid("Both passphrases must be the same"); return false; + } + message.clear(); return true;//new String(p1).equals(new String(p2)); } *************** *** 146,150 **** private JPanel buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ", ! "pref,3dlu,pref, 3dlu, pref, 3dlu, pref, 7dlu, pref"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); --- 158,162 ---- private JPanel buildPanel() { FormLayout layout = new FormLayout("right:pref, 3dlu, 100dlu:grow ", ! "pref,3dlu,pref, 3dlu, pref, 3dlu, pref,3dlu, pref, 7dlu, pref"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); *************** *** 153,163 **** builder.addSeparator("Create alias", cc.xyw(1, 1, 3)); ! builder.addLabel("Alias:", cc.xy(1, 3)); builder.add(alias, cc.xy(3, 3)); ! builder.addLabel("Passphrase:", cc.xy(1, 5)); builder.add(passphrase1, cc.xy(3, 5)); ! 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(); --- 165,176 ---- builder.addSeparator("Create alias", cc.xyw(1, 1, 3)); ! builder.addLabel("Alias:", cc.xy(1, 3)).setLabelFor(alias); builder.add(alias, cc.xy(3, 3)); ! builder.addLabel("Passphrase:", cc.xy(1, 5)).setLabelFor(passphrase1); builder.add(passphrase1, cc.xy(3, 5)); ! builder.addLabel("(Repeat) Passphrase:", cc.xy(1, 7)).setLabelFor(passphrase2); builder.add(passphrase2, cc.xy(3, 7)); ! builder.add(message, cc.xyw(1, 9, 3)); ! ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); *************** *** 165,169 **** bb.addGridded(ok); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 9, 3)); return builder.getPanel(); --- 178,182 ---- bb.addGridded(ok); bb.addGridded(cancel); ! builder.add(bb.getPanel(), cc.xyw(1, 11, 3)); return builder.getPanel(); *************** *** 208,211 **** --- 221,228 ---- cancel.setEnabled(true); passphrase1.setEnabled(true); + alias.setText(""); + alias.setEnabled(true); + passphrase1.setText(""); + passphrase2.setText(""); alias.setEnabled(true); passphrase2.setEnabled(true); *************** *** 256,259 **** --- 273,277 ---- private JPanel regular; private JPanel process; + private MessageLabel message; } |