|
From: Pelle B. <pe...@us...> - 2004-04-14 15:30:13
|
Update of /cvsroot/neuclear/neuclear-signer/src/java/org/neuclear/signers/standalone In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27163/src/java/org/neuclear/signers/standalone Modified Files: StandaloneSigner.java StandaloneSigningServlet.java Added Files: QuickStart.java SplashWindow.java Log Message: Added splash screen and java web start support (try "maven jnlp") --- NEW FILE: SplashWindow.java --- package org.neuclear.signers.standalone; /* * @(#)SplashWindow.java 1.3 2003-06-01 * * Copyright (c) 1999-2003 Werner Randelshofer * Staldenmattweg 2, Immensee, CH-6405, Switzerland * All rights reserved. * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software is hereby granted without fee, * provided this copyright notice is retained on all copies. */ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; /** * Splash Window to show an image during startup of an application.<p> * <p/> * Usage: * <pre> * // open the splash window * Frame splashOwner = SplashWindow.splash(anImage); * <p/> * // start the application * // ... * <p/> * // dispose the splash window by disposing the frame that owns the window. * splashOwner.dispose(); * </pre> * <p/> * <p>To use the splash window as an about dialog write this: * <pre> * new SplashWindow( * this, * getToolkit().createImage(getClass().getResource("splash.png")) * ).show(); * </pre> * <p/> * The splash window disposes itself when the user clicks on it. * * @author Werner Randelshofer, Staldenmattweg 2, Immensee, CH-6405, Switzerland. * @version 1.3 2003-06-01 Revised. */ public class SplashWindow extends Window { private Image splashImage; /** * This attribute indicates whether the method * paint(Graphics) has been called at least once since the * construction of this window.<br> * This attribute is used to notify method splash(Image) * that the window has been drawn at least once * by the AWT event dispatcher thread.<br> * This attribute acts like a latch. Once set to true, * it will never be changed back to false again. * * @see #paint * @see #splash */ private boolean paintCalled = false; /** * Constructs a splash window and centers it on the * screen. The user can click on the window to dispose it. * * @param owner The frame owning the splash window. * @param splashImage The splashImage to be displayed. */ public SplashWindow(Frame owner, Image splashImage) { super(owner); this.splashImage = splashImage; // Load the image MediaTracker mt = new MediaTracker(this); mt.addImage(splashImage, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { } // Center the window on the screen. int imgWidth = splashImage.getWidth(this); int imgHeight = splashImage.getHeight(this); setSize(imgWidth, imgHeight); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2); // Users shall be able to close the splash window by // clicking on its display area. This mouse listener // listens for mouse clicks and disposes the splash window. MouseAdapter disposeOnClick = new MouseAdapter() { public void mouseClicked(MouseEvent evt) { // Note: To avoid that method splash hangs, we // must set paintCalled to true and call notifyAll. // This is necessary because the mouse click may // occur before the contents of the window // has been painted. synchronized (SplashWindow.this) { SplashWindow.this.paintCalled = true; SplashWindow.this.notifyAll(); } dispose(); } }; addMouseListener(disposeOnClick); } /** * Updates the display area of the window. */ public void update(Graphics g) { // Note: Since the paint method is going to draw an // image that covers the complete area of the component we // do not fill the component with its background color // here. This avoids flickering. g.setColor(getForeground()); paint(g); } /** * Paints the image on the window. */ public void paint(Graphics g) { g.drawImage(splashImage, 0, 0, this); // Notify method splash that the window // has been painted. // Note: To improve performance we do not enter // the synchronized block unless we have to. if (!paintCalled) { paintCalled = true; synchronized (this) { notifyAll(); } } } /** * Constructs and displays a SplashWindow.<p> * This method is useful for startup splashs. * Dispose the return frame to get rid of the splash window.<p> * * @param splashImage The image to be displayed. * @return Returns the frame that owns the SplashWindow. */ public static Frame splash(Image splashImage) { Frame f = new Frame(); SplashWindow w = new SplashWindow(f, splashImage); // Show the window. w.toFront(); w.show(); // Note: To make sure the user gets a chance to see the // splash window we wait until its paint method has been // called at least by the AWT event dispatcher thread. if (!EventQueue.isDispatchThread()) { synchronized (w) { while (!w.paintCalled) { try { w.wait(); } catch (InterruptedException e) { } } } } return f; } } --- NEW FILE: QuickStart.java --- package org.neuclear.signers.standalone; import java.awt.*; /** * Starts a Jetty servlet Engine at port 11870, only listening on localhost. * with a SigningServlet at http://127.0.0.1:11870/Signer */ public class QuickStart { public static void main(String args[]) { Frame splash = SplashWindow.splash(Toolkit.getDefaultToolkit().createImage(QuickStart.class.getClassLoader().getResource("neuclearsplash.png"))); try { Class.forName("org.neuclear.signers.standalone.StandaloneSigner") .getMethod("main", new Class[]{String[].class}) .invoke(null, new Object[]{args}); } catch (Throwable e) { e.printStackTrace(); System.err.flush(); System.exit(10); } try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } splash.dispose(); } } Index: StandaloneSigningServlet.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-signer/src/java/org/neuclear/signers/standalone/StandaloneSigningServlet.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** StandaloneSigningServlet.java 9 Apr 2004 18:40:35 -0000 1.7 --- StandaloneSigningServlet.java 14 Apr 2004 15:30:02 -0000 1.8 *************** *** 4,10 **** import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import org.neuclear.commons.crypto.passphraseagents.swing.SwingAgent; import org.neuclear.commons.crypto.signers.DefaultSigner; import org.neuclear.commons.crypto.signers.InvalidPassphraseException; - import org.neuclear.commons.crypto.signers.Signer; import org.neuclear.commons.servlets.ServletTools; import org.neuclear.id.signers.SigningServlet; --- 4,10 ---- import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import org.neuclear.commons.crypto.passphraseagents.swing.SwingAgent; + 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.servlets.ServletTools; import org.neuclear.id.signers.SigningServlet; *************** *** 29,33 **** } ! protected Signer createSigner(ServletConfig config) throws UserCancellationException { try { return new DefaultSigner(agent); --- 29,33 ---- } ! protected BrowsableSigner createSigner(ServletConfig config) throws UserCancellationException { try { return new DefaultSigner(agent); Index: StandaloneSigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-signer/src/java/org/neuclear/signers/standalone/StandaloneSigner.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** StandaloneSigner.java 14 Apr 2004 00:10:30 -0000 1.5 --- StandaloneSigner.java 14 Apr 2004 15:30:02 -0000 1.6 *************** *** 1,8 **** --- 1,17 ---- package org.neuclear.signers.standalone; + import com.jgoodies.plaf.Options; import org.mortbay.http.HttpContext; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.util.InetAddrPort; + import org.neuclear.commons.crypto.CryptoTools; + import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent; + + import javax.swing.*; + import java.awt.*; + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; + import java.net.URL; *************** *** 13,17 **** --- 22,29 ---- public class StandaloneSigner { public static void main(String args[]) { + // Frame splash=SplashWindow.splash(Toolkit.getDefaultToolkit().createImage(StandaloneSigner.class.getClassLoader().getResource("neuclearsplash.png"))); + try { + CryptoTools.ensureProvider(); Server server = new Server(); server.addListener(new InetAddrPort("127.0.0.1", 11870)); *************** *** 24,30 **** --- 36,91 ---- handler.start(); handler.initializeServlets(); + + JFrame frame = createFrame(); + + Thread.sleep(2000); + // splash.dispose(); } catch (Exception e) { e.printStackTrace(); } } + + public static JFrame createFrame() { + 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. + } + JFrame frame = new JFrame("NeuClear Signing Agent"); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + JButton quit = new JButton("Shut down"); + + quit.addActionListener(new ActionListener() { + /** + * Invoked when an action occurs. + */ + public void actionPerformed(ActionEvent e) { + System.exit(0); + + } + + }); + Container content = frame.getContentPane(); + content.setLayout(new BorderLayout()); + final URL imageurl = PassPhraseAgent.class.getClassLoader().getResource("org/neuclear/commons/crypto/passphraseagents/neuclear.png"); + JLabel label = new JLabel("NeuClear Personal Signer"); + ; + if (imageurl != null) { + final ImageIcon icon = new ImageIcon(imageurl); + frame.setIconImage(icon.getImage()); + label.setIcon(icon); + } + + label.setForeground(Color.WHITE); + label.setFont(new Font("Arial", Font.BOLD, 14)); + content.add(label, BorderLayout.NORTH); + content.add(quit, BorderLayout.SOUTH); + content.setBackground(Color.BLUE); + frame.pack(); + frame.show(); + + return frame; + + } } |