|
From: Pelle B. <pe...@us...> - 2004-04-13 00:04:02
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21842/src/java/org/neuclear/commons/crypto/passphraseagents/swing Modified Files: KeyStoreDialog.java SwingAgent.java Added Files: RunnableQueue.java Log Message: implemented the queue and improved the DefaultSigner --- NEW FILE: RunnableQueue.java --- package org.neuclear.commons.crypto.passphraseagents.swing; import java.util.LinkedList; /* 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: RunnableQueue.java,v 1.1 2004/04/12 23:50:07 pelle Exp $ $Log: RunnableQueue.java,v $ Revision 1.1 2004/04/12 23:50:07 pelle implemented the queue and improved the DefaultSigner */ /** * User: pelleb * Date: Apr 12, 2004 * Time: 10:16:55 PM */ public class RunnableQueue implements Runnable { public RunnableQueue() { queue = new LinkedList(); } public void run() { System.out.println("Starting Crypto Agent Event Queue"); while (true) { read().run(); } } private Runnable read() { synchronized (monitor) { if (queue.size() > 0) return (Runnable) queue.removeFirst(); try { monitor.wait(); } catch (InterruptedException e) { e.printStackTrace(); } return read(); } } public void queue(Runnable run) { if (thread == null) { thread = new Thread(this); thread.start(); } synchronized (monitor) { queue.add(run); monitor.notifyAll(); } } private final LinkedList queue; private Thread thread; private final Object monitor = new Object(); } Index: SwingAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/SwingAgent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SwingAgent.java 12 Apr 2004 15:00:29 -0000 1.3 --- SwingAgent.java 12 Apr 2004 23:50:07 -0000 1.4 *************** *** 6,21 **** import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import org.neuclear.commons.crypto.signers.BrowsableSigner; import org.neuclear.commons.crypto.signers.InvalidPassphraseException; import org.neuclear.commons.crypto.signers.SetPublicKeyCallBack; - import org.neuclear.commons.crypto.signers.TestCaseSigner; 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. --- 6,22 ---- import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; 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 java.security.PublicKey; /* $Id$ $Log$ + Revision 1.4 2004/04/12 23:50:07 pelle + implemented the queue and improved the DefaultSigner + 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. *************** *** 47,60 **** 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) { --- 48,57 ---- ksd = new KeyStoreDialog(); simple = new SimpleDialog(); ! queue = new RunnableQueue(); } private final SimpleDialog simple; private final KeyStoreDialog ksd; ! private final RunnableQueue queue; public static void main(final String[] args) { *************** *** 62,66 **** try { try { ! final BrowsableSigner signer = new TestCaseSigner(dia); byte sig[] = signer.sign("testdata".getBytes(), new SetPublicKeyCallBack() { public void setPublicKey(PublicKey pub) { --- 59,64 ---- 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) { *************** *** 95,99 **** public char[] getPassPhrase(String name, boolean incorrect) throws UserCancellationException { WaitForInput waiter = simple.createGetPassphraseTask(name, incorrect); ! new Thread(waiter).start(); return (char[]) waiter.getResult(); } --- 93,97 ---- public char[] getPassPhrase(String name, boolean incorrect) throws UserCancellationException { WaitForInput waiter = simple.createGetPassphraseTask(name, incorrect); ! queue.queue(waiter); return (char[]) waiter.getResult(); } *************** *** 109,113 **** 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(); } --- 107,111 ---- public byte[] sign(BrowsableSigner signer, byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { WaitForInput waiter = ksd.createSigningTask(signer, data, callback); ! queue.queue(waiter); return (byte[]) waiter.getResult(); } Index: KeyStoreDialog.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/swing/KeyStoreDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KeyStoreDialog.java 12 Apr 2004 15:00:29 -0000 1.1 --- KeyStoreDialog.java 12 Apr 2004 23:50:07 -0000 1.2 *************** *** 28,31 **** --- 28,34 ---- $Id$ $Log$ + Revision 1.2 2004/04/12 23:50:07 pelle + implemented the queue and improved the DefaultSigner + 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. *************** *** 60,64 **** cancel = new JButton("Cancel"); newId = new JButton("New ..."); ! list = new JList(new String[]{"bob", "carol", "alice"}); list.setBorder(BorderFactory.createLoweredBevelBorder()); passphrase = new JPasswordField(); --- 63,67 ---- cancel = new JButton("Cancel"); newId = new JButton("New ..."); ! list = new JList(); list.setBorder(BorderFactory.createLoweredBevelBorder()); passphrase = new JPasswordField(); |