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         /** The current default node. */
61         private Node defaultNode;
62
63         /**
64          * Creates a new swing interface.
65          * 
66          * @param core
67          *            The core to operate on
68          */
69         public SwingInterface(Core core) {
70                 this.core = core;
71                 initActions();
72                 initDialogs();
73         }
74
75         //
76         // ACCESSORS
77         //
78
79         /**
80          * Returns the “manage nodes” action.
81          * 
82          * @return The “manage nodes” action
83          */
84         public Action getManageNodesAction() {
85                 return manageNodesAction;
86         }
87
88         /**
89          * Returns the “connect to node” action.
90          * 
91          * @return The “connect to node” action
92          */
93         public Action getNodeConnectAction() {
94                 return nodeConnectAction;
95         }
96
97         /**
98          * Returns the “disconnect from node” action.
99          * 
100          * @return The “disconnect from node” action
101          */
102         public Action getNodeDisconnectAction() {
103                 return nodeDisconnectAction;
104         }
105
106         //
107         // ACTIONS
108         //
109
110         //
111         // SERVICE METHODS
112         //
113
114         /**
115          * Starts the interface.
116          */
117         public void start() {
118                 mainWindow = new MainWindow(this);
119         }
120
121         //
122         // PRIVATE METHODS
123         //
124
125         /**
126          * Initializes all actions.
127          */
128         private void initActions() {
129                 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
130
131                         /**
132                          * {@inheritDoc}
133                          */
134                         @SuppressWarnings("synthetic-access")
135                         public void actionPerformed(ActionEvent e) {
136                                 manageNodes();
137                         }
138                 };
139                 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
140
141                         @SuppressWarnings("synthetic-access")
142                         public void actionPerformed(ActionEvent e) {
143                                 nodeConnect();
144                         }
145
146                 };
147                 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
148
149                         /**
150                          * {@inheritDoc}
151                          */
152                         @SuppressWarnings("synthetic-access")
153                         public void actionPerformed(ActionEvent e) {
154                                 nodeDisconnect();
155                         }
156                 };
157         }
158
159         /**
160          * Initializes all child dialogs.
161          */
162         private void initDialogs() {
163                 manageNodesDialog = new ManageNodesDialog(mainWindow);
164         }
165
166         /**
167          * Pops up the “manage nodes” dialog.
168          */
169         private void manageNodes() {
170                 manageNodesDialog.setVisible(true);
171         }
172
173         /**
174          * Connects to the node.
175          */
176         private void nodeConnect() {
177                 core.connectToNode(null); // FIXME
178         }
179
180         /**
181          * Disconnects from the node.
182          */
183         private void nodeDisconnect() {
184         }
185
186         //
187         // INTERFACE CoreListener
188         //
189
190         /**
191          * {@inheritDoc}
192          */
193         public void coreLoaded() {
194                 this.nodeList = core.getNodeList();
195                 this.defaultNode = core.getDefaultNode();
196                 manageNodesDialog.setNodeList(nodeList);
197                 manageNodesDialog.setDefaultNode(defaultNode);
198                 mainWindow.setVisible(true);
199                 mainWindow.setStatusBarText("Core loaded.");
200         }
201
202         /**
203          * {@inheritDoc}
204          */
205         public void nodeConnected(Node node) {
206         }
207
208         /**
209          * {@inheritDoc}
210          */
211         public void nodeConnecting(Node node) {
212         }
213
214         /**
215          * {@inheritDoc}
216          */
217         public void nodeDisconnected(Node node) {
218         }
219
220 }