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;
25 import java.security.KeyStore;
26 import java.util.HashMap;
29 import javax.swing.Action;
30 import javax.swing.BorderFactory;
31 import javax.swing.JComponent;
32 import javax.swing.JFrame;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuBar;
35 import javax.swing.JPanel;
36 import javax.swing.JTabbedPane;
37 import javax.swing.JToolBar;
39 import net.pterodactylus.jkeytool.core.Core;
40 import net.pterodactylus.jkeytool.gui.Interface;
41 import net.pterodactylus.jkeytool.main.Main;
42 import net.pterodactylus.util.i18n.I18n;
43 import net.pterodactylus.util.i18n.gui.I18nAction;
44 import net.pterodactylus.util.i18n.gui.I18nMenu;
45 import net.pterodactylus.util.swing.StatusBar;
50 * @author David Roden <droden@gmail.com>
52 public class SwingInterface implements Interface {
54 /** The core to control. */
57 /** The I18n container. */
58 private I18n i18n = new I18n("jkeytool", SwingInterface.class);
60 /** The main frame. */
61 private JFrame mainFrame = new JFrame("jkeytool " + Main.getVersion());
64 private JTabbedPane tabPane = new JTabbedPane();
66 /** The status bar. */
67 private StatusBar statusBar = new StatusBar();
69 /** The “create key store” action. */
70 private Action createKeyStoreAction;
72 /** The “quit” action. */
73 private Action quitAction;
75 /** Loaded key stores and their panels. */
76 private final Map<KeyStore, KeyStorePanel> keyStores = new HashMap<KeyStore, KeyStorePanel>();
78 public SwingInterface() {
87 private void createKeyStore() {
98 private void createActions() {
99 createKeyStoreAction = new I18nAction(i18n, "jkeytool.action.createKeyStore") {
101 @SuppressWarnings("synthetic-access")
102 public void actionPerformed(ActionEvent actionEvent) {
106 quitAction = new I18nAction(i18n, "jkeytool.action.quit") {
109 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
111 @SuppressWarnings("synthetic-access")
112 public void actionPerformed(ActionEvent actionEvent) {
118 private void createFrame() {
119 mainFrame.setJMenuBar(createMenubar());
120 mainFrame.getContentPane().add(createToolbar(), BorderLayout.PAGE_START);
121 mainFrame.getContentPane().add(createCenterPanel(), BorderLayout.CENTER);
122 mainFrame.getContentPane().add(statusBar, BorderLayout.PAGE_END);
126 private JComponent createCenterPanel() {
127 JPanel centerPanel = new JPanel(new BorderLayout());
128 centerPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
130 centerPanel.add(tabPane, BorderLayout.CENTER);
135 private JMenuBar createMenubar() {
136 JMenuBar menubar = new JMenuBar();
138 JMenu fileMenu = new I18nMenu(i18n, "jkeytool.menu.file");
139 menubar.add(fileMenu);
140 fileMenu.add(createKeyStoreAction);
141 fileMenu.addSeparator();
142 fileMenu.add(quitAction);
147 private JToolBar createToolbar() {
148 JToolBar toolbar = new JToolBar();
150 toolbar.add(createKeyStoreAction);
151 toolbar.add(quitAction);
157 // INTERFACE Interface
161 * Sets the core to control.
164 * The core to control
166 public void setCore(Core core) {
173 public void start() {
174 mainFrame.setVisible(true);
175 statusBar.setText("jkeytool startup complete.");
176 core.loadKeyStore(new File("client.p12"));
187 // INTERFACE CoreListener
193 public void keyStoreCreated(KeyStore keyStore) {
200 public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) {
201 KeyStorePanel keyStorePanel = new KeyStorePanel(keyStore);
202 keyStores.put(keyStore, keyStorePanel);
203 tabPane.addTab(keyStoreFile.getName(), keyStorePanel);
209 public void keyStoreNotCreated(String keyStoreType, Throwable reason) {
216 public void keyStoreNotLoaded(File keyStoreFile) {