[graphl-cvs] graphl/src/org/mediavirus/graphl/layout AbsoluteNodeLayouter.java SpringEdgeLayouter.j
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2006-06-08 13:15:46
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv17343/src/org/mediavirus/graphl/layout Modified Files: AbsoluteNodeLayouter.java SpringEdgeLayouter.java GraphlLayoutStrategy.java Removed Files: AbsoluteNodeLayouterController.java Log Message: a lot of changes done a long time ago... changelog has to be updated another time :( Index: GraphlLayoutStrategy.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/GraphlLayoutStrategy.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GraphlLayoutStrategy.java 18 Dec 2005 11:11:40 -0000 1.13 --- GraphlLayoutStrategy.java 8 Jun 2006 13:14:57 -0000 1.14 *************** *** 90,93 **** --- 90,94 ---- public void executeGraphLayoutStep() { //long layoutStartTime=System.currentTimeMillis(); + //System.out.println(" executeGraphLayoutStep()"); for (int i=0;i<10;i++) { layoutEdges(); *************** *** 128,131 **** --- 129,133 ---- double lastMaxMotion=graphManager.maxMotion; graphManager.maxMotion=0; + // prevent copncurrent modifications through loading etc. Iterator iterator=graph.getNodes().iterator(); while (iterator.hasNext()) { --- AbsoluteNodeLayouterController.java DELETED --- Index: SpringEdgeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/SpringEdgeLayouter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SpringEdgeLayouter.java 18 Dec 2005 11:11:40 -0000 1.10 --- SpringEdgeLayouter.java 8 Jun 2006 13:14:57 -0000 1.11 *************** *** 11,14 **** --- 11,15 ---- import org.mediavirus.graphl.graph.Edge; import org.mediavirus.graphl.graph.Node; + import org.mediavirus.graphl.jxpath.JXPathFactory; import org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager; import org.mediavirus.graphl.view.AbstractFacet; *************** *** 21,25 **** public class SpringEdgeLayouter extends AbstractFacet implements EdgeLayouter { ! float defaultLength = 40.0f; float defaultRigidity = 1.0f; --- 22,26 ---- public class SpringEdgeLayouter extends AbstractFacet implements EdgeLayouter { ! float defaultLength = 300.0f; float defaultRigidity = 1.0f; *************** *** 34,38 **** protected Spring(float length, float rigidity) { - this.length = length; this.rigidity = rigidity; --- 35,38 ---- *************** *** 54,59 **** if (lengthExpr != null || rigidityExpr != null) { ! JXPathContext context = JXPathContext.newContext(edge); ! context.setLenient(true); if (lengthExpr != null) { Object lengthO = context.getValue(lengthExpr); --- 54,58 ---- if (lengthExpr != null || rigidityExpr != null) { ! JXPathContext context = JXPathFactory.createContext(edge); if (lengthExpr != null) { Object lengthO = context.getValue(lengthExpr); *************** *** 82,89 **** Node from = edge.getFrom(); Node to = edge.getTo(); double deltaX = to.getCenterX() - from.getCenterX(); double deltaY = to.getCenterY() - from.getCenterY(); double currentLength = Math.sqrt(deltaX * deltaX + deltaY * deltaY); ! double factor = spring.rigidity * currentLength / (spring.length * 100.0f); double dx = deltaX * factor; double dy = deltaY * factor; --- 81,93 ---- Node from = edge.getFrom(); Node to = edge.getTo(); + double deltaX = to.getCenterX() - from.getCenterX(); double deltaY = to.getCenterY() - from.getCenterY(); + double currentLength = Math.sqrt(deltaX * deltaX + deltaY * deltaY); ! double factor = spring.rigidity * currentLength / (spring.length * 100.0); ! //double factor = (spring.rigidity * currentLength / 2000.0) * (spring.rigidity * currentLength / 2000.0) - (spring.rigidity * spring.length / 2000.0) * (spring.rigidity * spring.length / 2000.0); ! //double factor = spring.rigidity * currentLength / 1000.0 - spring.rigidity * spring.length / 1000.0; ! //System.out.println("currentLenght: " + currentLength + " spring length: " + spring.length + " factor: " + factor); double dx = deltaX * factor; double dy = deltaY * factor; *************** *** 205,207 **** --- 209,215 ---- } + public void refresh() { + springCache.clear(); + } + } Index: AbsoluteNodeLayouter.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/layout/AbsoluteNodeLayouter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AbsoluteNodeLayouter.java 17 Aug 2005 15:52:49 -0000 1.9 --- AbsoluteNodeLayouter.java 8 Jun 2006 13:14:57 -0000 1.10 *************** *** 5,18 **** package org.mediavirus.graphl.layout; import java.awt.geom.Point2D; ! import java.awt.geom.Rectangle2D; ! ! import javax.swing.JComponent; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager; import org.mediavirus.graphl.view.AbstractFacet; import org.mediavirus.graphl.vocabulary.NS; - import org.mediavirus.util.ParseUtils; /** --- 5,19 ---- package org.mediavirus.graphl.layout; + import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; ! import java.util.HashMap; ! import java.util.Map; + import org.apache.commons.jxpath.JXPathContext; import org.mediavirus.graphl.graph.Node; + import org.mediavirus.graphl.jxpath.JXPathFactory; import org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager; import org.mediavirus.graphl.view.AbstractFacet; import org.mediavirus.graphl.vocabulary.NS; /** *************** *** 22,166 **** public class AbsoluteNodeLayouter extends AbstractFacet implements NodeLayouter { ! public static final int FIXED = 0; ! public static final int PROPERTY = 1; ! public static final int GEO = 2; ! ! Point2D target = new Point2D.Float(0.0f,0.0f); ! Point2D scale = new Point2D.Float(1.0f, 1.0f); ! Point2D offset = new Point2D.Float(0.0f, 0.0f); ! ! int method = FIXED; ! String property = null; - boolean draggable = true; - /** * @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager manager) { ! if (method == FIXED) { ! if (draggable && node.isDragging()) { ! setTarget(new Point2D.Double(node.getCenterX()/scale.getX()-offset.getX(), node.getCenterY()/scale.getY()-offset.getY())); ! } ! else { ! node.setCenter((target.getX()+offset.getX())*scale.getX(), (target.getY()+offset.getY())*scale.getY()); ! } ! } ! else if (method == PROPERTY){ ! Node n = node.getFirstNeighbour(property, true); ! if (n != null) { ! Rectangle2D r = getAreaForGeoNode(n); ! if (r != null) { ! node.setCenter(r.getCenterX(), r.getCenterY()); ! node.setSize(r.getWidth(), r.getHeight()); ! // TODO (2) make this configurable ! node.setZIndex(0); ! } ! else { ! Point2D p = getLocationForGeoNode(n); ! node.setCenter((p.getX()+offset.getX())*scale.getX(), (p.getY()+offset.getY())*scale.getY()); ! } ! } ! } ! else if (method == GEO) { ! Rectangle2D r = getAreaForGeoNode(node); ! if (r != null) { ! node.setCenter(r.getCenterX(), r.getCenterY()); ! node.setSize(r.getWidth(), r.getHeight()); ! // TODO (2) make this configurable ! node.setZIndex(0); ! } ! else { ! Point2D p = getLocationForGeoNode(node); ! node.setCenter((p.getX()+offset.getX())*scale.getX(), (p.getY()+offset.getY())*scale.getY()); ! } } } ! private static Point2D getLocationForGeoNode(Node node) { ! float lat = 0.0f, lon = 0.0f; ! ! String str = node.getProperty("http://www.w3.org/2003/01/geo/wgs84_pos#long"); ! if (str != null) { ! try { ! lon = Float.parseFloat(str); ! } ! catch (Exception e) { ! } ! } ! ! str = node.getProperty("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); ! if (str != null) { ! try { ! lat = Float.parseFloat(str); ! } ! catch (Exception e) { } ! } ! ! Node n = node.getFirstNeighbour("http://www.funkfeuer.at/vocab#map", true); ! if (n != null) { ! n = n.getFirstNeighbour("http://www.funkfeuer.at/vocab#transformation", true); ! if (n != null) { ! str = n.getProperty("http://www.funkfeuer.at/vocab#matrix3"); ! float[] mat = ParseUtils.parseMatrix(str); ! float x = lon * mat[0] + lat * mat[1] + mat[2]; ! float y = lon * mat[3] + lat * mat[4] + mat[5]; ! lon = x; ! lat = y; ! } ! } ! return new Point2D.Float(lon, lat); } ! private static Rectangle2D getAreaForGeoNode(Node node) { ! float xmin = 0.0f, xmax = 0.0f, ymin = 0.0f, ymax = 0.0f; ! String str = node.getProperty("http://fabl.net/vocabularies/geometry/1.1/xmin"); ! if (str != null) { ! try { ! xmin = Float.parseFloat(str); ! } ! catch (Exception e) { ! return null; ! } ! } ! else return null; ! str = node.getProperty("http://fabl.net/vocabularies/geometry/1.1/xmax"); ! if (str != null) { ! try { ! xmax = Float.parseFloat(str); ! } ! catch (Exception e) { ! return null; ! } ! } ! else return null; ! str = node.getProperty("http://fabl.net/vocabularies/geometry/1.1/ymin"); ! if (str != null) { ! try { ! ymin = Float.parseFloat(str); ! } ! catch (Exception e) { ! return null; } ! } ! else return null; ! str = node.getProperty("http://fabl.net/vocabularies/geometry/1.1/ymax"); ! if (str != null) { ! try { ! ymax = Float.parseFloat(str); ! } ! catch (Exception e) { ! return null; ! } ! } ! else return null; - return new Rectangle2D.Float(xmin,ymin,xmax-xmin,ymax-ymin); } --- 23,127 ---- public class AbsoluteNodeLayouter extends AbstractFacet implements NodeLayouter { ! String xExpr; ! String yExpr; ! String widthExpr; ! String heightExpr; ! ! AffineTransform transform = new AffineTransform(); ! ! Map<Node, Point2D> positionCache = new HashMap<Node, Point2D>(); ! Map<Node, Point2D> sizeCache = new HashMap<Node, Point2D>(); /** * @see org.mediavirus.graphl.layout.NodeLayouter#performLayoutStep(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.layout.GraphlLayoutStrategy.GraphManager) */ public void performLayoutStep(Node node, GraphManager manager) { ! Point2D pos = getPosition(node); ! Point2D size = getSize(node); ! if (pos != null) { ! pos = transform.transform(pos, new Point2D.Double()); ! node.setCenter(pos.getX(), pos.getY()); } + if (size != null) { + node.setSize(size.getX(), size.getY()); + } } ! private Point2D getPosition(Node node) { ! Point2D pos = positionCache.get(node); ! ! if (pos == null) { ! double x = 0; ! double y = 0; ! ! if (xExpr != null || yExpr != null) { ! JXPathContext context = JXPathFactory.createContext(node); ! if (xExpr != null) { ! Object xO = context.getValue(xExpr); ! try { ! x = ((Double) xO).doubleValue(); ! x -= 51; ! x *= 100; ! } ! catch (Exception ex) { ! } ! } ! ! if (yExpr != null) { ! Object yO = context.getValue(yExpr); ! try { ! y = ((Double) yO).doubleValue(); ! //y -= 51.51; ! y *= 100; ! } ! catch (Exception ex) { ! } ! } } ! System.out.println("pos: " + x + ":" + y); ! pos = new Point2D.Double(x, y); ! positionCache.put(node, pos); ! } ! ! return pos; } ! private Point2D getSize(Node node) { ! Point2D size = sizeCache.get(node); ! if (size == null) { ! double width = 0; ! double height = 0; ! if (widthExpr != null || heightExpr != null) { ! JXPathContext context = JXPathFactory.createContext(node); ! if (widthExpr != null) { ! Object widthO = context.getValue(widthExpr); ! try { ! width = ((Double) widthO).doubleValue(); ! } ! catch (Exception ex) { ! } ! } ! if (heightExpr != null) { ! Object heightO = context.getValue(heightExpr); ! try { ! height = ((Double) heightO).doubleValue(); ! } ! catch (Exception ex) { ! } ! } } ! else return null; ! ! size = new Point2D.Double(width, height); ! sizeCache.put(node, size); ! } ! ! return size; } *************** *** 173,183 **** /* - * Overrides @see org.mediavirus.graphl.view.Facet#getVisualController() - */ - public JComponent getVisualController() { - return new AbsoluteNodeLayouterController(this); - } - - /* * Overrides @see org.mediavirus.graphl.view.Facet#isSameClass(java.lang.Object) */ --- 134,137 ---- *************** *** 186,250 **** } - /** - * @return Returns the offset. - */ - public Point2D getOffset() { - return offset; - } - /** - * @param offset The offset to set. - */ - public void setOffset(Point2D offset) { - this.offset = offset; - } - /** - * @return Returns the scale. - */ - public Point2D getScale() { - return scale; - } - /** - * @param scale The scale to set. - */ - public void setScale(Point2D scale) { - this.scale = scale; - } - - /** - * @return Returns the method. - */ - public int getMethod() { - return method; - } - /** - * @param method The method to set. - */ - public void setMethod(int method) { - this.method = method; - } - /** - * @return Returns the property. - */ - public String getProperty() { - return property; - } - /** - * @param property The property to set. - */ - public void setProperty(String property) { - this.property = property; - } - /** - * @return Returns the target. - */ - public Point2D getTarget() { - return target; - } - /** - * @param target The target to set. - */ - public void setTarget(Point2D target) { - this.target = target; - } /* * Overrides @see java.lang.Object#clone() --- 140,143 ---- *************** *** 269,299 **** */ public boolean isDraggable() { ! return draggable; } - public void setDraggable(boolean draggable) { - this.draggable = draggable; - } - public void setConfigurationNode(Node node) { ! String str = node.getProperty(NS.graphl + "method"); ! if ( str != null) { ! if (str.equalsIgnoreCase("property")) { ! setMethod(PROPERTY); ! } ! else if (str.equalsIgnoreCase("geo")) { ! setMethod(GEO); ! } ! else { ! setMethod(FIXED); ! } ! } ! ! str = node.getProperty(NS.graphl + "property"); ! if (str != null) setProperty(str); ! ! str = node.getProperty(NS.graphl + "draggable"); ! if (str != null) setDraggable(Boolean.valueOf(str).booleanValue()); } } --- 162,225 ---- */ public boolean isDraggable() { ! // TODO: implement draggable absolute layout by writing properties upon drag ! return false; } public void setConfigurationNode(Node node) { ! xExpr = node.getProperty(NS.graphl + "x"); ! yExpr = node.getProperty(NS.graphl + "y"); ! widthExpr = node.getProperty(NS.graphl + "width"); ! heightExpr = node.getProperty(NS.graphl + "height"); } + + + public String getHeightExpr() { + return heightExpr; + } + + + public void setHeightExpr(String heightExpr) { + this.heightExpr = heightExpr; + } + + + public String getWidthExpr() { + return widthExpr; + } + + + public void setWidthExpr(String widthExpr) { + this.widthExpr = widthExpr; + } + + + public String getXExpr() { + return xExpr; + } + + + public void setXExpr(String expr) { + xExpr = expr; + } + + + public String getYExpr() { + return yExpr; + } + + + public void setYExpr(String expr) { + yExpr = expr; + } + + + public AffineTransform getTransform() { + return transform; + } + + + public void setTransform(AffineTransform transform) { + this.transform = transform; + } } |