added more german i18n
[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 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27
28 import javax.swing.Box;
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JFrame;
32 import javax.swing.JMenuBar;
33 import javax.swing.JPanel;
34 import javax.swing.JTabbedPane;
35 import javax.swing.JToolBar;
36 import javax.swing.SwingConstants;
37 import javax.swing.border.EmptyBorder;
38
39 import net.pterodactylus.jsite.core.Project;
40 import net.pterodactylus.jsite.i18n.I18n;
41 import net.pterodactylus.jsite.i18n.I18nable;
42 import net.pterodactylus.jsite.i18n.gui.I18nAction;
43 import net.pterodactylus.jsite.i18n.gui.I18nMenu;
44 import net.pterodactylus.jsite.main.Version;
45 import net.pterodactylus.util.swing.StatusBar;
46 import net.pterodactylus.util.swing.SwingUtils;
47
48 /**
49  * Defines the main window of the application.
50  *
51  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
52  * @version $Id$
53  */
54 public class MainWindow extends JFrame implements I18nable {
55
56         /** The swing interface that receives all actions. */
57         private final SwingInterface swingInterface;
58
59         /** The status bar. */
60         private StatusBar statusBar = new StatusBar();
61
62         /** The content pane. */
63         private JPanel contentPane = new JPanel(new BorderLayout(12, 12));
64
65         /** The jSite menu. */
66         private I18nMenu jSiteMenu;
67
68         /** The node menu. */
69         private I18nMenu nodeMenu;
70
71         /** The language menu. */
72         private I18nMenu languageMenu;
73
74         /** The about menu. */
75         private I18nMenu helpMenu;
76
77         /** The tabbed project pane. */
78         private JTabbedPane projectPane;
79
80         /** The project overview panel. */
81         private Box projectOverviewPanel;
82
83         /**
84          * Creates a new main window that redirects all actions to the given swing
85          * interface.
86          *
87          * @param swingInterface
88          *            The swing interface to receive all actions
89          */
90         public MainWindow(SwingInterface swingInterface) {
91                 super("jSite " + Version.getVersion());
92                 this.swingInterface = swingInterface;
93                 initWindow();
94                 setPreferredSize(new Dimension(480, 280));
95                 pack();
96                 SwingUtils.center(this);
97                 I18n.registerI18nable(this);
98                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
99         }
100
101         //
102         // ACCESSORS
103         //
104
105         /**
106          * Sets the text of the status bar.
107          *
108          * @param text
109          *            The text of the status bar
110          */
111         public void setStatusBarText(String text) {
112                 statusBar.setText(text);
113         }
114
115         /**
116          * {@inheritDoc}
117          */
118         @Override
119         public Container getContentPane() {
120                 return contentPane;
121         }
122
123         /**
124          * Returns the currently selected project.
125          *
126          * @return The currently selected project
127          */
128         public Project getSelectedProject() {
129                 return null;
130         }
131
132         //
133         // PRIVATE METHODS
134         //
135
136         /**
137          * Initializes the window by creating all its components.
138          */
139         private void initWindow() {
140                 JMenuBar menuBar = new JMenuBar();
141
142                 jSiteMenu = new I18nMenu("mainWindow.menu.jSite");
143                 menuBar.add(jSiteMenu);
144
145                 jSiteMenu.add(new FixedJMenuItem(swingInterface.getConfigureAction()));
146                 jSiteMenu.addSeparator();
147                 jSiteMenu.add(new FixedJMenuItem(swingInterface.getImportConfigAction()));
148                 jSiteMenu.addSeparator();
149                 jSiteMenu.add(new FixedJMenuItem(swingInterface.getQuitAction()));
150
151                 nodeMenu = new I18nMenu("mainWindow.menu.node");
152                 menuBar.add(nodeMenu);
153
154                 nodeMenu.add(new FixedJMenuItem(swingInterface.getManageNodesAction()));
155                 nodeMenu.addSeparator();
156                 nodeMenu.add(new FixedJMenuItem(swingInterface.getNodeConnectAction()));
157                 nodeMenu.add(new FixedJMenuItem(swingInterface.getNodeDisconnectAction()));
158
159                 languageMenu = new I18nMenu("mainWindow.menu.language");
160                 menuBar.add(languageMenu);
161
162                 for (I18nAction languageAction: swingInterface.getLanguageActions()) {
163                         languageMenu.add(new FixedJMenuItem(languageAction));
164                 }
165
166                 JPanel spacerPanel = new JPanel();
167                 spacerPanel.setOpaque(false);
168                 menuBar.add(spacerPanel);
169
170                 helpMenu = new I18nMenu("mainWindow.menu.help");
171                 menuBar.add(helpMenu);
172
173                 helpMenu.add(new FixedJMenuItem(swingInterface.getHelpAboutAction()));
174
175                 setJMenuBar(menuBar);
176
177                 JToolBar toolBar = new JToolBar(I18n.get("mainWindow.toolbar.name"));
178                 toolBar.add(swingInterface.getManageNodesAction());
179                 toolBar.addSeparator();
180                 toolBar.add(swingInterface.getNodeConnectAction());
181                 toolBar.add(swingInterface.getNodeDisconnectAction());
182                 super.getContentPane().add(toolBar, BorderLayout.PAGE_START);
183
184                 super.getContentPane().add(contentPane, BorderLayout.CENTER);
185
186                 addWindowListener(new WindowAdapter() {
187
188                         /**
189                          * {@inheritDoc}
190                          */
191                         @SuppressWarnings("synthetic-access")
192                         @Override
193                         public void windowClosing(WindowEvent windowEvent) {
194                                 swingInterface.getQuitAction().actionPerformed(null);
195                         }
196                 });
197
198                 initComponents();
199         }
200
201         /**
202          * Initializes all components of this window.
203          */
204         private void initComponents() {
205                 super.getContentPane().add(statusBar, BorderLayout.PAGE_END);
206
207                 /*
208                  * the main window consists of two panels which are vertically oriented.
209                  * the upper panel contains of a tabbed pane, the lower panel consists
210                  * of a table that lists the running requests.
211                  */
212
213                 JPanel upperPanel = new JPanel(new BorderLayout(12, 12));
214                 getContentPane().add(upperPanel, BorderLayout.PAGE_START);
215                 contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
216
217                 projectPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
218                 upperPanel.add(projectPane, BorderLayout.CENTER);
219
220                 projectOverviewPanel = new Box(BoxLayout.PAGE_AXIS);
221                 projectOverviewPanel.setName(I18n.get("mainWindow.pane.overview.title"));
222                 projectPane.add(projectOverviewPanel);
223                 projectOverviewPanel.setBorder(new EmptyBorder(12, 12, 12, 12));
224                 projectOverviewPanel.add(Box.createVerticalGlue());
225                 JButton addProjectButton = new JButton(swingInterface.getAddProjectAction());
226                 addProjectButton.setAlignmentX(0.5f);
227                 projectOverviewPanel.add(addProjectButton);
228                 projectOverviewPanel.add(Box.createVerticalGlue());
229
230 // JPanel lowerPanel = new JPanel(new BorderLayout(12, 12));
231 // getContentPane().add(lowerPanel, BorderLayout.CENTER);
232         }
233
234         //
235         // INTERFACE I18nable
236         //
237
238         /**
239          * {@inheritDoc}
240          */
241         public void updateI18n() {
242                 swingInterface.getConfigureAction().updateI18n();
243                 swingInterface.getImportConfigAction().updateI18n();
244                 swingInterface.getQuitAction().updateI18n();
245                 swingInterface.getManageNodesAction().updateI18n();
246                 swingInterface.getNodeConnectAction().updateI18n();
247                 swingInterface.getNodeDisconnectAction().updateI18n();
248                 swingInterface.getAddProjectAction().updateI18n();
249                 swingInterface.getCloneProjectAction().updateI18n();
250                 swingInterface.getDeleteProjectAction().updateI18n();
251                 swingInterface.getHelpAboutAction().updateI18n();
252                 jSiteMenu.updateI18n();
253                 nodeMenu.updateI18n();
254                 languageMenu.updateI18n();
255                 for (I18nAction languageAction: swingInterface.getLanguageActions()) {
256                         languageAction.updateI18n();
257                 }
258                 helpMenu.updateI18n();
259                 getJMenuBar().revalidate();
260                 projectOverviewPanel.setName(I18n.get("mainWindow.pane.overview.title"));
261                 for (int componentIndex = 0; componentIndex < projectPane.getTabCount(); componentIndex++) {
262                         projectPane.setTitleAt(componentIndex, projectPane.getComponentAt(componentIndex).getName());
263                 }
264                 SwingUtils.repackCentered(this);
265         }
266
267 }