current main window
[jSite2.git] / src / net / pterodactylus / jsite / gui / MainWindow.java
1 /*
2  * jSite2 - MainWindow.java -
3  * Copyright © 2008 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.jsite.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24
25 import javax.swing.JFrame;
26 import javax.swing.JMenu;
27 import javax.swing.JMenuBar;
28
29 import net.pterodactylus.jsite.i18n.I18n;
30 import net.pterodactylus.jsite.main.Version;
31 import net.pterodactylus.util.swing.StatusBar;
32 import net.pterodactylus.util.swing.SwingUtils;
33
34 /**
35  * Defines the main window of the application.
36  * 
37  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
38  * @version $Id$
39  */
40 public class MainWindow extends JFrame {
41
42         /** The swing interface that receives all actions. */
43         private final SwingInterface swingInterface;
44
45         /** The status bar. */
46         private StatusBar statusBar = new StatusBar();
47
48         /**
49          * Creates a new main window that redirects all actions to the given swing
50          * interface.
51          * 
52          * @param swingInterface
53          *            The swing interface to receive all actions
54          */
55         public MainWindow(SwingInterface swingInterface) {
56                 super("jSite " + Version.getVersion());
57                 this.swingInterface = swingInterface;
58                 initWindow();
59                 setPreferredSize(new Dimension(480, 280));
60                 pack();
61                 SwingUtils.center(this);
62                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
63         }
64
65         //
66         // ACCESSORS
67         //
68
69         /**
70          * Sets the text of the status bar.
71          * 
72          * @param text
73          *            The text of the status bar
74          */
75         public void setStatusBarText(String text) {
76                 statusBar.setText(text);
77         }
78
79         //
80         // PRIVATE METHODS
81         //
82
83         /**
84          * Initializes the window by creating all its components.
85          */
86         private void initWindow() {
87                 JMenuBar menuBar = new JMenuBar();
88
89                 final JMenu nodeMenu = new JMenu(I18n.get("mainWindow.menu.node.name"));
90                 menuBar.add(nodeMenu);
91                 nodeMenu.setMnemonic(I18n.get("mainWindow.menu.node.mnemonic").charAt(0));
92
93                 nodeMenu.add(swingInterface.getManageNodesAction());
94                 nodeMenu.addSeparator();
95                 nodeMenu.add(swingInterface.getNodeConnectAction());
96                 nodeMenu.add(swingInterface.getNodeDisconnectAction());
97
98                 setJMenuBar(menuBar);
99                 initComponents();
100         }
101
102         /**
103          * Initializes all components of this window.
104          */
105         private void initComponents() {
106                 getContentPane().add(statusBar, BorderLayout.PAGE_END);
107         }
108
109 }