package net.pterodactylus.jsite.gui;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+
import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+
+import net.pterodactylus.jsite.i18n.I18n;
+import net.pterodactylus.jsite.main.Version;
+import net.pterodactylus.util.swing.StatusBar;
+import net.pterodactylus.util.swing.SwingUtils;
/**
* Defines the main window of the application.
*/
public class MainWindow extends JFrame {
+ /** The swing interface that receives all actions. */
+ private final SwingInterface swingInterface;
+
+ /** The status bar. */
+ private StatusBar statusBar = new StatusBar();
+
+ /**
+ * Creates a new main window that redirects all actions to the given swing
+ * interface.
+ *
+ * @param swingInterface
+ * The swing interface to receive all actions
+ */
+ public MainWindow(SwingInterface swingInterface) {
+ super("jSite " + Version.getVersion());
+ this.swingInterface = swingInterface;
+ initWindow();
+ setPreferredSize(new Dimension(480, 280));
+ pack();
+ SwingUtils.center(this);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Sets the text of the status bar.
+ *
+ * @param text
+ * The text of the status bar
+ */
+ public void setStatusBarText(String text) {
+ statusBar.setText(text);
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Initializes the window by creating all its components.
+ */
+ private void initWindow() {
+ JMenuBar menuBar = new JMenuBar();
+
+ final JMenu nodeMenu = new JMenu(I18n.get("mainWindow.menu.node.name"));
+ menuBar.add(nodeMenu);
+ nodeMenu.setMnemonic(I18n.get("mainWindow.menu.node.mnemonic").charAt(0));
+
+ nodeMenu.add(swingInterface.getManageNodesAction());
+ nodeMenu.addSeparator();
+ nodeMenu.add(swingInterface.getNodeConnectAction());
+ nodeMenu.add(swingInterface.getNodeDisconnectAction());
+
+ setJMenuBar(menuBar);
+ initComponents();
+ }
+
+ /**
+ * Initializes all components of this window.
+ */
+ private void initComponents() {
+ getContentPane().add(statusBar, BorderLayout.PAGE_END);
+ }
+
}