6a6597e30e867cd471cb2c4a5f10635f9d9f42fd
[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.awt.BorderLayout;
23 import java.io.File;
24 import java.security.KeyStore;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import javax.swing.BorderFactory;
29 import javax.swing.JComponent;
30 import javax.swing.JFrame;
31 import javax.swing.JPanel;
32 import javax.swing.JTabbedPane;
33
34 import net.pterodactylus.jkeytool.core.Core;
35 import net.pterodactylus.jkeytool.gui.Interface;
36 import net.pterodactylus.jkeytool.main.Main;
37 import net.pterodactylus.util.swing.StatusBar;
38
39 /**
40  * TODO
41  *
42  * @author David Roden <droden@gmail.com>
43  */
44 public class SwingInterface implements Interface {
45
46         /** The core to control. */
47         private Core core;
48
49         /** The main frame. */
50         private JFrame mainFrame = new JFrame("jkeytool " + Main.getVersion());
51
52         /** The tab pane. */
53         private JTabbedPane tabPane = new JTabbedPane();
54
55         /** The status bar. */
56         private StatusBar statusBar = new StatusBar();
57
58         /** Loaded key stores and their panels. */
59         private final Map<KeyStore, KeyStorePanel> keyStores = new HashMap<KeyStore, KeyStorePanel>();
60
61         public SwingInterface() {
62                 createFrame();
63         }
64
65         //
66         // PRIVATE METHODS
67         //
68
69         private void createFrame() {
70                 mainFrame.getContentPane().add(createCenterPanel(), BorderLayout.CENTER);
71                 mainFrame.getContentPane().add(statusBar, BorderLayout.PAGE_END);
72                 mainFrame.pack();
73         }
74
75         private JComponent createCenterPanel() {
76                 JPanel centerPanel = new JPanel(new BorderLayout());
77                 centerPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
78
79                 centerPanel.add(tabPane, BorderLayout.CENTER);
80
81                 return centerPanel;
82         }
83
84         //
85         // INTERFACE Interface
86         //
87
88         /**
89          * Sets the core to control.
90          *
91          * @param core
92          *            The core to control
93          */
94         public void setCore(Core core) {
95                 this.core = core;
96         }
97
98         /**
99          * {@inheritDoc}
100          */
101         public void start() {
102                 mainFrame.setVisible(true);
103                 statusBar.setText("jkeytool startup complete.");
104                 core.loadKeyStore(new File("client.p12"));
105         }
106
107         /**
108          * {@inheritDoc}
109          */
110         public void stop() {
111                 /* TODO */
112         }
113
114         //
115         // INTERFACE CoreListener
116         //
117
118         /**
119          * {@inheritDoc}
120          */
121         public void keyStoreCreated(KeyStore keyStore) {
122                 /* TODO */
123         }
124
125         /**
126          * {@inheritDoc}
127          */
128         public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) {
129                 KeyStorePanel keyStorePanel = new KeyStorePanel(keyStore);
130                 keyStores.put(keyStore, keyStorePanel);
131                 tabPane.addTab(keyStoreFile.getName(), keyStorePanel);
132         }
133
134         /**
135          * {@inheritDoc}
136          */
137         public void keyStoreNotCreated(String keyStoreType, Throwable reason) {
138                 /* TODO */
139         }
140
141         /**
142          * {@inheritDoc}
143          */
144         public void keyStoreNotLoaded(File keyStoreFile) {
145                 /* TODO */
146         }
147
148 }