From ef96023a38c8d148103212c5196f771a847f58f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 19 Jan 2009 23:42:39 +0100 Subject: [PATCH] =?utf8?q?Add=20=E2=80=9CFile=20->=20Quit=E2=80=9D=20actio?= =?utf8?q?n.=20Add=20=E2=80=9CKey=20Store=20->=20New=E2=80=9D=20actions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/net/pterodactylus/jkeytool/gui/MainFrame.java | 86 ++++++++++++++++++++++- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/src/net/pterodactylus/jkeytool/gui/MainFrame.java b/src/net/pterodactylus/jkeytool/gui/MainFrame.java index cfbccee..d477726 100644 --- a/src/net/pterodactylus/jkeytool/gui/MainFrame.java +++ b/src/net/pterodactylus/jkeytool/gui/MainFrame.java @@ -56,6 +56,9 @@ public class MainFrame implements CoreListener, WindowListener { /** The jkeytool core. */ private final Core core; + /** The “File -> Quit” action. */ + private Action fileQuitAction; + /** The “open keystore” action. */ private Action openKeystoreAction; @@ -96,11 +99,24 @@ public class MainFrame implements CoreListener, WindowListener { * Constructs all actions. */ private void constructActions() { + fileQuitAction = new AbstractAction("Quit") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + actionFileQuit(); + } + }; + fileQuitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_Q); + fileQuitAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); + openKeystoreAction = new AbstractAction("Open Keystore") { @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - openKeystore(); + actionKeystoreOpen(); } }; openKeystoreAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O); @@ -116,6 +132,7 @@ public class MainFrame implements CoreListener, WindowListener { JMenuBar menuBar = new JMenuBar(); menuBar.add(constructFileMenu()); + menuBar.add(constructKeystoreMenu()); return menuBar; } @@ -128,15 +145,67 @@ public class MainFrame implements CoreListener, WindowListener { private JMenu constructFileMenu() { JMenu fileMenu = new JMenu("File"); - fileMenu.add(openKeystoreAction); + fileMenu.add(fileQuitAction); return fileMenu; } /** + * Creates the “Key Store” menu. + * + * @return The “Key Store” menu + */ + private JMenu constructKeystoreMenu() { + JMenu keystoreMenu = new JMenu("Key Store"); + + keystoreMenu.add(constructNewKeystoreTypeMenu()); + keystoreMenu.add(openKeystoreAction); + + return keystoreMenu; + } + + /** + * Creates a new menu containing all the types for new key stores. + * + * @return A menu containing all new key store types + */ + private JMenu constructNewKeystoreTypeMenu() { + JMenu keystoreTypeMenu = new JMenu("New Key Store"); + keystoreTypeMenu.setMnemonic(KeyEvent.VK_N); + + for (final String keystoreType : new String[] { "JKS", "PKCS12" }) { + Action keystoreTypeAction = new AbstractAction(keystoreType) { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + actionNewKeystore(keystoreType); + } + }; + keystoreTypeMenu.add(keystoreTypeAction); + } + + return keystoreTypeMenu; + } + + // + // PRIVATE ACTIONS + // + + /** + * Quits the program. + */ + private void actionFileQuit() { + /* TODO - ask for confirmation. */ + System.exit(0); + } + + /** * Shows a file selection dialog and loads a keystore from a file. */ - private void openKeystore() { + private void actionKeystoreOpen() { File directory; synchronized (syncObject) { if (lastOpenKeystoreDirectory == null) { @@ -157,6 +226,17 @@ public class MainFrame implements CoreListener, WindowListener { } } + /** + * Tells the core to create a new key store. + * + * @see Core#createKeyStore(String) + * @param keystoreType + * The type of the key store + */ + private void actionNewKeystore(String keystoreType) { + core.createKeyStore(keystoreType); + } + // // INTERFACE CoreListener // -- 2.7.4