3190c2a426aba61306f88a3f6eb09c7f010664fa
[jkeytool.git] / src / net / pterodactylus / jkeytool / gui / swing / SwingInterface.java
1 /*
2  * jkeytool - SwingInterface.java -
3  * Copyright © 2009 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.jkeytool.gui.swing;
21
22 import java.io.File;
23 import java.security.KeyStore;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import javax.swing.JFrame;
28
29 import net.pterodactylus.jkeytool.core.Core;
30 import net.pterodactylus.jkeytool.gui.Interface;
31 import net.pterodactylus.jkeytool.main.Main;
32 import net.pterodactylus.util.swing.StatusBar;
33
34 /**
35  * TODO
36  *
37  * @author David Roden <droden@gmail.com>
38  */
39 public class SwingInterface implements Interface {
40
41         /** The core to control. */
42         private Core core;
43
44         /** The main frame. */
45         private JFrame mainFrame = new JFrame("jkeytool " + Main.getVersion());
46
47         /** The status bar. */
48         private StatusBar statusBar = new StatusBar();
49
50         /** Loaded key stores and their panels. */
51         private final Map<KeyStore, KeyStorePanel> keyStores = new HashMap<KeyStore, KeyStorePanel>();
52
53         public SwingInterface() {
54                 createFrame();
55         }
56
57         //
58         // PRIVATE METHODS
59         //
60
61         private void createFrame() {
62                 mainFrame.getContentPane().add(statusBar, BorderLayout.PAGE_END);
63                 mainFrame.pack();
64         }
65
66         //
67         // INTERFACE Interface
68         //
69
70         /**
71          * Sets the core to control.
72          *
73          * @param core
74          *            The core to control
75          */
76         public void setCore(Core core) {
77                 this.core = core;
78         }
79
80         /**
81          * {@inheritDoc}
82          */
83         public void start() {
84                 mainFrame.setVisible(true);
85                 statusBar.setText("jkeytool startup complete.");
86                 core.loadKeyStore(new File("client.p12"));
87         }
88
89         /**
90          * {@inheritDoc}
91          */
92         public void stop() {
93                 /* TODO */
94         }
95
96         //
97         // INTERFACE CoreListener
98         //
99
100         /**
101          * {@inheritDoc}
102          */
103         public void keyStoreCreated(KeyStore keyStore) {
104                 /* TODO */
105         }
106
107         /**
108          * {@inheritDoc}
109          */
110         public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) {
111                 KeyStorePanel keyStorePanel = new KeyStorePanel(keyStore);
112                 keyStores.put(keyStore, keyStorePanel);
113         }
114
115         /**
116          * {@inheritDoc}
117          */
118         public void keyStoreNotCreated(String keyStoreType, Throwable reason) {
119                 /* TODO */
120         }
121
122         /**
123          * {@inheritDoc}
124          */
125         public void keyStoreNotLoaded(File keyStoreFile) {
126                 /* TODO */
127         }
128
129 }