extract interface from core
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 3 May 2008 19:50:57 +0000 (19:50 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 3 May 2008 19:50:57 +0000 (19:50 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@785 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/Core.java [deleted file]
src/net/pterodactylus/jsite/core/CoreImpl.java [new file with mode: 0644]
src/net/pterodactylus/jsite/main/Main.java

diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java
deleted file mode 100644 (file)
index 9aa60cf..0000000
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * jSite2 - Core.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.core;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The core of jSite.
- *
- * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
- * @version $Id$
- */
-public class Core {
-
-       /** The core listeners. */
-       private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
-
-       /** The project manager. */
-       private ProjectManager projectManager;
-
-       /** The node manager. */
-       private NodeManager nodeManager;
-
-       //
-       // LISTENER MANAGEMENT
-       //
-
-       /**
-        * Adds the given listener to the list of registered listeners.
-        *
-        * @param coreListener
-        *            The listener to add
-        */
-       public void addCoreListener(CoreListener coreListener) {
-               coreListeners.add(coreListener);
-       }
-
-       /**
-        * Removes the given listener from the list of registered listeners.
-        *
-        * @param coreListener
-        *            The listener to remove
-        */
-       public void removeCoreListener(CoreListener coreListener) {
-               coreListeners.remove(coreListener);
-       }
-
-       /**
-        * Notifies all listeners that the projects were loaded successfully.
-        *
-        * @param directory
-        *            The directory the projects were loaded from
-        */
-       private void fireLoadingProjectsDone(String directory) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.loadingProjectsDone(directory);
-               }
-       }
-
-       /**
-        * Notifies all core listeners that loading the projects from the given
-        * directory has failed.
-        *
-        * @param directory
-        *            The directory the projects were tried to load from
-        * @param throwable
-        *            The exception that occured when loading projects
-        */
-       private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.loadingProjectsFailed(directory, throwable);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the projects were successfully saved.
-        *
-        * @param directory
-        *            The directory the projects were saved to
-        */
-       private void fireSavingProjectsDone(String directory) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.savingProjectsDone(directory);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the projects could not be saved.
-        *
-        * @param directory
-        *            The directory the projects were to be saved to
-        * @param throwable
-        *            The exception that occured when saving the projects
-        */
-       private void fireSavingProjectsFailed(String directory, Throwable throwable) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.savingProjectsFailed(directory, throwable);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the nodes were successfully loaded.
-        *
-        * @param directory
-        *            The directory the nodes were loaded from
-        */
-       private void fireLoadingNodesDone(String directory) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.loadingNodesDone(directory);
-               }
-       }
-
-       /**
-        * Notifies all listeners that loading the nodes has failed.
-        *
-        * @param directory
-        *            The directory the nodes were loaded from
-        * @param throwable
-        *            The exception that occured while loading the nodes
-        */
-       private void fireLoadingNodesFailed(String directory, Throwable throwable) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.loadingNodesFailed(directory, throwable);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the nodes were saved successfully.
-        *
-        * @param directory
-        *            The directory the nodes were saved to
-        */
-       private void fireSavingNodesDone(String directory) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.savingNodesDone(directory);
-               }
-       }
-
-       /**
-        * Notifies all listeners that saving the nodes has failed.
-        *
-        * @param directory
-        *            The directory the nodes were saved to
-        * @param throwable
-        *            The exception that occured while saving the nodes
-        */
-       private void fireSavingNodesFailed(String directory, Throwable throwable) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.savingProjectsFailed(directory, throwable);
-               }
-       }
-
-       /**
-        * Notifies all core listeners that the core has loaded and is ready to run.
-        */
-       private void fireCoreLoaded() {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.coreLoaded();
-               }
-       }
-
-       /**
-        * Notifies all listeners that the core was stopped.
-        */
-       private void fireCoreStopped() {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.coreStopped();
-               }
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       /**
-        * Returns the project manager.
-        *
-        * @return The project manager
-        */
-       public ProjectManager getProjectManager() {
-               return projectManager;
-       }
-
-       /**
-        * Sets the project manager to use.
-        *
-        * @param projectManager
-        *            The project manager to use
-        */
-       public void setProjectManager(ProjectManager projectManager) {
-               this.projectManager = projectManager;
-       }
-
-       /**
-        * Returns the node manager.
-        *
-        * @return The node manager
-        */
-       public NodeManager getNodeManager() {
-               return nodeManager;
-       }
-
-       /**
-        * Sets the node manager to use.
-        *
-        * @param nodeManager
-        *            The node manager to use
-        */
-       public void setNodeManager(NodeManager nodeManager) {
-               this.nodeManager = nodeManager;
-       }
-
-       /**
-        * Returns the list of all configured nodes.
-        *
-        * @return All configured nodes
-        */
-       public List<Node> getNodes() {
-               return nodeManager.getNodes();
-       }
-
-       /**
-        * Returns whether the core is currently connected to the given node.
-        *
-        * @param node
-        *            The node to check
-        * @return <code>true</code> if the core is currently connected to the
-        *         node, <code>false</code> otherwise
-        */
-       public boolean isNodeConnected(Node node) {
-               return nodeManager.hasNode(node);
-       }
-
-       //
-       // ACTIONS
-       //
-
-       /**
-        * Starts the core.
-        */
-       public void start() {
-               try {
-                       projectManager.load();
-                       fireLoadingProjectsDone(projectManager.getDirectory());
-               } catch (IOException ioe1) {
-                       fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1);
-               }
-               try {
-                       nodeManager.load();
-                       fireLoadingNodesDone(nodeManager.getDirectory());
-               } catch (IOException ioe1) {
-                       fireLoadingNodesFailed(nodeManager.getDirectory(), ioe1);
-               }
-               fireCoreLoaded();
-       }
-
-       /**
-        * Stops the core.
-        */
-       public void stop() {
-               try {
-                       projectManager.save();
-                       fireSavingProjectsDone(projectManager.getDirectory());
-               } catch (IOException ioe1) {
-                       fireSavingProjectsFailed(projectManager.getDirectory(), ioe1);
-               }
-               try {
-                       nodeManager.save();
-                       fireSavingNodesDone(nodeManager.getDirectory());
-               } catch (IOException ioe1) {
-                       fireSavingNodesFailed(nodeManager.getDirectory(), ioe1);
-               }
-               fireCoreStopped();
-       }
-
-       /**
-        * Connects to the given node.
-        *
-        * @param node
-        *            The node to connect to
-        */
-       public void connectToNode(Node node) {
-               /* TODO */
-       }
-
-       //
-       // PRIVATE METHODS
-       //
-
-       /**
-        * Loads the configuration.
-        */
-       @SuppressWarnings("unused")
-       private void loadConfig() {
-               /* TODO */
-       }
-
-       /**
-        * Saves the configuration.
-        */
-       @SuppressWarnings("unused")
-       private void saveConfig() {
-               /* TODO */
-       }
-
-}
diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java
new file mode 100644 (file)
index 0000000..8b79d3e
--- /dev/null
@@ -0,0 +1,309 @@
+/*
+ * jSite2 - Core.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.core;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The core of jSite.
+ *
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class CoreImpl implements Core {
+
+       /** The core listeners. */
+       private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
+
+       /** The project manager. */
+       private ProjectManager projectManager;
+
+       /** The node manager. */
+       private NodeManager nodeManager;
+
+       //
+       // LISTENER MANAGEMENT
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       public void addCoreListener(CoreListener coreListener) {
+               coreListeners.add(coreListener);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void removeCoreListener(CoreListener coreListener) {
+               coreListeners.remove(coreListener);
+       }
+
+       /**
+        * Notifies all listeners that the projects were loaded successfully.
+        *
+        * @param directory
+        *            The directory the projects were loaded from
+        */
+       private void fireLoadingProjectsDone(String directory) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.loadingProjectsDone(directory);
+               }
+       }
+
+       /**
+        * Notifies all core listeners that loading the projects from the given
+        * directory has failed.
+        *
+        * @param directory
+        *            The directory the projects were tried to load from
+        * @param throwable
+        *            The exception that occured when loading projects
+        */
+       private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.loadingProjectsFailed(directory, throwable);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the projects were successfully saved.
+        *
+        * @param directory
+        *            The directory the projects were saved to
+        */
+       private void fireSavingProjectsDone(String directory) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.savingProjectsDone(directory);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the projects could not be saved.
+        *
+        * @param directory
+        *            The directory the projects were to be saved to
+        * @param throwable
+        *            The exception that occured when saving the projects
+        */
+       private void fireSavingProjectsFailed(String directory, Throwable throwable) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.savingProjectsFailed(directory, throwable);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the nodes were successfully loaded.
+        *
+        * @param directory
+        *            The directory the nodes were loaded from
+        */
+       private void fireLoadingNodesDone(String directory) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.loadingNodesDone(directory);
+               }
+       }
+
+       /**
+        * Notifies all listeners that loading the nodes has failed.
+        *
+        * @param directory
+        *            The directory the nodes were loaded from
+        * @param throwable
+        *            The exception that occured while loading the nodes
+        */
+       private void fireLoadingNodesFailed(String directory, Throwable throwable) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.loadingNodesFailed(directory, throwable);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the nodes were saved successfully.
+        *
+        * @param directory
+        *            The directory the nodes were saved to
+        */
+       private void fireSavingNodesDone(String directory) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.savingNodesDone(directory);
+               }
+       }
+
+       /**
+        * Notifies all listeners that saving the nodes has failed.
+        *
+        * @param directory
+        *            The directory the nodes were saved to
+        * @param throwable
+        *            The exception that occured while saving the nodes
+        */
+       private void fireSavingNodesFailed(String directory, Throwable throwable) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.savingProjectsFailed(directory, throwable);
+               }
+       }
+
+       /**
+        * Notifies all core listeners that the core has loaded and is ready to run.
+        */
+       private void fireCoreLoaded() {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.coreLoaded();
+               }
+       }
+
+       /**
+        * Notifies all listeners that the core was stopped.
+        */
+       private void fireCoreStopped() {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.coreStopped();
+               }
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns the project manager.
+        *
+        * @return The project manager
+        */
+       public ProjectManager getProjectManager() {
+               return projectManager;
+       }
+
+       /**
+        * Sets the project manager to use.
+        *
+        * @param projectManager
+        *            The project manager to use
+        */
+       public void setProjectManager(ProjectManager projectManager) {
+               this.projectManager = projectManager;
+       }
+
+       /**
+        * Returns the node manager.
+        *
+        * @return The node manager
+        */
+       public NodeManager getNodeManager() {
+               return nodeManager;
+       }
+
+       /**
+        * Sets the node manager to use.
+        *
+        * @param nodeManager
+        *            The node manager to use
+        */
+       public void setNodeManager(NodeManager nodeManager) {
+               this.nodeManager = nodeManager;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public List<Node> getNodes() {
+               return nodeManager.getNodes();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public boolean isNodeConnected(Node node) {
+               return nodeManager.hasNode(node);
+       }
+
+       //
+       // ACTIONS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       public void start() {
+               try {
+                       projectManager.load();
+                       fireLoadingProjectsDone(projectManager.getDirectory());
+               } catch (IOException ioe1) {
+                       fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1);
+               }
+               try {
+                       nodeManager.load();
+                       fireLoadingNodesDone(nodeManager.getDirectory());
+               } catch (IOException ioe1) {
+                       fireLoadingNodesFailed(nodeManager.getDirectory(), ioe1);
+               }
+               fireCoreLoaded();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void stop() {
+               try {
+                       projectManager.save();
+                       fireSavingProjectsDone(projectManager.getDirectory());
+               } catch (IOException ioe1) {
+                       fireSavingProjectsFailed(projectManager.getDirectory(), ioe1);
+               }
+               try {
+                       nodeManager.save();
+                       fireSavingNodesDone(nodeManager.getDirectory());
+               } catch (IOException ioe1) {
+                       fireSavingNodesFailed(nodeManager.getDirectory(), ioe1);
+               }
+               fireCoreStopped();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void connectToNode(Node node) {
+               /* TODO */
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
+        * Loads the configuration.
+        */
+       @SuppressWarnings("unused")
+       private void loadConfig() {
+               /* TODO */
+       }
+
+       /**
+        * Saves the configuration.
+        */
+       @SuppressWarnings("unused")
+       private void saveConfig() {
+               /* TODO */
+       }
+
+}
index 0c7e637..42012e1 100644 (file)
@@ -21,7 +21,7 @@ package net.pterodactylus.jsite.main;
 
 import java.io.File;
 
-import net.pterodactylus.jsite.core.Core;
+import net.pterodactylus.jsite.core.CoreImpl;
 import net.pterodactylus.jsite.core.NodeManager;
 import net.pterodactylus.jsite.core.ProjectManager;
 import net.pterodactylus.jsite.gui.SwingInterface;
@@ -48,7 +48,7 @@ public class Main {
         * Starts the core and the default {@link SwingInterface}.
         */
        private void start() {
-               Core core = new Core();
+               CoreImpl core = new CoreImpl();
 
                String configDirectory = System.getProperty("user.home") + File.separator + ".jSite";