X-Git-Url: https://git.pterodactylus.net/?p=jkeytool.git;a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjkeytool%2Fgui%2Fswing%2FSwingInterface.java;h=107dc8d1938ad15b39bff7eb3044cf9a6d29d228;hp=388846d75724142cef087a82cdc594e599c2c5fd;hb=7255bdf4430ded3abfbc342f15ccd9091b9617b7;hpb=8aa34340dda1029328137a73e42fe37995665869 diff --git a/src/net/pterodactylus/jkeytool/gui/swing/SwingInterface.java b/src/net/pterodactylus/jkeytool/gui/swing/SwingInterface.java index 388846d..107dc8d 100644 --- a/src/net/pterodactylus/jkeytool/gui/swing/SwingInterface.java +++ b/src/net/pterodactylus/jkeytool/gui/swing/SwingInterface.java @@ -19,10 +19,25 @@ package net.pterodactylus.jkeytool.gui.swing; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; import java.io.File; import java.security.KeyStore; +import java.util.HashMap; +import java.util.Map; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; + +import net.pterodactylus.jkeytool.core.Core; import net.pterodactylus.jkeytool.gui.Interface; +import net.pterodactylus.jkeytool.main.Main; +import net.pterodactylus.util.i18n.gui.I18nAction; +import net.pterodactylus.util.swing.StatusBar; /** * TODO @@ -31,14 +46,109 @@ import net.pterodactylus.jkeytool.gui.Interface; */ public class SwingInterface implements Interface { + /** The core to control. */ + private Core core; + + /** The main frame. */ + private JFrame mainFrame = new JFrame("jkeytool " + Main.getVersion()); + + /** The tab pane. */ + private JTabbedPane tabPane = new JTabbedPane(); + + /** The status bar. */ + private StatusBar statusBar = new StatusBar(); + + /** The “create key store” action. */ + private Action createKeyStoreAction; + + /** The “quit” action. */ + private Action quitAction; + + /** Loaded key stores and their panels. */ + private final Map keyStores = new HashMap(); + + public SwingInterface() { + createActions(); + createFrame(); + } + + // + // ACTIONS + // + + private void createKeyStore() { + } + + private void quit() { + System.exit(0); + } + + // + // PRIVATE METHODS + // + + private void createActions() { + createKeyStoreAction = new I18nAction("jkeytool.action.createKeyStore") { + + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + createKeyStore(); + } + }; + quitAction = new I18nAction("jkeytool.action.quit") { + + /** + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + quit(); + } + }; + } + + private void createFrame() { + mainFrame.getContentPane().add(createCenterPanel(), BorderLayout.CENTER); + mainFrame.getContentPane().add(statusBar, BorderLayout.PAGE_END); + mainFrame.pack(); + } + + private JComponent createCenterPanel() { + JPanel centerPanel = new JPanel(new BorderLayout()); + centerPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); + + centerPanel.add(tabPane, BorderLayout.CENTER); + + return centerPanel; + } + // // INTERFACE Interface // /** + * Sets the core to control. + * + * @param core + * The core to control + */ + public void setCore(Core core) { + this.core = core; + } + + /** * {@inheritDoc} */ public void start() { + mainFrame.setVisible(true); + statusBar.setText("jkeytool startup complete."); + core.loadKeyStore(new File("client.p12")); + } + + /** + * {@inheritDoc} + */ + public void stop() { /* TODO */ } @@ -57,7 +167,9 @@ public class SwingInterface implements Interface { * {@inheritDoc} */ public void keyStoreLoaded(File keyStoreFile, KeyStore keyStore) { - /* TODO */ + KeyStorePanel keyStorePanel = new KeyStorePanel(keyStore); + keyStores.put(keyStore, keyStorePanel); + tabPane.addTab(keyStoreFile.getName(), keyStorePanel); } /**