2 * jSite2 - SwingInterface.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.event.ActionEvent;
23 import java.util.List;
25 import net.pterodactylus.jsite.core.Core;
26 import net.pterodactylus.jsite.core.CoreListener;
27 import net.pterodactylus.jsite.core.Node;
32 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
35 public class SwingInterface implements CoreListener {
37 /** The application core. */
38 private final Core core;
40 /** The main window. */
41 private MainWindow mainWindow;
43 /** The “manage nodes” action. */
44 private I18nAction manageNodesAction;
46 /** The “connect to node” action. */
47 private I18nAction nodeConnectAction;
49 /** The “disconnect from node” action. */
50 private I18nAction nodeDisconnectAction;
52 /** The node manager dialog. */
53 private ManageNodesDialog manageNodesDialog;
55 /** The list of all defined nodes. */
56 private List<Node> nodeList;
59 * Creates a new swing interface.
62 * The core to operate on
64 public SwingInterface(Core core) {
75 * Returns the core that is controlled by the Swing interface.
84 * Returns the main window of the Swing interface.
86 * @return The main window
88 MainWindow getMainWindow() {
93 * Returns the “manage nodes” action.
95 * @return The “manage nodes” action
97 I18nAction getManageNodesAction() {
98 return manageNodesAction;
102 * Returns the “connect to node” action.
104 * @return The “connect to node” action
106 I18nAction getNodeConnectAction() {
107 return nodeConnectAction;
111 * Returns the “disconnect from node” action.
113 * @return The “disconnect from node” action
115 I18nAction getNodeDisconnectAction() {
116 return nodeDisconnectAction;
128 * Starts the interface.
130 public void start() {
131 mainWindow = new MainWindow(this);
139 * Initializes all actions.
141 private void initActions() {
142 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
147 @SuppressWarnings("synthetic-access")
148 public void actionPerformed(ActionEvent e) {
152 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
154 @SuppressWarnings("synthetic-access")
155 public void actionPerformed(ActionEvent e) {
160 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
165 @SuppressWarnings("synthetic-access")
166 public void actionPerformed(ActionEvent e) {
173 * Initializes all child dialogs.
175 private void initDialogs() {
176 manageNodesDialog = new ManageNodesDialog(this);
180 * Pops up the “manage nodes” dialog.
182 private void manageNodes() {
183 manageNodesDialog.setNodeList(nodeList);
184 manageNodesDialog.setVisible(true);
185 nodeList = manageNodesDialog.getNodeList();
189 * Connects to the node.
191 private void nodeConnect() {
195 * Disconnects from the node.
197 private void nodeDisconnect() {
201 // INTERFACE CoreListener
207 public void coreLoaded() {
208 this.nodeList = core.getNodes();
209 manageNodesDialog.setNodeList(nodeList);
210 mainWindow.setVisible(true);
211 mainWindow.setStatusBarText("Core loaded.");
217 public void nodeConnected(Node node) {
223 public void nodeConnecting(Node node) {
229 public void nodeDisconnected(Node node) {