|
From: <jan...@us...> - 2008-01-01 15:05:09
|
Revision: 706
http://magicmap.svn.sourceforge.net/magicmap/?rev=706&view=rev
Author: jan_fride
Date: 2008-01-01 07:04:39 -0800 (Tue, 01 Jan 2008)
Log Message:
-----------
added get method and iterator for edges.
Modified Paths:
--------------
trunk/magicmapclient/src/net/sf/magicmap/client/model/location/INodePlacer.java
trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/JungNodePlacer.java
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/model/location/INodePlacer.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/model/location/INodePlacer.java 2007-12-31 17:59:57 UTC (rev 705)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/model/location/INodePlacer.java 2008-01-01 15:04:39 UTC (rev 706)
@@ -18,20 +18,20 @@
* @author Jan Friderici
*
*/
-public interface INodePlacer {
+public interface INodePlacer extends Iterable<IMagicEdge>{
/**
* Fügt einen neuen Knoten ein.
*
* @param node der neue Knoten.
*/
- public void insertNode(Node node);
+ void insertNode(Node node);
/**
* Löscht einen Knoten.
* @param node
*/
- public void deleteNode(Node node);
+ void deleteNode(Node node);
/**
* Legt eine gerichtete Kante zwischen den beiden Knoten an.
@@ -40,14 +40,22 @@
* @param n2 das Ziel der Kante
* @return
*/
- public IMagicEdge addEdge(Node n1, Node n2);
+ IMagicEdge addEdge(Node n1, Node n2);
/**
+ * <p>Find the ege connecting the two given nodes.</p>
+ * @param n1 first node
+ * @param n2 secnd node
+ * @return the connecting edge or null.
+ */
+ IMagicEdge getEdge(Node n1, Node n2);
+
+ /**
* Löscht eine gerichtete Kante. (also nur eine Richtung).
- * @param n1
- * @param n2
+ * @param n1 first node
+ * @param n2 second node
*/
- public void removeEdge(Node n1, Node n2);
+ void removeEdge(Node n1, Node n2);
/**
* Die Größe des Layoutalgorithmus sollte der der Karte
@@ -56,43 +64,58 @@
* @param width die Breite (der Karte).
* @param height die Höhe (der Karte).
*/
- public void setSize(int width, int height);
+ void setSize(int width, int height);
/**
* Starts the algorithm.
*
*/
- public abstract void startNodePlacer();
+ void startNodePlacer();
/**
* Stops the algorithm
*
*/
- public abstract void stopNodePlacer();
+ void stopNodePlacer();
/**
*
* @param pause
*/
- public abstract void pauseNodePlacer(boolean pause);
+ void pauseNodePlacer(boolean pause);
/**
*
* @return
*/
- public boolean isPaused();
+ boolean isPaused();
/**
* Adds a handler for node updates.
* @param handler
*/
- public void addNodeUpdateHandler(NodeUpdateHandler handler);
+ void addNodeUpdateHandler(NodeUpdateHandler handler);
- public NodeMetricManager getMetricManager();
-
- public void updateNode(Node node, int type, Object data);
- static final class NodeHandlerFactory {
+ /**
+ *
+ * @return the metric manager for this layout.
+ */
+ NodeMetricManager getMetricManager();
+ /**
+ *
+ * @param node
+ * @param type
+ * @param data
+ */
+ void updateNode(Node node, int type, Object data);
+
+
+ /**
+ *
+ */
+ static final class NodeHandlerFactory {
+
public final HashMap<Integer, NodeUpdateHandler> handlerMap;
public NodeHandlerFactory() {
@@ -124,5 +147,9 @@
return this.handlerMap.get(type);
}
}
- public void clear();;
+
+ /**
+ * <p>Remove all nodes and edges...</p>
+ */
+ void clear();
}
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/JungNodePlacer.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/JungNodePlacer.java 2007-12-31 17:59:57 UTC (rev 705)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/JungNodePlacer.java 2008-01-01 15:04:39 UTC (rev 706)
@@ -1,49 +1,31 @@
package net.sf.magicmap.client.model.location.jung;
-import java.awt.Dimension;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
+import edu.uci.ics.jung.graph.Edge;
+import edu.uci.ics.jung.graph.Vertex;
+import edu.uci.ics.jung.graph.decorators.StringLabeller;
+import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
+import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
+import edu.uci.ics.jung.utils.UserData;
+import edu.uci.ics.jung.visualization.SpringLayout;
import net.sf.magicmap.client.algorithms.MagicMetric;
import net.sf.magicmap.client.algorithms.NodeMetricManager;
import net.sf.magicmap.client.algorithms.NodeModelMetric;
-import net.sf.magicmap.client.controller.Controller;
import net.sf.magicmap.client.model.location.INodePlacer;
import net.sf.magicmap.client.model.location.NodeUpdateHandler;
-import net.sf.magicmap.client.model.location.jung.handler.AccessPointHiddenStateHandler;
-import net.sf.magicmap.client.model.location.jung.handler.CalculationStateHandler;
-import net.sf.magicmap.client.model.location.jung.handler.FixStateHandler;
-import net.sf.magicmap.client.model.location.jung.handler.LabelChangeHandler;
-import net.sf.magicmap.client.model.location.jung.handler.NotSeeAccessPointHandler;
-import net.sf.magicmap.client.model.location.jung.handler.PositionUpdateHandler;
-import net.sf.magicmap.client.model.location.jung.handler.SeeAccessPointHandler;
-import net.sf.magicmap.client.model.node.ClientNode;
-import net.sf.magicmap.client.model.node.IMagicEdge;
-import net.sf.magicmap.client.model.node.LocationNode;
-import net.sf.magicmap.client.model.node.MapNode;
-import net.sf.magicmap.client.model.node.Node;
-import net.sf.magicmap.client.model.node.NodeModelConstants;
-
+import net.sf.magicmap.client.model.location.jung.handler.*;
+import net.sf.magicmap.client.model.node.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import edu.uci.ics.jung.graph.Edge;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.graph.decorators.StringLabeller;
-import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
-import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
-import edu.uci.ics.jung.utils.UserData;
-import edu.uci.ics.jung.visualization.SpringLayout;
+import java.awt.*;
+import java.util.*;
/**
* Dieses Model benutzt die Layoutfunktionen von Jung und einige Angepasste
* Layoutalgorithmen um die Knotenposition zu berechnen.
*
- * @author Jan
+ * @author Jan Friderici
*
*/
public class JungNodePlacer extends DirectedSparseGraph implements INodePlacer, NodeModelConstants {
@@ -98,6 +80,8 @@
private final Object edgeLock = new Object();
private final Object vertexLock = new Object();
+ private final Map<Edge, IMagicEdge> magicEdges = new HashMap<Edge, IMagicEdge>();
+
public JungNodePlacer() {
this(new MagicMetric());
}
@@ -112,8 +96,7 @@
/**
*
- * @param settings
- * @param metric
+ * @param metric the metrics to use.
*/
public JungNodePlacer(NodeModelMetric metric) {
super();
@@ -179,10 +162,18 @@
}
+ /**
+ *
+ * @param node
+ */
public void deleteNode(Node node){
removeVertex(node);
}
+ /**
+ *
+ * @return
+ */
public SpringLayout getLayout(){
return this.layout;
}
@@ -194,7 +185,7 @@
* @param node der neue oder ge\xE4nderte Knoten
* @param type der Typ des Events. (Enum nutzen)?
* @param data ---?
- * @see NodeModelListener, INodeModel, NodeModel
+ * @see net.sf.magicmap.client.interfaces.NodeModelListener , INodeModel, NodeModel
*/
public void updateNode(Node node, int type, Object data){
// first try if we have a handler for this event.
@@ -216,6 +207,11 @@
}
}
+ /**
+ *
+ * @param node
+ * @return
+ */
public Vertex findVertex(Node node){
return this.nodeVertexMapping.get(node);
}
@@ -292,9 +288,9 @@
* F\xFCgt eine gerichtete Kante von Knoten node1 zu node2 hinzu.
*
* Das Gewicht der Kante
- * @param node1
- * @param node2
- * @return
+ * @param node1 first node.
+ * @param node2 second node.
+ * @return a new or old edge between the two nodes.
*/
public IMagicEdge addEdge(Node node1, Node node2){
if (node1 == node2) return null;
@@ -307,8 +303,8 @@
/**
* F\xFCgt eine Jungkante hinzu. wird intern verwendet.
*
- * @param v1
- * @param v2
+ * @param v1 first vertex
+ * @param v2 second vertex.
* @return
*/
private IMagicEdge addEdge(Vertex v1, Vertex v2){
@@ -326,6 +322,7 @@
((SpringLayout) this.worker.getGraphLayout()).update();
this.worker.unsuspend(); // resumeGraph();
+ magicEdges.put(e,edge);
return edge;
}
@@ -333,6 +330,22 @@
}
/**
+ * @see INodePlacer
+ * @param n1 first node.
+ * @param n2 second node.
+ * @return an JungEdge or null.
+ */
+ public JungEdge getEdge(Node n1, Node n2){
+ Vertex v = findVertex(n1);
+ Vertex w = findVertex(n2);
+ if (v != null && w != null) {
+ return (JungEdge)v.findEdge(w);
+ }
+ else return null;
+
+ }
+
+ /**
* L\xF6scht eine Kantew zwischen den beiden Knoten.
* @param node1 Quelle der Kante.
* @param node2 Ziel der Kante.
@@ -347,6 +360,7 @@
Edge e = (Edge) edge;
if (e.getIncidentVertices().contains(v) && e.getIncidentVertices().contains(w)) {
removeEdge(e);
+ magicEdges.remove(e);
break;
}
}
@@ -364,12 +378,10 @@
Vertex v = findVertex(node);
if (v != null) {
this.worker.suspend();
- Set edges = getEdges();
// Kein Iterator direkt auf die Sets des
// Graphen => Concurrent modification!
- ArrayList list = new ArrayList(edges);
- for (Object aList : list) {
- Edge e = (Edge) aList;
+ ArrayList<Edge> list = new ArrayList<Edge>(getEdges());
+ for (Edge e : list) {
if (e.getIncidentVertices().contains(v)) {
super.removeEdge(e);
}
@@ -399,4 +411,14 @@
nodeVertexMapping.clear();
}
+ /**
+ *
+ * @return
+ */
+ public Iterator<IMagicEdge> iterator() {
+ synchronized (edgeLock) {
+ ArrayList<IMagicEdge> edgeCopy = new ArrayList<IMagicEdge>(magicEdges.values());
+ return edgeCopy.iterator();
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|