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;
60 /** The current default node. */
61 private Node defaultNode;
64 * Creates a new swing interface.
67 * The core to operate on
69 public SwingInterface(Core core) {
80 * Returns the “manage nodes” action.
82 * @return The “manage nodes” action
84 public Action getManageNodesAction() {
85 return manageNodesAction;
89 * Returns the “connect to node” action.
91 * @return The “connect to node” action
93 public Action getNodeConnectAction() {
94 return nodeConnectAction;
98 * Returns the “disconnect from node” action.
100 * @return The “disconnect from node” action
102 public Action getNodeDisconnectAction() {
103 return nodeDisconnectAction;
115 * Starts the interface.
117 public void start() {
118 mainWindow = new MainWindow(this);
126 * Initializes all actions.
128 private void initActions() {
129 manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
134 @SuppressWarnings("synthetic-access")
135 public void actionPerformed(ActionEvent e) {
139 nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
141 @SuppressWarnings("synthetic-access")
142 public void actionPerformed(ActionEvent e) {
147 nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
152 @SuppressWarnings("synthetic-access")
153 public void actionPerformed(ActionEvent e) {
160 * Initializes all child dialogs.
162 private void initDialogs() {
163 manageNodesDialog = new ManageNodesDialog(mainWindow);
167 * Pops up the “manage nodes” dialog.
169 private void manageNodes() {
170 manageNodesDialog.setVisible(true);
174 * Connects to the node.
176 private void nodeConnect() {
177 core.connectToNode(null); // FIXME
181 * Disconnects from the node.
183 private void nodeDisconnect() {
187 // INTERFACE CoreListener
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.");
205 public void nodeConnected(Node node) {
211 public void nodeConnecting(Node node) {
217 public void nodeDisconnected(Node node) {