Add “File -> Quit” action.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jan 2009 22:42:39 +0000 (23:42 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jan 2009 22:42:39 +0000 (23:42 +0100)
Add “Key Store -> New” actions.

src/net/pterodactylus/jkeytool/gui/MainFrame.java

index cfbccee..d477726 100644 (file)
@@ -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
        //