From: David ‘Bombe’ Roden Date: Mon, 26 Jan 2009 23:24:22 +0000 (+0100) Subject: Remove old user interface code. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=890be90f28fe14e240f86a14a1660cb526f14db1;p=jkeytool.git Remove old user interface code. --- diff --git a/src/net/pterodactylus/jkeytool/gui/AbstractKeyStorePanel.java b/src/net/pterodactylus/jkeytool/gui/AbstractKeyStorePanel.java deleted file mode 100644 index 8eece78..0000000 --- a/src/net/pterodactylus/jkeytool/gui/AbstractKeyStorePanel.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * jkeytool - KeystoreWindow.java - - * Copyright © 2009 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jkeytool.gui; - -import java.awt.BorderLayout; -import java.security.KeyStore; - -import javax.swing.JPanel; - -/** - * A {@link JPanel} that displays all key store entries and information about - * them. - * - * @author David Roden <droden@gmail.com> - */ -public abstract class AbstractKeyStorePanel extends JPanel { - - /** The key store. */ - protected final KeyStore keyStore; - - /** - * Creates a new key store panel. - * - * @param keyStore - * The key store to display - */ - protected AbstractKeyStorePanel(KeyStore keyStore) { - super(new BorderLayout()); - this.keyStore = keyStore; - } - - // - // SUBCLASS METHODS - // - - /** - * Creates the panel that lets the user select a key store entry and adds it - * to this key store panel. The created panel should be placed in the - * {@link BorderLayout#WEST} or {@link BorderLayout#NORTH} area of the key - * store panel. - */ - protected abstract void createEntryPanel(); - - // - // PROTECTED METHODS - // - - /** - * Called by a subclass when a key store entry has been selected. - * - * @param alias - * The selected key store entry alias, or null if no - * entry has been selected or the selection has been cleared - */ - protected void selectedEntry(String alias) { - System.out.println(alias); - } - - /** - * Creates the content panels. - */ - protected void construct() { - createEntryPanel(); - } - - // - // PRIVATE METHODS - // - -} diff --git a/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java b/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java deleted file mode 100644 index d935b01..0000000 --- a/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * jkeytool - ListKeyStorePanel.java - - * Copyright © 2009 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jkeytool.gui; - -import java.awt.BorderLayout; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.util.Collections; - -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -/** - * TODO - * - * @author David Roden <droden@gmail.com> - */ -public class ListKeyStorePanel extends AbstractKeyStorePanel implements ListSelectionListener { - - /** The list model containing all aliases. */ - private final DefaultListModel listModel = new DefaultListModel(); - - /** The list. */ - private final JList entryList = new JList(listModel); - - /** - * Creates a new key store panel that displays all entry aliases in a list. - * - * @param keyStore - * The key store to display - */ - public ListKeyStorePanel(KeyStore keyStore) { - super(keyStore); - try { - for (String alias : Collections.list(keyStore.aliases())) { - listModel.addElement(alias); - } - } catch (KeyStoreException kse1) { - kse1.printStackTrace(); - } - construct(); - entryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - entryList.addListSelectionListener(this); - } - - /** - * {@inheritDoc} - */ - @Override - protected void createEntryPanel() { - add(entryList, BorderLayout.WEST); - } - - // - // INTERFACE ListSelectionListener - // - - /** - * {@inheritDoc} - */ - public void valueChanged(ListSelectionEvent listSelectionEvent) { - if (listSelectionEvent.getValueIsAdjusting()) { - return; - } - Object object = entryList.getSelectedValue(); - selectedEntry((String) object); - } - -} diff --git a/src/net/pterodactylus/jkeytool/gui/MainFrame.java b/src/net/pterodactylus/jkeytool/gui/MainFrame.java deleted file mode 100644 index cd6052a..0000000 --- a/src/net/pterodactylus/jkeytool/gui/MainFrame.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * jkeytool - MainWindow.java - - * Copyright © 2009 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jkeytool.gui; - -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.beans.PropertyVetoException; -import java.io.File; -import java.security.KeyStore; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JDesktopPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; - -import net.pterodactylus.jkeytool.core.Core; -import net.pterodactylus.jkeytool.core.CoreListener; -import net.pterodactylus.jkeytool.main.Main; - -/** - * The jkeytool main frame. - * - * @author David Roden <droden@gmail.com> - */ -public class MainFrame implements CoreListener, WindowListener { - - /** Object used for synchronization. */ - private final Object syncObject = new Object(); - - /** The main frame. */ - private final JFrame mainFrame; - - /** The main frame’s desktop. */ - private final JDesktopPane desktop; - - /** The jkeytool core. */ - private final Core core; - - /** The “File -> Quit” action. */ - private Action fileQuitAction; - - /** The “open keystore” action. */ - private Action openKeystoreAction; - - /** The last directory when opening keystores. */ - private File lastOpenKeystoreDirectory = null; - - /** - * Creates a new jkeytool main frame. - * - * @param core - * The core of the jkeytool application - */ - public MainFrame(Core core) { - this.core = core; - mainFrame = new JFrame("jkeytool " + Main.getVersion()); - constructActions(); - mainFrame.setJMenuBar(constructMenuBar()); - mainFrame.addWindowListener(this); - desktop = new JDesktopPane(); - mainFrame.setContentPane(desktop); - mainFrame.pack(); - } - - // - // ACTIONS - // - - /** - * Shows the main frame. - */ - public void show() { - mainFrame.setVisible(true); - } - - // - // PRIVATE METHODS - // - - /** - * 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) { - actionKeystoreOpen(); - } - }; - openKeystoreAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O); - openKeystoreAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); - } - - /** - * Creates the menu bar. - * - * @return The menu bar - */ - private JMenuBar constructMenuBar() { - JMenuBar menuBar = new JMenuBar(); - - menuBar.add(constructFileMenu()); - menuBar.add(constructKeystoreMenu()); - - return menuBar; - } - - /** - * Creates the “File” menu. - * - * @return The “File” menu - */ - private JMenu constructFileMenu() { - JMenu fileMenu = new JMenu("File"); - - 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 void constructKeyStoreWindow(KeyStore keyStore) { - JInternalFrame internalFrame = new JInternalFrame("Key Store (" + keyStore.getType() + ")", true, true, true, true); - internalFrame.getContentPane().add(new ListKeyStorePanel(keyStore)); - internalFrame.setBounds(10, 10, 200, 200); - desktop.add(internalFrame); - internalFrame.setVisible(true); - try { - internalFrame.setSelected(true); - } catch (PropertyVetoException pve1) { - pve1.printStackTrace(); - } - } - - // - // 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 actionKeystoreOpen() { - File directory; - synchronized (syncObject) { - if (lastOpenKeystoreDirectory == null) { - lastOpenKeystoreDirectory = new File("."); - } - directory = lastOpenKeystoreDirectory; - } - JFileChooser fileChooser = new JFileChooser(directory); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setMultiSelectionEnabled(false); - int returnedOption = fileChooser.showOpenDialog(mainFrame); - if (returnedOption != JFileChooser.APPROVE_OPTION) { - return; - } - core.loadKeyStore(fileChooser.getSelectedFile()); - synchronized (syncObject) { - lastOpenKeystoreDirectory = fileChooser.getCurrentDirectory(); - } - } - - /** - * 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 - // - - /** - * {@inheritDoc} - */ - public void keyStoreCreated(KeyStore keyStore) { - constructKeyStoreWindow(keyStore); - } - - /** - * {@inheritDoc} - */ - public void keyStoreNotCreated(String keyStoreType, Throwable reason) { - JOptionPane.showMessageDialog(mainFrame, "Could not create a key store of type “" + keyStoreType + "”.", "Could Not Create Key Store", JOptionPane.ERROR_MESSAGE); - } - - /** - * {@inheritDoc} - */ - public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) { - constructKeyStoreWindow(keyStore); - } - - /** - * {@inheritDoc} - */ - public void keyStoreNotLoaded(File keyStoreFile) { - JOptionPane.showMessageDialog(mainFrame, "Could not load key store from “" + keyStoreFile.getName() + "”.", "Could Not Load Key Store", JOptionPane.ERROR_MESSAGE); - } - - // - // INTERFACE WindowListener - // - - /** - * {@inheritDoc} - */ - public void windowActivated(WindowEvent e) { - /* ignore. */ - } - - /** - * {@inheritDoc} - */ - public void windowClosed(WindowEvent e) { - /* ignore. */ - } - - /** - * {@inheritDoc} - */ - public void windowClosing(WindowEvent e) { - System.exit(0); - } - - /** - * {@inheritDoc} - */ - public void windowDeactivated(WindowEvent e) { - /* ignore. */ - } - - /** - * {@inheritDoc} - */ - public void windowDeiconified(WindowEvent e) { - /* ignore. */ - } - - /** - * {@inheritDoc} - */ - public void windowIconified(WindowEvent e) { - /* ignore. */ - } - - /** - * {@inheritDoc} - */ - public void windowOpened(WindowEvent e) { - /* ignore. */ - } - -}