2 * jkeytool - SwingInterface.java -
3 * Copyright © 2009 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jkeytool.gui.swing;
22 import java.awt.BorderLayout;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
27 import java.security.KeyStore;
28 import java.util.HashMap;
31 import javax.swing.Action;
32 import javax.swing.BorderFactory;
33 import javax.swing.JComponent;
34 import javax.swing.JFrame;
35 import javax.swing.JMenu;
36 import javax.swing.JMenuBar;
37 import javax.swing.JPanel;
38 import javax.swing.JTabbedPane;
39 import javax.swing.JToolBar;
41 import net.pterodactylus.jkeytool.core.Core;
42 import net.pterodactylus.jkeytool.gui.Interface;
43 import net.pterodactylus.jkeytool.main.Main;
44 import net.pterodactylus.util.i18n.I18n;
45 import net.pterodactylus.util.i18n.gui.I18nAction;
46 import net.pterodactylus.util.i18n.gui.I18nMenu;
47 import net.pterodactylus.util.swing.StatusBar;
52 * @author David Roden <droden@gmail.com>
54 public class SwingInterface implements Interface {
56 /** The core to control. */
59 /** The I18n container. */
60 private I18n i18n = new I18n("jkeytool", SwingInterface.class);
62 /** The main frame. */
63 private JFrame mainFrame = new JFrame("jkeytool " + Main.getVersion());
66 private JTabbedPane tabPane = new JTabbedPane();
68 /** The status bar. */
69 private StatusBar statusBar = new StatusBar();
71 /** The “create key store” action. */
72 private Action createKeyStoreAction;
74 /** The “quit” action. */
75 private Action quitAction;
77 /** Loaded key stores and their panels. */
78 private final Map<KeyStore, KeyStorePanel> keyStores = new HashMap<KeyStore, KeyStorePanel>();
81 * Creates a new Swing interface.
83 public SwingInterface() {
93 * Creates a new key store.
95 private void createKeyStore() {
100 * Exits the application.
102 private void quit() {
111 * Creates all used actions.
113 private void createActions() {
114 createKeyStoreAction = new I18nAction(i18n, "jkeytool.action.createKeyStore") {
116 @SuppressWarnings("synthetic-access")
117 public void actionPerformed(ActionEvent actionEvent) {
121 quitAction = new I18nAction(i18n, "jkeytool.action.quit") {
124 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
126 @SuppressWarnings("synthetic-access")
127 public void actionPerformed(ActionEvent actionEvent) {
134 * Creates the application main frame.
136 private void createFrame() {
137 mainFrame.setJMenuBar(createMenubar());
138 mainFrame.getContentPane().add(createToolbar(), BorderLayout.PAGE_START);
139 mainFrame.getContentPane().add(createCenterPanel(), BorderLayout.CENTER);
140 mainFrame.getContentPane().add(statusBar, BorderLayout.PAGE_END);
142 mainFrame.addWindowListener(new WindowAdapter() {
148 @SuppressWarnings("synthetic-access")
149 public void windowClosing(WindowEvent windowEvent) {
156 * Creates the central panel of the frame.
158 * @return The central panel of the frame
160 private JComponent createCenterPanel() {
161 JPanel centerPanel = new JPanel(new BorderLayout());
162 centerPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
164 centerPanel.add(tabPane, BorderLayout.CENTER);
170 * Creates the menu bar of the frame.
172 * @return The menu bar of the frame
174 private JMenuBar createMenubar() {
175 JMenuBar menubar = new JMenuBar();
177 JMenu fileMenu = new I18nMenu(i18n, "jkeytool.menu.file");
178 menubar.add(fileMenu);
179 fileMenu.add(createKeyStoreAction);
180 fileMenu.addSeparator();
181 fileMenu.add(quitAction);
187 * Creates the tool bar of the frame.
189 * @return The tool bar of the frame
191 private JToolBar createToolbar() {
192 JToolBar toolbar = new JToolBar();
194 toolbar.add(createKeyStoreAction);
195 toolbar.add(quitAction);
201 // INTERFACE Interface
205 * Sets the core to control.
208 * The core to control
210 public void setCore(Core core) {
217 public void start() {
218 mainFrame.setVisible(true);
219 statusBar.setText("jkeytool startup complete.");
220 core.loadKeyStore(new File("client.p12"));
231 // INTERFACE CoreListener
237 public void keyStoreCreated(KeyStore keyStore) {
244 public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) {
245 KeyStorePanel keyStorePanel = new KeyStorePanel(i18n, keyStore);
246 keyStores.put(keyStore, keyStorePanel);
247 tabPane.addTab(keyStoreFile.getName(), keyStorePanel);
253 public void keyStoreNotCreated(String keyStoreType, Throwable reason) {
260 public void keyStoreNotLoaded(File keyStoreFile) {