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