/** The jkeytool core. */
private final Core core;
+ /** The “File -> Quit” action. */
+ private Action fileQuitAction;
+
/** The “open keystore” action. */
private Action openKeystoreAction;
* 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);
JMenuBar menuBar = new JMenuBar();
menuBar.add(constructFileMenu());
+ menuBar.add(constructKeystoreMenu());
return menuBar;
}
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) {
}
}
+ /**
+ * 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
//