From: David ‘Bombe’ Roden <bombe@pterodactylus.net>
Date: Fri, 4 Apr 2008 22:07:54 +0000 (+0000)
Subject: swing interface
X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b97d649800f285ca81e79cb880b21a6db4240328;p=jSite2.git

swing interface

git-svn-id: http://trooper/svn/projects/jSite/trunk@592 c3eda9e8-030b-0410-8277-bc7414b0a119
---

diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java
new file mode 100644
index 0000000..fab1bc9
--- /dev/null
+++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java
@@ -0,0 +1,220 @@
+/*
+ * jSite2 - SwingInterface.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.jsite.gui;
+
+import java.awt.event.ActionEvent;
+import java.util.List;
+
+import javax.swing.Action;
+
+import net.pterodactylus.jsite.core.Core;
+import net.pterodactylus.jsite.core.CoreListener;
+import net.pterodactylus.jsite.core.Node;
+
+/**
+ * TODO
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class SwingInterface implements CoreListener {
+
+	/** The application core. */
+	private final Core core;
+
+	/** The main window. */
+	private MainWindow mainWindow;
+
+	/** The “manage nodes” action. */
+	private Action manageNodesAction;
+
+	/** The “connect to node” action. */
+	private Action nodeConnectAction;
+
+	/** The “disconnect from node” action. */
+	private Action nodeDisconnectAction;
+
+	/** The node manager dialog. */
+	private ManageNodesDialog manageNodesDialog;
+
+	/** The list of all defined nodes. */
+	private List<Node> nodeList;
+
+	/** The current default node. */
+	private Node defaultNode;
+
+	/**
+	 * Creates a new swing interface.
+	 * 
+	 * @param core
+	 *            The core to operate on
+	 */
+	public SwingInterface(Core core) {
+		this.core = core;
+		initActions();
+		initDialogs();
+	}
+
+	//
+	// ACCESSORS
+	//
+
+	/**
+	 * Returns the “manage nodes” action.
+	 * 
+	 * @return The “manage nodes” action
+	 */
+	public Action getManageNodesAction() {
+		return manageNodesAction;
+	}
+
+	/**
+	 * Returns the “connect to node” action.
+	 * 
+	 * @return The “connect to node” action
+	 */
+	public Action getNodeConnectAction() {
+		return nodeConnectAction;
+	}
+
+	/**
+	 * Returns the “disconnect from node” action.
+	 * 
+	 * @return The “disconnect from node” action
+	 */
+	public Action getNodeDisconnectAction() {
+		return nodeDisconnectAction;
+	}
+
+	//
+	// ACTIONS
+	//
+
+	//
+	// SERVICE METHODS
+	//
+
+	/**
+	 * Starts the interface.
+	 */
+	public void start() {
+		mainWindow = new MainWindow(this);
+	}
+
+	//
+	// PRIVATE METHODS
+	//
+
+	/**
+	 * Initializes all actions.
+	 */
+	private void initActions() {
+		manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
+
+			/**
+			 * {@inheritDoc}
+			 */
+			@SuppressWarnings("synthetic-access")
+			public void actionPerformed(ActionEvent e) {
+				manageNodes();
+			}
+		};
+		nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
+
+			@SuppressWarnings("synthetic-access")
+			public void actionPerformed(ActionEvent e) {
+				nodeConnect();
+			}
+
+		};
+		nodeDisconnectAction = new I18nAction("mainWindow.menu.node.item.disconnect", false) {
+
+			/**
+			 * {@inheritDoc}
+			 */
+			@SuppressWarnings("synthetic-access")
+			public void actionPerformed(ActionEvent e) {
+				nodeDisconnect();
+			}
+		};
+	}
+
+	/**
+	 * Initializes all child dialogs.
+	 */
+	private void initDialogs() {
+		manageNodesDialog = new ManageNodesDialog(mainWindow);
+	}
+
+	/**
+	 * Pops up the “manage nodes” dialog.
+	 */
+	private void manageNodes() {
+		manageNodesDialog.setVisible(true);
+	}
+
+	/**
+	 * Connects to the node.
+	 */
+	private void nodeConnect() {
+		core.connectToNode(null); // FIXME
+	}
+
+	/**
+	 * Disconnects from the node.
+	 */
+	private void nodeDisconnect() {
+	}
+
+	//
+	// INTERFACE CoreListener
+	//
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void coreLoaded() {
+		this.nodeList = core.getNodeList();
+		this.defaultNode = core.getDefaultNode();
+		manageNodesDialog.setNodeList(nodeList);
+		manageNodesDialog.setDefaultNode(defaultNode);
+		mainWindow.setVisible(true);
+		mainWindow.setStatusBarText("Core loaded.");
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void nodeConnected(Node node) {
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void nodeConnecting(Node node) {
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void nodeDisconnected(Node node) {
+	}
+
+}