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