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 javax.swing.Action;
27 import net.pterodactylus.jsite.core.Core;
28 import net.pterodactylus.jsite.core.CoreListener;
29 import net.pterodactylus.jsite.core.Node;
34 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
37 public class SwingInterface implements CoreListener {
39 /** The application core. */
40 private final Core core;
42 /** The main window. */
43 private MainWindow mainWindow;
45 /** The “manage nodes” action. */
46 private Action manageNodesAction;
48 /** The “connect to node” action. */
49 private Action nodeConnectAction;
51 /** The “disconnect from node” action. */
52 private Action nodeDisconnectAction;
54 /** The node manager dialog. */
55 private ManageNodesDialog manageNodesDialog;
57 /** The list of all defined nodes. */
58 private List<Node> nodeList;
61 * Creates a new swing interface.
64 * The core to operate on
66 public SwingInterface(Core core) {
77 * Returns the core that is controlled by the Swing interface.
86 * Returns the main window of the Swing interface.
88 * @return The main window
90 MainWindow getMainWindow() {
95 * Returns the “manage nodes” action.
97 * @return The “manage nodes” action
99 Action getManageNodesAction() {
100 return manageNodesAction;
104 * Returns the “connect to node” action.
106 * @return The “connect to node” action
108 Action getNodeConnectAction() {
109 return nodeConnectAction;
113 * Returns the “disconnect from node” action.
115 * @return The “disconnect from node” action
117 Action getNodeDisconnectAction() {
118 return nodeDisconnectAction;
130 * Starts the interface.
132 public void start() {
133 mainWindow = new MainWindow(this);
141 * Initializes all actions.
143 private void initActions() {
144 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
149 @SuppressWarnings("synthetic-access")
150 public void actionPerformed(ActionEvent e) {
154 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
156 @SuppressWarnings("synthetic-access")
157 public void actionPerformed(ActionEvent e) {
162 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
167 @SuppressWarnings("synthetic-access")
168 public void actionPerformed(ActionEvent e) {
175 * Initializes all child dialogs.
177 private void initDialogs() {
178 manageNodesDialog = new ManageNodesDialog(this);
182 * Pops up the “manage nodes” dialog.
184 private void manageNodes() {
185 manageNodesDialog.setNodeList(nodeList);
186 manageNodesDialog.setVisible(true);
187 nodeList = manageNodesDialog.getNodeList();
191 * Connects to the node.
193 private void nodeConnect() {
197 * Disconnects from the node.
199 private void nodeDisconnect() {
203 // INTERFACE CoreListener
209 public void coreLoaded() {
210 this.nodeList = core.getNodes();
211 manageNodesDialog.setNodeList(nodeList);
212 mainWindow.setVisible(true);
213 mainWindow.setStatusBarText("Core loaded.");
219 public void nodeConnected(Node node) {
225 public void nodeConnecting(Node node) {
231 public void nodeDisconnected(Node node) {