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 “manage nodes” action.
79 * @return The “manage nodes” action
81 public Action getManageNodesAction() {
82 return manageNodesAction;
86 * Returns the “connect to node” action.
88 * @return The “connect to node” action
90 public Action getNodeConnectAction() {
91 return nodeConnectAction;
95 * Returns the “disconnect from node” action.
97 * @return The “disconnect from node” action
99 public Action getNodeDisconnectAction() {
100 return nodeDisconnectAction;
112 * Starts the interface.
114 public void start() {
115 mainWindow = new MainWindow(this);
123 * Initializes all actions.
125 private void initActions() {
126 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
131 @SuppressWarnings("synthetic-access")
132 public void actionPerformed(ActionEvent e) {
136 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
138 @SuppressWarnings("synthetic-access")
139 public void actionPerformed(ActionEvent e) {
144 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
149 @SuppressWarnings("synthetic-access")
150 public void actionPerformed(ActionEvent e) {
157 * Initializes all child dialogs.
159 private void initDialogs() {
160 manageNodesDialog = new ManageNodesDialog(mainWindow);
164 * Pops up the “manage nodes” dialog.
166 private void manageNodes() {
167 manageNodesDialog.setNodeList(nodeList);
168 manageNodesDialog.setVisible(true);
169 nodeList = manageNodesDialog.getNodeList();
173 * Connects to the node.
175 private void nodeConnect() {
179 * Disconnects from the node.
181 private void nodeDisconnect() {
185 // INTERFACE CoreListener
191 public void coreLoaded() {
192 this.nodeList = core.getNodes();
193 manageNodesDialog.setNodeList(nodeList);
194 mainWindow.setVisible(true);
195 mainWindow.setStatusBarText("Core loaded.");
201 public void nodeConnected(Node node) {
207 public void nodeConnecting(Node node) {
213 public void nodeDisconnected(Node node) {