make the GUI update its texts when a new language is chosen
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
1 /*
2  * jSite2 - SwingInterface.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.event.ActionEvent;
23 import java.util.List;
24
25 import net.pterodactylus.jsite.core.Core;
26 import net.pterodactylus.jsite.core.CoreListener;
27 import net.pterodactylus.jsite.core.Node;
28
29 /**
30  * TODO
31  * 
32  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33  * @version $Id$
34  */
35 public class SwingInterface implements CoreListener {
36
37         /** The application core. */
38         private final Core core;
39
40         /** The main window. */
41         private MainWindow mainWindow;
42
43         /** The “manage nodes” action. */
44         private I18nAction manageNodesAction;
45
46         /** The “connect to node” action. */
47         private I18nAction nodeConnectAction;
48
49         /** The “disconnect from node” action. */
50         private I18nAction nodeDisconnectAction;
51
52         /** The node manager dialog. */
53         private ManageNodesDialog manageNodesDialog;
54
55         /** The list of all defined nodes. */
56         private List<Node> nodeList;
57
58         /**
59          * Creates a new swing interface.
60          * 
61          * @param core
62          *            The core to operate on
63          */
64         public SwingInterface(Core core) {
65                 this.core = core;
66                 initActions();
67                 initDialogs();
68         }
69
70         //
71         // ACCESSORS
72         //
73
74         /**
75          * Returns the core that is controlled by the Swing interface.
76          * 
77          * @return The core
78          */
79         Core getCore() {
80                 return core;
81         }
82
83         /**
84          * Returns the main window of the Swing interface.
85          * 
86          * @return The main window
87          */
88         MainWindow getMainWindow() {
89                 return mainWindow;
90         }
91
92         /**
93          * Returns the “manage nodes” action.
94          * 
95          * @return The “manage nodes” action
96          */
97         I18nAction getManageNodesAction() {
98                 return manageNodesAction;
99         }
100
101         /**
102          * Returns the “connect to node” action.
103          * 
104          * @return The “connect to node” action
105          */
106         I18nAction getNodeConnectAction() {
107                 return nodeConnectAction;
108         }
109
110         /**
111          * Returns the “disconnect from node” action.
112          * 
113          * @return The “disconnect from node” action
114          */
115         I18nAction getNodeDisconnectAction() {
116                 return nodeDisconnectAction;
117         }
118
119         //
120         // ACTIONS
121         //
122
123         //
124         // SERVICE METHODS
125         //
126
127         /**
128          * Starts the interface.
129          */
130         public void start() {
131                 mainWindow = new MainWindow(this);
132         }
133
134         //
135         // PRIVATE METHODS
136         //
137
138         /**
139          * Initializes all actions.
140          */
141         private void initActions() {
142                 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
143
144                         /**
145                          * {@inheritDoc}
146                          */
147                         @SuppressWarnings("synthetic-access")
148                         public void actionPerformed(ActionEvent e) {
149                                 manageNodes();
150                         }
151                 };
152                 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
153
154                         @SuppressWarnings("synthetic-access")
155                         public void actionPerformed(ActionEvent e) {
156                                 nodeConnect();
157                         }
158
159                 };
160                 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
161
162                         /**
163                          * {@inheritDoc}
164                          */
165                         @SuppressWarnings("synthetic-access")
166                         public void actionPerformed(ActionEvent e) {
167                                 nodeDisconnect();
168                         }
169                 };
170         }
171
172         /**
173          * Initializes all child dialogs.
174          */
175         private void initDialogs() {
176                 manageNodesDialog = new ManageNodesDialog(this);
177         }
178
179         /**
180          * Pops up the “manage nodes” dialog.
181          */
182         private void manageNodes() {
183                 manageNodesDialog.setNodeList(nodeList);
184                 manageNodesDialog.setVisible(true);
185                 nodeList = manageNodesDialog.getNodeList();
186         }
187
188         /**
189          * Connects to the node.
190          */
191         private void nodeConnect() {
192         }
193
194         /**
195          * Disconnects from the node.
196          */
197         private void nodeDisconnect() {
198         }
199
200         //
201         // INTERFACE CoreListener
202         //
203
204         /**
205          * {@inheritDoc}
206          */
207         public void coreLoaded() {
208                 this.nodeList = core.getNodes();
209                 manageNodesDialog.setNodeList(nodeList);
210                 mainWindow.setVisible(true);
211                 mainWindow.setStatusBarText("Core loaded.");
212         }
213
214         /**
215          * {@inheritDoc}
216          */
217         public void nodeConnected(Node node) {
218         }
219
220         /**
221          * {@inheritDoc}
222          */
223         public void nodeConnecting(Node node) {
224         }
225
226         /**
227          * {@inheritDoc}
228          */
229         public void nodeDisconnected(Node node) {
230         }
231
232 }