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