|
From: <fle...@us...> - 2007-12-20 12:59:54
|
Revision: 696
http://magicmap.svn.sourceforge.net/magicmap/?rev=696&view=rev
Author: flederohr
Date: 2007-12-20 04:59:48 -0800 (Thu, 20 Dec 2007)
Log Message:
-----------
introduced optional distributed computation of the client positions
Modified Paths:
--------------
trunk/magicmapclient/res/screentext.properties
trunk/magicmapclient/res/screentext_de_DE.properties
trunk/magicmapclient/src/edu/uci/ics/jung/visualization/AbstractLayout.java
trunk/magicmapclient/src/edu/uci/ics/jung/visualization/SpringLayout.java
trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java
trunk/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java
trunk/magicmapclient/src/net/sf/magicmap/client/gui/MapPanel.java
trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/JungNodePlacer.java
trunk/magicmapclient/src/net/sf/magicmap/client/model/node/ClientNode.java
trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModelConstants.java
Added Paths:
-----------
trunk/magicmapclient/src/net/sf/magicmap/client/model/location/jung/handler/CalculationStateHandler.java
Modified: trunk/magicmapclient/res/screentext.properties
===================================================================
--- trunk/magicmapclient/res/screentext.properties 2007-12-20 12:51:48 UTC (rev 695)
+++ trunk/magicmapclient/res/screentext.properties 2007-12-20 12:59:48 UTC (rev 696)
@@ -113,19 +113,22 @@
message.dialog.wrong.height = Error! The Node's height wasn't updated!
map.panel.context.hide.ap = hide accesspoint
map.panel.context.hide.ap.off = compute accesspoint
+map.panel.context.calculate.client = calculate client
node.accesspoint.is.hide = OFF
continue=C&ontinue
plugins.show=Plugins
plugins.show.tooltip=Shows all plugins
plugins.installed=Installed Plugins
-plugins.load=Show Plugins
+plugins.load=Reload Repository
plugins.install=Install Plugins
plugins.uninstall=Deinstall Plugins
-plugins.load.tooltip=Load the Plugin List
+plugins.uninstall.dialog=The plugin $pluginname can only be deleted after a restart.\nDo you want to restart MagicMap now?
+plugins.load.tooltip=Reloads the Plugin List from the repository
plugins.install.tooltip=Installs the selected Plugin
plugins.uninstall.tooltip=Deinstalls the selected Plugin
plugins.available=Additional Plugins
plugins.dependencies=Dependencies
+plugins.description=Description
plugins.detailview=Detail View
plugins.name=Name
plugins.version=Version
Modified: trunk/magicmapclient/res/screentext_de_DE.properties
===================================================================
--- trunk/magicmapclient/res/screentext_de_DE.properties 2007-12-20 12:51:48 UTC (rev 695)
+++ trunk/magicmapclient/res/screentext_de_DE.properties 2007-12-20 12:59:48 UTC (rev 696)
@@ -113,19 +113,22 @@
message.dialog.wrong.height = H\xF6he wurde nicht ge\xE4ndert!
map.panel.context.hide.ap = Accesspoint bei Berechnung ausblenden
map.panel.context.hide.ap.off = Accesspoint bei Berechnung ber\xFCcksichtigen
+map.panel.context.calculate.client = Berechne Client
node.accesspoint.is.hide = AUS
continue=&Weiter
plugins.show=Plugins
plugins.show.tooltip=Zeige alle Plugins
plugins.installed=Installierte Plugins
-plugins.load=Zeige Plugins
+plugins.load=Erneuere Repository
plugins.install=Installiere Plugin
plugins.uninstall=Deinstalliere Plugin
-plugins.load.tooltip=L\xE4dt die Pluginliste
+plugins.uninstall.dialog=Das Plugin $pluginname kann erst nach einem Neustart gel\xF6scht werden.\nM\xF6chten sie MagicMap jetzt neu starten?
+plugins.load.tooltip=L\xE4dt erneut den Inhalt des Plugin-Repositories
plugins.install.tooltip=Installiert ausgew\xE4hltes Plugin
plugins.uninstall.tooltip=Deinstalliert ausgew\xE4hltes Plugin
plugins.available=Weitere Plugins
plugins.dependencies=Abh\xE4ngigkeiten
+plugins.description=Beschreibung
plugins.detailview=Detailansicht
plugins.name=Name
plugins.version=Version
Modified: trunk/magicmapclient/src/edu/uci/ics/jung/visualization/AbstractLayout.java
===================================================================
--- trunk/magicmapclient/src/edu/uci/ics/jung/visualization/AbstractLayout.java 2007-12-20 12:51:48 UTC (rev 695)
+++ trunk/magicmapclient/src/edu/uci/ics/jung/visualization/AbstractLayout.java 2007-12-20 12:59:48 UTC (rev 696)
@@ -1,14 +1,11 @@
/*
* Copyright (c) 2003, the JUNG Project and the Regents of the University of
- * California All rights reserved.
- *
- * This software is open-source under the BSD license; see either "license.txt"
- * or http://jung.sourceforge.net/license.txt for a description.
+ * California All rights reserved. This software is open-source under the BSD
+ * license; see either "license.txt" or http://jung.sourceforge.net/license.txt
+ * for a description.
*/
/*
- * Created on Jul 7, 2003
- *
- * To change the template for this generated file go to
+ * Created on Jul 7, 2003 To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
@@ -36,479 +33,515 @@
*/
abstract public class AbstractLayout implements Layout {
- /**
- * The set of vertices that have been locked. When running layout, it is
- * important to check
- *
- * <pre>
- * if (dontmove( v )) { ... }
- * </pre>
- *
- * @return whether this vertex may be legally moved or not
- */
- public boolean dontMove(Vertex v){
- return dontmove.contains(v);
- }
+ /**
+ * The set of vertices that have been locked. When running layout, it is
+ * important to check
+ *
+ * <pre>
+ * if (dontmove( v )) { ... }
+ * </pre>
+ *
+ * @return whether this vertex may be legally moved or not
+ */
+ public boolean dontMove(Vertex v){
+ return dontmove.contains(v);
+ }
- /**
- * Support for explicit fix nodes.
- * @param v
- * @return
- */
- public boolean fix(Vertex v){
- return fix.contains(v);
- }
+ /**
+ * Support for explicit fix nodes.
+ * @param v
+ * @return
+ */
+ public boolean fix(Vertex v){
+ return fix.contains(v);
+ }
- // private boolean initialized = false;
+ // private boolean initialized = false;
- private Set dontmove;
- private Set fix;
+ private Set dontmove;
+ private Set fix;
- private static final Object BASE_KEY = "edu.uci.ics.jung.Base_Visualization_Key";
+ private static final Object BASE_KEY = "edu.uci.ics.jung.Base_Visualization_Key";
- private Dimension currentSize;
- private Graph baseGraph;
- private Graph visibleGraph;
+ private Dimension currentSize;
+ private Graph baseGraph;
+ private Graph visibleGraph;
- /**
- * Constructor. Initializes the current size to be 100x100, both the graph
- * and the showing graph to the argument, and creates the <tt>dontmove</tt>
- * set.
- *
- * @param g
- */
- public AbstractLayout(Graph g) {
- // this.currentSize = new Dimension(100, 100);
- this.baseGraph = g;
- this.visibleGraph = g;
- this.visibleEdges = g.getEdges();
- this.visibleVertices = g.getVertices();
- this.dontmove = new HashSet();
- this.fix = new HashSet();
- }
+ /**
+ * Constructor. Initializes the current size to be 100x100, both the graph
+ * and the showing graph to the argument, and creates the <tt>dontmove</tt>
+ * set.
+ *
+ * @param g
+ */
+ public AbstractLayout(Graph g) {
+ // this.currentSize = new Dimension(100, 100);
+ this.baseGraph = g;
+ this.visibleGraph = g;
+ this.visibleEdges = g.getEdges();
+ this.visibleVertices = g.getVertices();
+ this.notCalculatedVertices = new HashSet(); //FLAW
+ this.dontmove = new HashSet();
+ this.fix = new HashSet();
+ }
- /**
- * Initializer, calls <tt>intialize_local</tt> and <tt>initializeLocations</tt>
- * to start construction process.
- */
- public void initialize(Dimension size){
- // System.out.println("Initialize " + this + size );
- this.currentSize = size;
- initialize_local();
- initializeLocations();
- // this.initialized = true;
- }
+ /**
+ * Initializer, calls <tt>intialize_local</tt> and <tt>initializeLocations</tt>
+ * to start construction process.
+ */
+ public void initialize(Dimension size){
+ // System.out.println("Initialize " + this + size );
+ this.currentSize = size;
+ initialize_local();
+ initializeLocations();
+ // this.initialized = true;
+ }
- /**
- * Initializes all local information, and is called immediately within the
- * <tt>initialize()</tt> process. The user is responsible for overriding
- * this method to do any construction that may be necessary: for example,
- * to initialize local per-edge or graph-wide data.
- */
- protected abstract void initialize_local();
+ /**
+ * Initializes all local information, and is called immediately within the
+ * <tt>initialize()</tt> process. The user is responsible for overriding
+ * this method to do any construction that may be necessary: for example,
+ * to initialize local per-edge or graph-wide data.
+ */
+ protected abstract void initialize_local();
- /**
- * Initializes the local information on a single vertex. The user is
- * responsible for overriding this method to do any vertex-level
- * construction that may be necessary: for example, to attach vertex-level
- * information to each vertex.
- */
- protected abstract void initialize_local_vertex(Vertex v);
+ /**
+ * Initializes the local information on a single vertex. The user is
+ * responsible for overriding this method to do any vertex-level
+ * construction that may be necessary: for example, to attach vertex-level
+ * information to each vertex.
+ */
+ protected abstract void initialize_local_vertex(Vertex v);
- private Object key;
+ private Object key;
- private Set visibleVertices;
- private Set visibleEdges;
+ private Set visibleVertices;
+ private Set visibleEdges;
- /**
- * Returns a visualization-specific key (that is, specific both to this
- * instance and <tt>AbstractLayout</tt>) that can be used to access
- * UserData related to the <tt>AbstractLayout</tt>.
- */
- public Object getBaseKey(){
- if (key == null) key = new Pair(this, BASE_KEY);
- return key;
- }
+ private Set notCalculatedVertices; //FLAW
- /**
- * This method calls <tt>initialize_local_vertex</tt> for each vertex,
- * and also adds initial coordinate information for each vertex. (The
- * vertex's initial location is set by calling <tt>initializeLocation</tt>.
- */
- protected void initializeLocations(){
- for (Iterator iter = baseGraph.getVertices().iterator(); iter.hasNext();){
- Vertex v = (Vertex) iter.next();
+ /**
+ * Returns a visualization-specific key (that is, specific both to this
+ * instance and <tt>AbstractLayout</tt>) that can be used to access
+ * UserData related to the <tt>AbstractLayout</tt>.
+ */
+ public Object getBaseKey(){
+ if (key == null) key = new Pair(this, BASE_KEY);
+ return key;
+ }
- Coordinates coord = (Coordinates) v.getUserDatum(getBaseKey());
- if (coord == null){
- coord = new Coordinates();
- v.addUserDatum(getBaseKey(), coord, UserData.REMOVE);
- }
- if (!dontmove.contains(v)) initializeLocation(v, coord, currentSize);
- initialize_local_vertex(v);
+ /**
+ * This method calls <tt>initialize_local_vertex</tt> for each vertex,
+ * and also adds initial coordinate information for each vertex. (The
+ * vertex's initial location is set by calling <tt>initializeLocation</tt>.
+ */
+ protected void initializeLocations(){
+ for (Iterator iter = baseGraph.getVertices().iterator(); iter.hasNext();) {
+ Vertex v = (Vertex) iter.next();
+
+ Coordinates coord = (Coordinates) v.getUserDatum(getBaseKey());
+ if (coord == null) {
+ coord = new Coordinates();
+ v.addUserDatum(getBaseKey(), coord, UserData.REMOVE);
+ }
+ if (!dontmove.contains(v)) initializeLocation(v, coord, currentSize);
+ initialize_local_vertex(v);
+ }
}
- }
- /* ------------------------- */
+ /* ------------------------- */
- /**
- * Sets random locations for a vertex within the dimensions of the space.
- * If you want to initialize in some different way, override this method.
- *
- * @param coord
- * @param d
- */
- protected void initializeLocation(Vertex v, Coordinates coord, Dimension d){
- double x = Math.random() * d.getWidth();
- double y = Math.random() * d.getHeight();
- coord.setX(x);
- coord.setY(y);
- }
+ /**
+ * Sets random locations for a vertex within the dimensions of the space.
+ * If you want to initialize in some different way, override this method.
+ *
+ * @param coord
+ * @param d
+ */
+ protected void initializeLocation(Vertex v, Coordinates coord, Dimension d){
+ double x = Math.random() * d.getWidth();
+ double y = Math.random() * d.getHeight();
+ coord.setX(x);
+ coord.setY(y);
+ }
- /**
- * {@inheritDoc}By default, an <tt>AbstractLayout</tt> returns null for
- * its status.
- */
- public String getStatus(){
- return null;
- }
+ /**
+ * {@inheritDoc}By default, an <tt>AbstractLayout</tt> returns null for
+ * its status.
+ */
+ public String getStatus(){
+ return null;
+ }
- /**
- * Implementors must override this method in order to create a Layout. If
- * the Layout is the sort that only calculates locations once, this method
- * may be overridden with an empty method.
- * <p>
- * Note that "locked" vertices are not to be moved; however, it is the
- * policy of the visualization to decide how to handle them, and what to do
- * with the vertices around them. Prototypical code might include a
- * clipping like
- *
- * <pre>
- * for (Iterator i = getVertices().iterator(); i.hasNext() ) { Vertex v = (Vertex) i.next(); if (! dontmove.contains( v ) ) { ... // handle the node } else { // ignore the node } }
- * </pre>
- *
- * @see Layout#advancePositions()
- */
- public abstract void advancePositions();
+ /**
+ * Implementors must override this method in order to create a Layout. If
+ * the Layout is the sort that only calculates locations once, this method
+ * may be overridden with an empty method.
+ * <p>
+ * Note that "locked" vertices are not to be moved; however, it is the
+ * policy of the visualization to decide how to handle them, and what to do
+ * with the vertices around them. Prototypical code might include a
+ * clipping like
+ *
+ * <pre>
+ * for (Iterator i = getVertices().iterator(); i.hasNext() ) { Vertex v = (Vertex) i.next(); if (! dontmove.contains( v ) ) { ... // handle the node } else { // ignore the node } }
+ * </pre>
+ *
+ * @see Layout#advancePositions()
+ */
+ public abstract void advancePositions();
- /**
- * Accessor for the graph that represets all visible vertices. <b>Warning:
- * </b> This graph consists of vertices that are equivalent to, but are <b>
- * not the same as</b> the vertices in <tt>getGraph()</tt>, nor the
- * vertices in <tt>getAllVertices()</tt>. Rather, it returns the
- * vertices and edges that were passed in during a call to <tt>applyFilter</tt>.
- * The call <tt>getVisibleGraph().getVertices()</tt>, is almost
- * indubitably incorrect.
- * <p>
- *
- * @return the current visible graph.
- * @see #getVisibleEdges
- * @see #getVisibleVertices
- */
- protected Graph getVisibleGraph(){
- return visibleGraph;
- }
+ /**
+ * Accessor for the graph that represets all visible vertices. <b>Warning:
+ * </b> This graph consists of vertices that are equivalent to, but are <b>
+ * not the same as</b> the vertices in <tt>getGraph()</tt>, nor the
+ * vertices in <tt>getAllVertices()</tt>. Rather, it returns the
+ * vertices and edges that were passed in during a call to <tt>applyFilter</tt>.
+ * The call <tt>getVisibleGraph().getVertices()</tt>, is almost
+ * indubitably incorrect.
+ * <p>
+ *
+ * @return the current visible graph.
+ * @see #getVisibleEdges
+ * @see #getVisibleVertices
+ */
+ protected Graph getVisibleGraph(){
+ return visibleGraph;
+ }
- /**
- * Returns the current size of the visualization space, accoring to the
- * last call to resize().
- *
- * @return the current size of the screen
- */
- public Dimension getCurrentSize(){
- return currentSize;
- }
+ /**
+ * Returns the current size of the visualization space, accoring to the
+ * last call to resize().
+ *
+ * @return the current size of the screen
+ */
+ public Dimension getCurrentSize(){
+ return currentSize;
+ }
- /**
- * Utility method, gets a single vertex from this edge. The utility's
- * implementation is to get the iterator from the edge's <tt>getIncidentVertices()</tt>
- * and then return the first element.
- */
- protected Vertex getAVertex(Edge e){
- Vertex v = (Vertex) e.getIncidentVertices().iterator().next();
- return v;
- }
+ /**
+ * Utility method, gets a single vertex from this edge. The utility's
+ * implementation is to get the iterator from the edge's <tt>getIncidentVertices()</tt>
+ * and then return the first element.
+ */
+ protected Vertex getAVertex(Edge e){
+ Vertex v = (Vertex) e.getIncidentVertices().iterator().next();
+ return v;
+ }
- /**
- * Returns the Coordinates object that stores the vertex' x and y location.
- *
- * @param v
- * A Vertex that is a part of the Graph being visualized.
- * @return A Coordinates object with x and y locations.
- */
- public Coordinates getCoordinates(Vertex v){
- return (Coordinates) v.getUserDatum(getBaseKey());
- }
+ /**
+ * Returns the Coordinates object that stores the vertex' x and y location.
+ *
+ * @param v
+ * A Vertex that is a part of the Graph being visualized.
+ * @return A Coordinates object with x and y locations.
+ */
+ public Coordinates getCoordinates(Vertex v){
+ return (Coordinates) v.getUserDatum(getBaseKey());
+ }
- /**
- * Returns the x coordinate of the vertex from the Coordiantes object.
- *
- * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
- */
- public double getX(Vertex v){
- return ((Coordinates) v.getUserDatum(getBaseKey())).getX();
- }
+ /**
+ * Returns the x coordinate of the vertex from the Coordiantes object.
+ *
+ * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
+ */
+ public double getX(Vertex v){
+ return ((Coordinates) v.getUserDatum(getBaseKey())).getX();
+ }
- /**
- * Returns the y coordinate of the vertex from the Coordiantes object.
- *
- * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
- */
- public double getY(Vertex v){
- return ((Coordinates) v.getUserDatum(getBaseKey())).getY();
- }
+ /**
+ * Returns the y coordinate of the vertex from the Coordiantes object.
+ *
+ * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
+ */
+ public double getY(Vertex v){
+ return ((Coordinates) v.getUserDatum(getBaseKey())).getY();
+ }
- // TH:
- /**
- * Returns the x coordinate of the vertex from the Coordiantes object.
- *
- * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
- */
- public void setX(Vertex v, double x){
- ((Coordinates) v.getUserDatum(getBaseKey())).setX(x);
- }
+ // TH:
+ /**
+ * Returns the x coordinate of the vertex from the Coordiantes object.
+ *
+ * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
+ */
+ public void setX(Vertex v, double x){
+ ((Coordinates) v.getUserDatum(getBaseKey())).setX(x);
+ }
- /**
- * Returns the y coordinate of the vertex from the Coordiantes object.
- *
- * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
- */
- public void setY(Vertex v, double y){
- ((Coordinates) v.getUserDatum(getBaseKey())).setY(y);
- }
+ /**
+ * Returns the y coordinate of the vertex from the Coordiantes object.
+ *
+ * @see edu.uci.ics.jung.visualization.Layout#getX(edu.uci.ics.jung.graph.Vertex)
+ */
+ public void setY(Vertex v, double y){
+ ((Coordinates) v.getUserDatum(getBaseKey())).setY(y);
+ }
- /**
- * When a visualizetion is resized, it presumably wants to fix the
- * locations of the vertices and possibly to reinitialize its data. The
- * current method calls <tt>initializeLocations</tt> followed by <tt>initialize_local</tt>.
- * TODO: A better implementation wouldn't destroy the current information,
- * but would either scale the current visualization, or move the nodes
- * toward the new center.
- */
- public void resize(Dimension size){
- // are we initialized yet?
+ /**
+ * When a visualizetion is resized, it presumably wants to fix the
+ * locations of the vertices and possibly to reinitialize its data. The
+ * current method calls <tt>initializeLocations</tt> followed by <tt>initialize_local</tt>.
+ * TODO: A better implementation wouldn't destroy the current information,
+ * but would either scale the current visualization, or move the nodes
+ * toward the new center.
+ */
+ public void resize(Dimension size){
+ // are we initialized yet?
- if (currentSize == null){
- currentSize = size;
- return;
+ if (currentSize == null) {
+ currentSize = size;
+ return;
+ }
+
+ Dimension oldSize;
+ synchronized (currentSize) {
+ if (currentSize.equals(size)) return;
+ oldSize = currentSize;
+ this.currentSize = size;
+ }
+
+ int xOffset = (size.width - oldSize.width) / 2;
+ int yOffset = (size.height - oldSize.height) / 2;
+
+ // now, move each vertex to be at the new screen center
+ for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();) {
+ Vertex e = (Vertex) iter.next();
+ offsetVertex(e, xOffset, yOffset);
+ }
+ // optionally, we may want to restart
}
- Dimension oldSize;
- synchronized (currentSize){
- if (currentSize.equals(size)) return;
- oldSize = currentSize;
- this.currentSize = size;
+ /**
+ * @param v
+ * @param xOffset
+ * @param yOffset
+ */
+ protected void offsetVertex(Vertex v, int xOffset, int yOffset){
+ Coordinates c = getCoordinates(v);
+ c.add(xOffset, yOffset);
+ forceMove(v, (int) c.getX(), (int) c.getY());
}
- int xOffset = (size.width - oldSize.width) / 2;
- int yOffset = (size.height - oldSize.height) / 2;
+ /**
+ * Restarts the visualization entirely, as if the the user had pressed the
+ * "scramble" button. Calls <tt>initializeLocation</tt> for each vertex.
+ * TODO: Is this enough? Should it call the whole initialization process?
+ * Why does resize do more?
+ */
+ public void restart(){
+ initializeLocations();
+ initialize_local();
+ }
- // now, move each vertex to be at the new screen center
- for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();){
- Vertex e = (Vertex) iter.next();
- offsetVertex(e, xOffset, yOffset);
+ // /**
+ // * Returns the set of all visible vertices known to the
+ // * visualization.
+ // * @return the list of all vertices in the visible graph
+ // */
+ // protected Set getAllVertices() {
+ // return getVisibleGraph().getVertices();
+ // }
+
+ /**
+ * Gets the vertex nearest to the location of the (x,y) location selected.
+ * Calls the longer form of the call.
+ */
+ public Vertex getVertex(double x, double y){
+ return getVertex(x, y, Math.sqrt(Double.MAX_VALUE - 1000));
}
- // optionally, we may want to restart
- }
- /**
- * @param v
- * @param xOffset
- * @param yOffset
- */
- protected void offsetVertex(Vertex v, int xOffset, int yOffset){
- Coordinates c = getCoordinates(v);
- c.add(xOffset, yOffset);
- forceMove(v, (int) c.getX(), (int) c.getY());
- }
+ /**
+ * Gets the vertex nearest to the location of the (x,y) location selected,
+ * within a distance of <tt>maxDistance</tt>. Iterates through all
+ * visible vertices and checks their distance from the click. Override this
+ * method to provde a more efficient implementation.
+ */
+ public Vertex getVertex(double x, double y, double maxDistance){
+ double minDistance = maxDistance * maxDistance;
+ Vertex closest = null;
+ for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();) {
+ Vertex v = (Vertex) iter.next();
+ double dx = getX(v) - x;
+ double dy = getY(v) - y;
+ double dist = dx * dx + dy * dy;
+ if (dist < minDistance) {
+ minDistance = dist;
+ closest = v;
+ }
+ }
+ return closest;
+ }
- /**
- * Restarts the visualization entirely, as if the the user had pressed the
- * "scramble" button. Calls <tt>initializeLocation</tt> for each vertex.
- * TODO: Is this enough? Should it call the whole initialization process?
- * Why does resize do more?
- */
- public void restart(){
- initializeLocations();
- initialize_local();
- }
+ /**
+ * Gets the edge nearest to the location of the (x,y) location selected.
+ * Calls the longer form of the call.
+ */
+ public Edge getEdge(double x, double y){
+ return getEdge(x, y, Math.sqrt(Double.MAX_VALUE - 1000));
+ }
- // /**
- // * Returns the set of all visible vertices known to the
- // * visualization.
- // * @return the list of all vertices in the visible graph
- // */
- // protected Set getAllVertices() {
- // return getVisibleGraph().getVertices();
- // }
+ /**
+ * Gets the edge nearest to the location of the (x,y) location selected,
+ * within a distance of <tt>maxDistance</tt>, Iterates through all
+ * visible edges and checks their distance from the click. Override this
+ * method to provide a more efficient implementation.
+ *
+ * @param x
+ * @param y
+ * @param maxDistance
+ * @return Edge closest to the click.
+ */
+ public Edge getEdge(double x, double y, double maxDistance){
+ double minDistance = maxDistance * maxDistance;
+ Edge closest = null;
+ for (Iterator iter = getVisibleEdges().iterator(); iter.hasNext();) {
+ Edge e = (Edge) iter.next();
+ // if anyone uses a hyperedge, this is too complex.
+ if (e.numVertices() != 2) continue;
+ // Could replace all this set stuff with getFrom_internal() etc.
+ Set vertices = e.getIncidentVertices();
+ Iterator vertexIterator = vertices.iterator();
+ Vertex v1 = (Vertex) vertexIterator.next();
+ Vertex v2 = (Vertex) vertexIterator.next();
+ // Get coords
+ double x1 = getX(v1);
+ double y1 = getY(v1);
+ double x2 = getX(v2);
+ double y2 = getY(v2);
+ // Calculate location on line closest to (x,y)
+ // First, check that v1 and v2 are not coincident.
+ if (x1 == x2 && y1 == y2) continue;
+ double b = ((y - y1) * (y2 - y1) + (x - x1) * (x2 - x1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ //
+ double distance2; // square of the distance
+ if (b <= 0)
+ distance2 = (x - x1) * (x - x1) + (y - y1) * (y - y1);
+ else if (b >= 1)
+ distance2 = (x - x2) * (x - x2) + (y - y2) * (y - y2);
+ else {
+ double x3 = x1 + b * (x2 - x1);
+ double y3 = y1 + b * (y2 - y1);
+ distance2 = (x - x3) * (x - x3) + (y - y3) * (y - y3);
+ }
- /**
- * Gets the vertex nearest to the location of the (x,y) location selected.
- * Calls the longer form of the call.
- */
- public Vertex getVertex(double x, double y){
- return getVertex(x, y, Math.sqrt(Double.MAX_VALUE - 1000));
- }
+ if (distance2 < minDistance) {
+ minDistance = distance2;
+ closest = e;
+ }
+ }
+ return closest;
+ }
- /**
- * Gets the vertex nearest to the location of the (x,y) location selected,
- * within a distance of <tt>maxDistance</tt>. Iterates through all
- * visible vertices and checks their distance from the click. Override this
- * method to provde a more efficient implementation.
- */
- public Vertex getVertex(double x, double y, double maxDistance){
- double minDistance = maxDistance * maxDistance;
- Vertex closest = null;
- for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();){
- Vertex v = (Vertex) iter.next();
- double dx = getX(v) - x;
- double dy = getY(v) - y;
- double dist = dx * dx + dy * dy;
- if (dist < minDistance){
- minDistance = dist;
- closest = v;
- }
+ /**
+ * Accessor for the graph that represets all vertices.
+ *
+ * @return the graph that contains all vertices.
+ */
+ public Graph getGraph(){
+ return baseGraph;
}
- return closest;
- }
- /**
- * Gets the edge nearest to the location of the (x,y) location selected.
- * Calls the longer form of the call.
- */
- public Edge getEdge(double x, double y){
- return getEdge(x, y, Math.sqrt(Double.MAX_VALUE - 1000));
- }
+ /**
+ * Returns the set of edges from the original <tt>getGraph</tt> that are
+ * now visible. These edges are equivalent to the ones passed in from the
+ * <tt>Graph</tt> argument to <tt>applyFilter()</tt>.
+ */
+ public Set getVisibleEdges(){
+ return visibleEdges;
+ }
- /**
- * Gets the edge nearest to the location of the (x,y) location selected,
- * within a distance of <tt>maxDistance</tt>, Iterates through all
- * visible edges and checks their distance from the click. Override this
- * method to provide a more efficient implementation.
- *
- * @param x
- * @param y
- * @param maxDistance
- * @return Edge closest to the click.
- */
- public Edge getEdge(double x, double y, double maxDistance){
- double minDistance = maxDistance * maxDistance;
- Edge closest = null;
- for (Iterator iter = getVisibleEdges().iterator(); iter.hasNext();){
- Edge e = (Edge) iter.next();
- // if anyone uses a hyperedge, this is too complex.
- if (e.numVertices() != 2) continue;
- // Could replace all this set stuff with getFrom_internal() etc.
- Set vertices = e.getIncidentVertices();
- Iterator vertexIterator = vertices.iterator();
- Vertex v1 = (Vertex) vertexIterator.next();
- Vertex v2 = (Vertex) vertexIterator.next();
- // Get coords
- double x1 = getX(v1);
- double y1 = getY(v1);
- double x2 = getX(v2);
- double y2 = getY(v2);
- // Calculate location on line closest to (x,y)
- // First, check that v1 and v2 are not coincident.
- if (x1 == x2 && y1 == y2) continue;
- double b = ((y - y1) * (y2 - y1) + (x - x1) * (x2 - x1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- //
- double distance2; // square of the distance
- if (b <= 0)
- distance2 = (x - x1) * (x - x1) + (y - y1) * (y - y1);
- else if (b >= 1)
- distance2 = (x - x2) * (x - x2) + (y - y2) * (y - y2);
- else{
- double x3 = x1 + b * (x2 - x1);
- double y3 = y1 + b * (y2 - y1);
- distance2 = (x - x3) * (x - x3) + (y - y3) * (y - y3);
- }
+ /**
+ * Returns the set of vertices from the original <tt>getGraph</tt> that
+ * are now visible. These vertices are equivalent to the ones passed in
+ * from the <tt>Graph</tt> argument to <tt>applyFilter()</tt>.
+ */
+ public Set getVisibleVertices(){
+ return visibleVertices;
+ }
- if (distance2 < minDistance){
- minDistance = distance2;
- closest = e;
- }
+ /**
+ * Forcibly moves a vertex to the (x,y) location by setting its x and y
+ * locations to the inputted location. Does not add the vertex to the
+ * "dontmove" list, and (in the default implementation) does not make any
+ * adjustments to the rest of the graph.
+ */
+ public void forceMove(Vertex picked, int x, int y){
+ if (!fix(picked)) {
+ Coordinates coord = getCoordinates(picked);
+ coord.setX(x);
+ coord.setY(y);
+ }
}
- return closest;
- }
- /**
- * Accessor for the graph that represets all vertices.
- *
- * @return the graph that contains all vertices.
- */
- public Graph getGraph(){
- return baseGraph;
- }
+ /**
+ * Adds the vertex to the DontMove list
+ */
+ public void lockVertex(Vertex v){
+ dontmove.add(v);
+ }
- /**
- * Returns the set of edges from the original <tt>getGraph</tt> that are
- * now visible. These edges are equivalent to the ones passed in from the
- * <tt>Graph</tt> argument to <tt>applyFilter()</tt>.
- */
- public Set getVisibleEdges(){
- return visibleEdges;
- }
+ /**
+ * Removes the vertex from the DontMove list
+ */
+ public void unlockVertex(Vertex v){
+ if (!fix(v)) {
+ dontmove.remove(v);
+ }
+ }
- /**
- * Returns the set of vertices from the original <tt>getGraph</tt> that
- * are now visible. These vertices are equivalent to the ones passed in
- * from the <tt>Graph</tt> argument to <tt>applyFilter()</tt>.
- */
- public Set getVisibleVertices(){
- return visibleVertices;
- }
+ public void setFix(Vertex v){
+ fix.add(v);
+ dontmove.add(v);
+ }
- /**
- * Forcibly moves a vertex to the (x,y) location by setting its x and y
- * locations to the inputted location. Does not add the vertex to the
- * "dontmove" list, and (in the default implementation) does not make any
- * adjustments to the rest of the graph.
- */
- public void forceMove(Vertex picked, int x, int y){
- if (!fix(picked)){
- Coordinates coord = getCoordinates(picked);
- coord.setX(x);
- coord.setY(y);
+ public void unsetFix(Vertex v){
+ fix.remove(v);
+ dontmove.remove(v);
}
- }
- /**
- * Adds the vertex to the DontMove list
- */
- public void lockVertex(Vertex v){
- dontmove.add(v);
- }
+ /**
+ * Applies the filter to the current graph. The default implementation
+ * merely makes fewer vertices available to the <tt>getVisibleVertices</tt>
+ * and <tt>getVisibleEdges</tt> methods.
+ *
+ * @see Layout#applyFilter(Graph g)
+ */
+ public synchronized void applyFilter(Graph g){
+ this.visibleGraph = g;
+ this.visibleVertices = GraphUtils.getEqualVertices(g.getVertices(), baseGraph);
+ this.visibleEdges = GraphUtils.getEqualEdges(g.getEdges(), baseGraph);
+ }
- /**
- * Removes the vertex from the DontMove list
- */
- public void unlockVertex(Vertex v){
- if (!fix(v)){
- dontmove.remove(v);
+ /**
+ * @author FLAW
+ * @return the notCalculatedVertices
+ */
+ public Set getNotCalculatedVertices(){
+ return notCalculatedVertices;
}
- }
- public void setFix(Vertex v){
- fix.add(v);
- dontmove.add(v);
- }
+ /**
+ * @author FLAW
+ * @param v
+ * @return is Vertex not calculated
+ */
+ public boolean isNotCalculatedVertx(Vertex v){
+ return notCalculatedVertices.contains(v);
+ }
- public void unsetFix(Vertex v){
- fix.remove(v);
- dontmove.remove(v);
- }
+ /**
+ * @author FLAW
+ * @param v
+ */
+ public void addNotCalculatedVertex(Vertex v){
+ notCalculatedVertices.add(v);
+ }
- /**
- * Applies the filter to the current graph. The default implementation
- * merely makes fewer vertices available to the <tt>getVisibleVertices</tt>
- * and <tt>getVisibleEdges</tt> methods.
- *
- * @see Layout#applyFilter(Graph g)
- */
- public synchronized void applyFilter(Graph g){
- this.visibleGraph = g;
- this.visibleVertices = GraphUtils.getEqualVertices(g.getVertices(), baseGraph);
- this.visibleEdges = GraphUtils.getEqualEdges(g.getEdges(), baseGraph);
- }
+ /**
+ * @author FLAW
+ * @param v
+ */
+ public void removeNotCalculatedVertex(Vertex v){
+ notCalculatedVertices.remove(v);
+ }
}
\ No newline at end of file
Modified: trunk/magicmapclient/src/edu/uci/ics/jung/visualization/SpringLayout.java
===================================================================
--- trunk/magicmapclient/src/edu/uci/ics/jung/visualization/SpringLayout.java 2007-12-20 12:51:48 UTC (rev 695)
+++ trunk/magicmapclient/src/edu/uci/ics/jung/visualization/SpringLayout.java 2007-12-20 12:59:48 UTC (rev 696)
@@ -1,9 +1,8 @@
/*
* Copyright (c) 2003, the JUNG Project and the Regents of the University of
- * California All rights reserved.
- *
- * This software is open-source under the BSD license; see either "license.txt"
- * or http://jung.sourceforge.net/license.txt for a description.
+ * California All rights reserved. This software is open-source under the BSD
+ * license; see either "license.txt" or http://jung.sourceforge.net/license.txt
+ * for a description.
*/
package edu.uci.ics.jung.visualization;
@@ -34,508 +33,521 @@
*/
public class SpringLayout extends AbstractLayout implements LayoutMutable {
- private static final Object SPRING_KEY = "temp_edu.uci.ics.jung.Spring_Visualization_Key";
- protected double stretch = 85.0; //70; // 0.70;
+ private static final Object SPRING_KEY = "temp_edu.uci.ics.jung.Spring_Visualization_Key";
+ protected double stretch = 85.0; //70; // 0.70;
- protected LengthFunction lengthFunction;
- protected RepulsionFunction repulsionFunction; // TH
- protected ForceFunction forceFunction; //TH
- protected CanLeaveMapFunction leaveFunction;
+ protected LengthFunction lengthFunction;
+ protected RepulsionFunction repulsionFunction; // TH
+ protected ForceFunction forceFunction; //TH
+ protected CanLeaveMapFunction leaveFunction;
- //protected int repulsion_range = 100;
- //protected double force_multiplier = 1.0 / 3.0;
+ //protected int repulsion_range = 100;
+ //protected double force_multiplier = 1.0 / 3.0;
- /**
- * Returns the status.
- */
- public String getStatus(){
- return null;
- }
+ /**
+ * Returns the status.
+ */
+ public String getStatus(){
+ return null;
+ }
- /**
- * Constructor for a SpringLayout for a raw graph with associated
- * dimension--the input knows how big the graph is. Defaults to the unit
- * length function.
- */
- public SpringLayout(Graph g) {
- this(g, UNITLENGTHFUNCTION, NoRepulsionFunction);
- }
+ /**
+ * Constructor for a SpringLayout for a raw graph with associated
+ * dimension--the input knows how big the graph is. Defaults to the unit
+ * length function.
+ */
+ public SpringLayout(Graph g) {
+ this(g, UNITLENGTHFUNCTION, NoRepulsionFunction);
+ }
- /**
- * Constructor for a SpringLayout for a raw graph with associated component.
- *
- * @param g
- * the input Graph
- * @param f
- * the length function
- */
- public SpringLayout(Graph g, LengthFunction f) {
- this(g,f,NoRepulsionFunction);
- }
+ /**
+ * Constructor for a SpringLayout for a raw graph with associated component.
+ *
+ * @param g
+ * the input Graph
+ * @param f
+ * the length function
+ */
+ public SpringLayout(Graph g, LengthFunction f) {
+ this(g, f, NoRepulsionFunction);
+ }
- /**
- * Constructor for a SpringLayout for a raw graph with associated component.
- *
- * @param g
- * the input Graph
- * @param f
- * the length function
- * @param r
- * the repulsion function
- */
- public SpringLayout(Graph g, LengthFunction f, RepulsionFunction r) {
- super(g);
- this.lengthFunction = f;
- this.repulsionFunction = r;
- this.forceFunction = DefaultForceFunction;
- this.leaveFunction = new CanLeaveMapFunction() {
+ /**
+ * Constructor for a SpringLayout for a raw graph with associated component.
+ *
+ * @param g
+ * the input Graph
+ * @param f
+ * the length function
+ * @param r
+ * the repulsion function
+ */
+ public SpringLayout(Graph g, LengthFunction f, RepulsionFunction r) {
+ super(g);
+ this.lengthFunction = f;
+ this.repulsionFunction = r;
+ this.forceFunction = DefaultForceFunction;
+ this.leaveFunction = new CanLeaveMapFunction() {
- public boolean canLeave(Vertex v){
- return false;
- }
- };
- }
+ public boolean canLeave(Vertex v){
+ return false;
+ }
+ };
+ }
- /**
- * @return the current value for the stretch parameter
- * @see #setStretch(double)
- */
- public double getStretch(){
- return stretch;
- }
+ /**
+ * @return the current value for the stretch parameter
+ * @see #setStretch(double)
+ */
+ public double getStretch(){
+ return stretch;
+ }
- /**
- * <p>Sets the stretch parameter for this instance. This value
- * specifies how much the degrees of an edge's incident vertices
- * should influence how easily the endpoints of that edge
- * can move (that is, that edge's tendency to change its length).</p>
- *
- * <p>The default value is 0.70. Positive values less than 1 cause
- * high-degree vertices to move less than low-degree vertices, and
- * values > 1 cause high-degree vertices to move more than
- * low-degree vertices. Negative values will have unpredictable
- * and inconsistent results.</p>
- * @param stretch
- */
- public void setStretch(double stretch){
- this.stretch = stretch;
- }
+ /**
+ * <p>Sets the stretch parameter for this instance. This value
+ * specifies how much the degrees of an edge's incident vertices
+ * should influence how easily the endpoints of that edge
+ * can move (that is, that edge's tendency to change its length).</p>
+ *
+ * <p>The default value is 0.70. Positive values less than 1 cause
+ * high-degree vertices to move less than low-degree vertices, and
+ * values > 1 cause high-degree vertices to move more than
+ * low-degree vertices. Negative values will have unpredictable
+ * and inconsistent results.</p>
+ * @param stretch
+ */
+ public void setStretch(double stretch){
+ this.stretch = stretch;
+ }
- public CanLeaveMapFunction getLeaveFunction(){
- return leaveFunction;
- }
+ public CanLeaveMapFunction getLeaveFunction(){
+ return leaveFunction;
+ }
- public void setLeaveFunction(CanLeaveMapFunction leaveFunction){
- this.leaveFunction = leaveFunction;
- }
+ public void setLeaveFunction(CanLeaveMapFunction leaveFunction){
+ this.leaveFunction = leaveFunction;
+ }
- protected void initialize_local(){
- for (Iterator iter = getGraph().getEdges().iterator(); iter.hasNext();){
- Edge e = (Edge) iter.next();
- SpringEdgeData sed = getSpringData(e);
- if (sed == null){
- sed = new SpringEdgeData(e);
- e.addUserDatum(getSpringKey(), sed, UserData.REMOVE);
- }
- calcEdgeLength(sed, lengthFunction);
+ protected void initialize_local(){
+ for (Iterator iter = getGraph().getEdges().iterator(); iter.hasNext();) {
+ Edge e = (Edge) iter.next();
+ SpringEdgeData sed = getSpringData(e);
+ if (sed == null) {
+ sed = new SpringEdgeData(e);
+ e.addUserDatum(getSpringKey(), sed, UserData.REMOVE);
+ }
+ calcEdgeLength(sed, lengthFunction);
+ }
}
- }
- Object key = null;
+ Object key = null;
- public Object getSpringKey(){
- if (key == null) key = new Pair(this, SPRING_KEY);
- return key;
- }
+ public Object getSpringKey(){
+ if (key == null) key = new Pair(this, SPRING_KEY);
+ return key;
+ }
- /**
- * (non-Javadoc)
- *
- * @see edu.uci.ics.jung.visualization.AbstractLayout#initialize_local_vertex(edu.uci.ics.jung.graph.Vertex)
- */
- protected void initialize_local_vertex(Vertex v){
- SpringVertexData vud = getSpringData(v);
- if (vud == null){
- vud = new SpringVertexData();
- v.addUserDatum(getSpringKey(), vud, UserData.REMOVE);
+ /**
+ * (non-Javadoc)
+ *
+ * @see edu.uci.ics.jung.visualization.AbstractLayout#initialize_local_vertex(edu.uci.ics.jung.graph.Vertex)
+ */
+ protected void initialize_local_vertex(Vertex v){
+ SpringVertexData vud = getSpringData(v);
+ if (vud == null) {
+ vud = new SpringVertexData();
+ v.addUserDatum(getSpringKey(), vud, UserData.REMOVE);
+ }
}
- }
- /* ------------------------- */
+ /* ------------------------- */
- protected void calcEdgeLength(SpringEdgeData sed, LengthFunction f){
- sed.length = f.getLength(sed.e);
- }
+ protected void calcEdgeLength(SpringEdgeData sed, LengthFunction f){
+ sed.length = f.getLength(sed.e);
+ }
- /* ------------------------- */
+ /* ------------------------- */
- /**
- * Relaxation step. Moves all nodes a smidge.
- */
- public void advancePositions(){
- for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();){
- Vertex v = (Vertex) iter.next();
- SpringVertexData svd = getSpringData(v);
- if (svd == null){
- System.out.println("How confusing!");
- continue;
- }
- svd.dx /= 4;
- svd.dy /= 4;
- svd.edgedx = svd.edgedy = 0;
- svd.repulsiondx = svd.repulsiondy = 0;
- }
+ /**
+ * Relaxation step. Moves all nodes a smidge.
+ */
+ public void advancePositions(){
+ for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();) {
+ Vertex v = (Vertex) iter.next();
+ if (isNotCalculatedVertx(v)) {
+ continue;
+ }
+ SpringVertexData svd = getSpringData(v);
+ if (svd == null) {
+ System.out.println("How confusing!");
+ continue;
+ }
+ svd.dx /= 4;
+ svd.dy /= 4;
+ svd.edgedx = svd.edgedy = 0;
+ svd.repulsiondx = svd.repulsiondy = 0;
+ }
- try{
- SwingUtilities.invokeAndWait(new Runnable() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
- public void run(){
- relaxEdges();
- calculateRepulsion();
- moveNodes();
+ public void run(){
+ relaxEdges();
+ calculateRepulsion();
+ moveNodes();
+ }
+ });
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- });
- } catch (InterruptedException e){
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e){
- // TODO Auto-generated catch block
- e.printStackTrace();
+
}
- }
+ protected Vertex getAVertex(Edge e){
+ Vertex v = (Vertex) e.getIncidentVertices().iterator().next();
+ return v;
+ }
- protected Vertex getAVertex(Edge e){
- Vertex v = (Vertex) e.getIncidentVertices().iterator().next();
- return v;
- }
+ protected void relaxEdges(){
+ for (Iterator i = getVisibleEdges().iterator(); i.hasNext();) {
+ Edge e = (Edge) i.next();
- protected void relaxEdges(){
- for (Iterator i = getVisibleEdges().iterator(); i.hasNext();){
- Edge e = (Edge) i.next();
+ Vertex v1 = getAVertex(e);
+ Vertex v2 = e.getOpposite(v1);
- Vertex v1 = getAVertex(e);
- Vertex v2 = e.getOpposite(v1);
+ double vx = getX(v1) - getX(v2);
+ double vy = getY(v1) - getY(v2);
+ double len = Math.sqrt(vx * vx + vy * vy);
- double vx = getX(v1) - getX(v2);
- double vy = getY(v1) - getY(v2);
- double len = Math.sqrt(vx * vx + vy * vy);
+ double desiredLen = getLength(e);
- double desiredLen = getLength(e);
+ // round from zero, if needed [zero would be Bad.].
+ len = (len == 0) ? .0001 : len;
- // round from zero, if needed [zero would be Bad.].
- len = (len == 0) ? .0001 : len;
+ double force_multiplier = forceFunction.getForce(v1, v2);
- double force_multiplier = forceFunction.getForce(v1, v2);
+ double f = force_multiplier * (desiredLen - len) / len;
- double f = force_multiplier * (desiredLen - len) / len;
+ f = f * Math.pow(stretch / 100.0, (v1.degree() + v2.degree() - 2));
- f = f * Math.pow(stretch / 100.0, (v1.degree() + v2.degree() - 2));
+ // the actual movement distance 'dx' is the force multiplied by the
+ // distance to go.
+ double dx = f * vx;
+ double dy = f * vy;
+ SpringVertexData v1D, v2D;
+ v1D = getSpringData(v1);
+ v2D = getSpringData(v2);
- // the actual movement distance 'dx' is the force multiplied by the
- // distance to go.
- double dx = f * vx;
- double dy = f * vy;
- SpringVertexData v1D, v2D;
- v1D = getSpringData(v1);
- v2D = getSpringData(v2);
+ SpringEdgeData sed = getSpringData(e);
+ sed.f = f;
- SpringEdgeData sed = getSpringData(e);
- sed.f = f;
+ v1D.edgedx += dx;
+ v1D.edgedy += dy;
+ v2D.edgedx += -dx;
+ v2D.edgedy += -dy;
+ }
- v1D.edgedx += dx;
- v1D.edgedy += dy;
- v2D.edgedx += -dx;
- v2D.edgedy += -dy;
}
- }
+ protected void calculateRepulsion(){
+ for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();) {
+ Vertex v = (Vertex) iter.next();
+ if (isNotCalculatedVertx(v)) {
+ continue;
+ }
+ if (dontMove(v)) continue;
- protected void calculateRepulsion(){
- for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext();){
- Vertex v = (Vertex) iter.next();
- if (dontMove(v)) continue;
+ SpringVertexData svd = getSpringData(v);
+ double dx = 0, dy = 0;
- SpringVertexData svd = getSpringData(v);
- double dx = 0, dy = 0;
+ double repulsion_range = 0;
- double repulsion_range = 0;
+ for (Iterator iter2 = getVisibleVertices().iterator(); iter2.hasNext();) {
- for (Iterator iter2 = getVisibleVertices().iterator(); iter2.hasNext();){
+ Vertex v2 = (Vertex) iter2.next();
+ if (v == v2) continue;
- Vertex v2 = (Vertex) iter2.next();
- if (v == v2) continue;
+ // TH
+ repulsion_range = this.repulsionFunction.getRepulsion(v, v2);
- // TH
- repulsion_range = this.repulsionFunction.getRepulsion(v, v2);
-
- double vx = getX(v) - getX(v2);
- double vy = getY(v) - getY(v2);
- double distance = vx * vx + vy * vy;
- if (distance == 0){
- dx += Math.random();
- dy += Math.random();
- } else if (distance < repulsion_range * repulsion_range){
- double factor = 1;
- dx += factor * vx / Math.pow(distance, 2);
- dy += factor * vy / Math.pow(distance, 2);
+ double vx = getX(v) - getX(v2);
+ double vy = getY(v) - getY(v2);
+ double distance = vx * vx + vy * vy;
+ if (distance == 0) {
+ dx += Math.random();
+ dy += Math.random();
+ } else if (distance < repulsion_range * repulsion_range) {
+ double factor = 1;
+ dx += factor * vx / Math.pow(distance, 2);
+ dy += factor * vy / Math.pow(distance, 2);
+ }
+ }
+ double dlen = dx * dx + dy * dy;
+ if (dlen > 0) {
+ dlen = Math.sqrt(dlen) / 2;
+ svd.repulsiondx += dx / dlen;
+ svd.repulsiondy += dy / dlen;
+ }
}
- }
- double dlen = dx * dx + dy * dy;
- if (dlen > 0){
- dlen = Math.sqrt(dlen) / 2;
- svd.repulsiondx += dx / dlen;
- svd.repulsiondy += dy / dlen;
- }
}
- }
- protected void moveNodes(){
+ protected void moveNodes(){
- synchronized (getCurrentSize()){
+ synchronized (getCurrentSize()) {
- for (Iterator i = getVisibleVertices().iterator(); i.hasNext();){
- Vertex v = (Vertex) i.next();
- if (dontMove(v)) continue;
- SpringVertexData vd = getSpringData(v);
- Coordinates xyd = getCoordinates(v);
+ for (Iterator i = getVisibleVertices().iterator(); i.hasNext();) {
+ Vertex v = (Vertex) i.next();
+ if (isNotCalculatedVertx(v)) {
+ continue;
+ }
+ if (dontMove(v)) continue;
+ SpringVertexData vd = getSpringData(v);
+ Coordinates xyd = getCoordinates(v);
- vd.dx += vd.repulsiondx + vd.edgedx;
- vd.dy += vd.repulsiondy + vd.edgedy;
+ vd.dx += vd.repulsiondx + vd.edgedx;
+ vd.dy += vd.repulsiondy + vd.edgedy;
- // keeps nodes from moving any faster than 5 per time unit
- xyd.addX(Math.max(-5, Math.min(5, vd.dx)));
- xyd.addY(Math.max(-5, Math.min(5, vd.dy)));
+ // keeps nodes from moving any faster than 5 per time unit
+ xyd.addX(Math.max(-5, Math.min(5, vd.dx)));
+ xyd.addY(Math.max(-5, Math.min(5, vd.dy)));
- int width = getCurrentSize().width;
- int height = getCurrentSize().height;
+ int width = getCurrentSize().width;
+ int height = getCurrentSize().height;
- // Bestimmte Knoten sollen die Karte verlassen dr\xFCfen
- if (!leaveFunction.canLeave(v)){
- if (xyd.getX() < 0){
- xyd.setX(0);
- } else if (xyd.getX() > width){
- xyd.setX(width);
- }
- if (xyd.getY() < 0){
- xyd.setY(0);
- } else if (xyd.getY() > height){
- xyd.setY(height);
- }
+ // Bestimmte Knoten sollen die Karte verlassen dr\xFCfen
+ if (!leaveFunction.canLeave(v)) {
+ if (xyd.getX() < 0) {
+ xyd.setX(0);
+ } else if (xyd.getX() > width) {
+ xyd.setX(width);
+ }
+ if (xyd.getY() < 0) {
+ xyd.setY(0);
+ } else if (xyd.getY() > height) {
+ xyd.setY(height);
+ }
+ }
+
+ }
}
- }
}
- }
+ public SpringVertexData getSpringData(Vertex v){
+ return (SpringVertexData) (v.getUserDatum(getSpringKey()));
+ }
- public SpringVertexData getSpringData(Vertex v){
- return (SpringVertexData) (v.getUserDatum(getSpringKey()));
- }
+ public SpringEdgeData getSpringData(Edge e){
+ try {
+ return (SpringEdgeData) (e.getUserDatum(getSpringKey()));
+ } catch (ClassCastException cce) {
+ System.out.println(e.getUserDatum(getSpringKey()).getClass());
+ throw cce;
+ }
+ }
- public SpringEdgeData getSpringData(Edge e){
- try{
- return (SpringEdgeData) (e.getUserDatum(getSpringKey()));
- } catch (ClassCastException cce){
- System.out.println(e.getUserDatum(getSpringKey()).getClass());
- throw cce;
+ public double getLength(Edge e){
+ double d = ((SpringEdgeData) e.getUserDatum(getSpringKey())).length;
+ return d;
}
- }
- public double getLength(Edge e){
- double d = ((SpringEdgeData) e.getUserDatum(getSpringKey())).length;
- return d;
- }
+ public void setLength(Edge e, double length){
+ ((SpringEdgeData) e.getUserDatum(getSpringKey())).length = length;
+ }
- public void setLength(Edge e, double length){
- ((SpringEdgeData) e.getUserDatum(getSpringKey())).length = length;
- }
+ /* --------------- Repulsion Function------------------ */
- /* --------------- Repulsion Function------------------ */
+ /**
+ * Extension for PACW: Make the Repulsion configurable.
+ *
+ *
+ * @author thuebner
+ */
+ public static interface RepulsionFunction {
- /**
- * Extension for PACW: Make the Repulsion configurable.
- *
- *
- * @author thuebner
- */
- public static interface RepulsionFunction {
+ public double getRepulsion(Vertex v1, Vertex v2);
+ }
+ public static RepulsionFunction NoRepulsionFunction = new RepulsionFunction() {
- public double getRepulsion(Vertex v1, Vertex v2);
- }
- public static RepulsionFunction NoRepulsionFunction = new RepulsionFunction(){
- public double getRepulsion(Vertex v1, Vertex v2) {
- return 0;
- }
- };
- /**
- * Extension for PACW: Make the Repulsion configurable.
- *
- *
- * @author thuebner
- */
- public static interface ForceFunction {
+ public double getRepulsion(Vertex v1, Vertex v2){
+ return 0;
+ }
+ };
/**
- * Sets the force multiplier for this instance. This value is used to
- * specify how strongly an edge "wants" to be its default length
- * (higher values indicate a greater attraction for the default length),
- * which affects how much its endpoints move at each timestep.
- * The default value is 1/3. A value of 0 turns off any attempt by the
- * layout to cause edges to conform to the default length. Negative
- * values cause long edges to get longer and short edges to get shorter; use
- * at your own risk.
- * @param v1
- * @param v2
+ * Extension for PACW: Make the Repulsion configurable.
+ *
+ *
+ * @author thuebner
*/
+ public static interface ForceFunction {
- public double getForce(Vertex v1, Vertex v2);
- }
+ /**
+ * Sets the force multiplier for this instance. This value is used to
+ * specify how strongly an edge "wants" to be its default length
+ * (higher values indicate a greater attraction for the default length),
+ * which affects how much its...
[truncated message content] |