2 * jSite2 - MainWindow.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.Container;
24 import java.awt.Dimension;
26 import javax.swing.JFrame;
27 import javax.swing.JMenuBar;
28 import javax.swing.JPanel;
29 import javax.swing.JToolBar;
31 import net.pterodactylus.jsite.i18n.I18n;
32 import net.pterodactylus.jsite.i18n.I18nable;
33 import net.pterodactylus.jsite.main.Version;
34 import net.pterodactylus.util.swing.StatusBar;
35 import net.pterodactylus.util.swing.SwingUtils;
38 * Defines the main window of the application.
40 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
43 public class MainWindow extends JFrame implements I18nable {
45 /** The swing interface that receives all actions. */
46 private final SwingInterface swingInterface;
48 /** The status bar. */
49 private StatusBar statusBar = new StatusBar();
51 /** The content pane. */
52 private JPanel contentPane = new JPanel();
55 private I18nMenu nodeMenu;
57 /** The language menu. */
58 private I18nMenu languageMenu;
61 * Creates a new main window that redirects all actions to the given swing
64 * @param swingInterface
65 * The swing interface to receive all actions
67 public MainWindow(SwingInterface swingInterface) {
68 super("jSite " + Version.getVersion());
69 this.swingInterface = swingInterface;
71 setPreferredSize(new Dimension(480, 280));
73 SwingUtils.center(this);
74 I18n.registerI18nable(this);
75 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
83 * Sets the text of the status bar.
86 * The text of the status bar
88 public void setStatusBarText(String text) {
89 statusBar.setText(text);
97 * Initializes the window by creating all its components.
99 private void initWindow() {
100 JMenuBar menuBar = new JMenuBar();
102 nodeMenu = new I18nMenu("mainWindow.menu.node");
103 menuBar.add(nodeMenu);
105 nodeMenu.add(swingInterface.getManageNodesAction());
106 nodeMenu.addSeparator();
107 nodeMenu.add(swingInterface.getNodeConnectAction());
108 nodeMenu.add(swingInterface.getNodeDisconnectAction());
110 languageMenu = new I18nMenu("mainWindow.menu.language");
111 menuBar.add(languageMenu);
113 for (I18nAction languageAction: swingInterface.getLanguageActions()) {
114 languageMenu.add(languageAction);
117 setJMenuBar(menuBar);
119 JToolBar toolBar = new JToolBar(I18n.get("mainWindow.toolbar.name"));
120 toolBar.add(swingInterface.getManageNodesAction());
121 toolBar.addSeparator();
122 toolBar.add(swingInterface.getNodeConnectAction());
123 toolBar.add(swingInterface.getNodeDisconnectAction());
124 super.getContentPane().add(toolBar, BorderLayout.PAGE_START);
126 super.getContentPane().add(contentPane, BorderLayout.CENTER);
131 * Initializes all components of this window.
133 private void initComponents() {
134 super.getContentPane().add(statusBar, BorderLayout.PAGE_END);
141 public Container getContentPane() {
146 // INTERFACE I18nable
152 public void updateI18n() {
153 swingInterface.getManageNodesAction().updateI18n();
154 swingInterface.getNodeConnectAction().updateI18n();
155 swingInterface.getNodeDisconnectAction().updateI18n();
156 nodeMenu.updateI18n();
157 languageMenu.updateI18n();
158 getJMenuBar().revalidate();
159 SwingUtils.repackCentered(this);