private void applyChanges(final Hashtable<DefaultGraphCell, Map> map) { final Set<DefaultGraphCell> allchildren = parentship.keySet(); if (!map.isEmpty()) { glc.edit(map, null, null, null); for (Object key : map.keySet()) { if (GraphConstants.getBounds(map.get(key)) != null) { occupiedpositions.put((DefaultGraphCell) key, GraphConstants.getBounds(map.get(key)).getBounds()); } } } }
private void moveChildrenToParent(Hashtable map, Vector<DefaultGraphCell> children, Object changed, Map attsparent, Map newatts) { Rectangle2D coordParent = GraphConstants.getBounds(attsparent); Rectangle2D newCoordParent = GraphConstants.getBounds(newatts); Rectangle2D coordAtts = GraphConstants.getBounds(newatts); for (Object child : children) { Map attsChildren = dgm.getAttributes(child); // System.err.println("moving "+child); Rectangle2D coordChildren = GraphConstants.getBounds(attsChildren); int xchild = (int) coordChildren.getX(); int ychild = (int) coordChildren.getY(); int widthchild = (int) coordChildren.getWidth(); int heightchild = (int) coordChildren.getHeight(); xchild = (xchild + ((int) coordParent.getX() - (int) newCoordParent .getX())); ychild = ychild + ((int) coordParent.getY() - (int) newCoordParent.getY()); Hashtable newMap = new Hashtable(); GraphConstants.setBounds(newMap, new Rectangle(xchild, ychild, widthchild, heightchild)); map.put(child, newMap); } }
private Point calculateCenter(GraphCell[] selected){ int x=0; int y=0; for (int k=0;k<selected.length;k++){ GraphCell current=selected[k]; Rectangle rect=GraphConstants.getBounds(current.getAttributes()).getBounds(); x=x+rect.x+rect.width/2; y=y+rect. y+rect.height/2; } return new Point((int)(x/selected.length),(int)(y/selected.length)); }
private static Point calculateCenter(GraphCell[] selected){ int x=0; int y=0; for (int k=0;k<selected.length;k++){ GraphCell current=selected[k]; Rectangle rect=GraphConstants.getBounds(current.getAttributes()).getBounds(); x=x+rect.x+rect.width/2; y=y+rect. y+rect.height/2; } return new Point((int)(x/selected.length),(int)(y/selected.length)); }
private void moveChildrenToNewLocation(Hashtable<DefaultGraphCell, Map> map) { Vector<DefaultGraphCell> collectionkey = new Vector<DefaultGraphCell>( map.keySet()); for (Object key : collectionkey) { Vector<DefaultGraphCell> children = getChildren(key); // System.err.println("moving "+children); Map attsparent = (Map) (dgm.getAttributes(key)); Map newAtts = (Map) map.get(key); if (GraphConstants.getBounds(newAtts) != null) moveChildrenToParent(map, children, key, attsparent, newAtts); } }
private void initializeOccupiedPositions() { occupiedpositions.clear(); for (Object obj : dgm.getRoots()) { if (obj instanceof DefaultGraphCell) { // if (getChildren(obj).isEmpty()){ if (dgm.getAttributes(obj) != null && GraphConstants.getBounds(dgm.getAttributes(obj)) != null) occupiedpositions.put((DefaultGraphCell) obj, GraphConstants.getBounds(dgm.getAttributes(obj))); // } } } }
private Rectangle2D getBoundsCoordinates(DefaultGraphCell cell) { AttributeMap atts = target.getModel().getAttributes(cell); if (atts==null) return null; Rectangle2D bounds = GraphConstants.getBounds(atts); if (bounds==null) return null; return bounds; }
/** * Reads the bounds from the nested map for each cell and invokes setBounds * for that cell with a clone of the bounds. * * @param nestedMap * A map of (cell, map) pairs * * @see GraphConstants#getBounds(Map) */ public void setBounds(Map nestedMap) { if (nestedMap != null) { Iterator it = nestedMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Rectangle2D bounds = GraphConstants.getBounds((Map) entry .getValue()); if (bounds != null) { setBounds(entry.getKey(), (Rectangle2D) bounds.clone()); } } } }
private Point getFreeCoordinates(DefaultGraphCell cell) { AttributeMap atts = target.getModel().getAttributes(cell); if (atts==null) return null; Rectangle2D bounds = GraphConstants.getBounds(atts); Point centerPoint = new Point((int)bounds.getMinX(),(int)bounds.getMinY()); Object nextCell=null; do { nextCell=target.getNextCellForLocation(cell, centerPoint.x, centerPoint.y); if (nextCell!=null && nextCell!=cell){ centerPoint.x=centerPoint.x+10; if (centerPoint.x>bounds.getMaxX()){ centerPoint.x=(int) bounds.getMinX(); centerPoint.y=centerPoint.y+5; if (centerPoint.y>bounds.getMaxY()) nextCell=null; } } } while(nextCell!=null && nextCell!=cell); return centerPoint; }
private Rectangle2D getBounds(DefaultGraphCell cell) { AttributeMap atts = target.getModel().getAttributes(cell); if (atts==null) return null; Rectangle2D bounds = GraphConstants.getBounds(atts); return bounds; }
/** * Translates <code>map</code> by the given amount. */ public void translate(double dx, double dy) { // Translate Bounds if (GraphConstants.isMoveable(this)) { Rectangle2D bounds = GraphConstants.getBounds(this); if (bounds != null) { int moveableAxis = GraphConstants.getMoveableAxis(this); if (moveableAxis == GraphConstants.X_AXIS) dy = 0; else if (moveableAxis == GraphConstants.Y_AXIS) dx = 0; bounds.setFrame(bounds.getX() + dx, bounds.getY() + dy, bounds .getWidth(), bounds.getHeight()); } // Translate Points List points = GraphConstants.getPoints(this); if (points != null) { for (int i = 0; i < points.size(); i++) { Object obj = points.get(i); if (obj instanceof Point2D) { Point2D pt = (Point2D) obj; pt.setLocation(pt.getX() + dx, pt.getY() + dy); } } } } }
private Point getCentralCoordinates(DefaultGraphCell cell) { AttributeMap atts = target.getModel().getAttributes(cell); if (atts==null) return null; Rectangle2D bounds = GraphConstants.getBounds(atts); if (bounds==null) return null; return new Point((int)bounds.getCenterX(),(int)bounds.getCenterY()); }
public void updateAutoSize(CellView view) { if (!view.isLeaf()) { CellView[] children = view.getChildViews(); Rectangle2D rect = GraphConstants.getBounds(children[0] .getAllAttributes()); double x = rect.getMaxX() + 10; double y = rect.getY(); for (int index = 1; index < children.length; index++) { Rectangle2D childRect = GraphConstants .getBounds(children[index].getAllAttributes()); childRect.setFrame(x, y, childRect.getWidth(), childRect .getHeight()); x += childRect.getWidth() + 10; children[index].update(); } } else { super.updateAutoSize(view); } }
/** * Overrides the parent method to udpate the cached points. */ public void update(GraphLayoutCache cache) { super.update(cache); bounds = GraphConstants.getBounds(allAttributes); if (bounds == null) { bounds = allAttributes.createRect(defaultBounds); GraphConstants.setBounds(allAttributes, bounds); } groupBounds = null; }
@SuppressWarnings("unchecked") // FIXME hb 28-nov-05: See FIXME below private void positionVertexAt(Object vertex, int x, int y) { DefaultGraphCell cell = jgAdapter.getVertexCell(vertex); AttributeMap attr = cell.getAttributes(); Rectangle2D bounds = GraphConstants.getBounds(attr); Rectangle2D newBounds = new Rectangle2D.Double( x, y, bounds.getWidth(), bounds.getHeight()); GraphConstants.setBounds(attr, newBounds); // TODO: Clean up generics once JGraph goes generic AttributeMap cellAttr = new AttributeMap(); cellAttr.put(cell, attr); jgAdapter.edit(cellAttr, null, null, null); }
protected void cellWillCollapse(Object cell) { GraphModel model = getModel(); if (movesParentsOnCollapse) { CellView view = getMapping(cell, false); if (view != null && !view.isLeaf()) { // Uses view-local attribute if available AttributeMap attrs = view.getAttributes(); if (!attrs.contains(GraphConstants.BOUNDS) && !localAttributes.contains(GraphConstants.BOUNDS)) attrs = model.getAttributes(cell); // Moves the group to the origin of the children Rectangle2D src = GraphConstants.getBounds(attrs); Rectangle2D b = view.getBounds(); // FIXME: What if the group is exactly at "defaultBounds"? if (resizesParentsOnCollapse || src == null || src.equals(VertexView.defaultBounds)) { src = attrs.createRect(b.getX(), b.getY(), b.getWidth() * collapseXScale, b.getHeight() * collapseYScale); attrs.applyValue(GraphConstants.BOUNDS, src); } else { src.setFrame(b.getX(), b.getY(), src.getWidth(), src .getHeight()); } } } }
public void restoreContraints(DefaultGraphCell cell) { Entity ent=(Entity)cell.getUserObject(); Hashtable<DefaultGraphCell, Dimension> cellDimension = entityConstraints .get(this.hashCode()+":"+cell.hashCode() + ":" + ent.getPrefs(jg.getModel().getAttributes(cell)).getView()); Hashtable<Object, Map> changes = new Hashtable<Object, Map>(); if (cellDimension != null) { for (DefaultGraphCell dgc : cellDimension.keySet()) { if (dgc.getAttributes() != null) { // still exists Map oldmap = dgc.getAttributes(); Rectangle oldbounds = GraphConstants.getBounds(oldmap) .getBounds(); oldbounds.setSize(cellDimension.get(dgc)); GraphConstants.setBounds(oldmap, oldbounds); changes.put(dgc, oldmap); } } jg.getModel().edit(changes, null, null, null); jg.invalidate(); jg.repaint(); } }
public static void solveOverlappings(ModelJGraph graph, Hashtable<DefaultGraphCell, Map> map) { Hashtable<Object,Map> naryedgeatts=new Hashtable<Object,Map>(); for (int k=0;k<graph.getModel().getRootCount();k++){ if (graph.getModel().getRootAt(k) instanceof NAryEdge){ /*if (changes.get(graph.getModel().getRootAt(k))!=null) naryedgeatts.put(graph.getModel().getRootAt(k), changes.get(graph.getModel().getRootAt(k))); else*/ naryedgeatts.put(graph.getModel().getRootAt(k), graph.getModel().getAttributes(graph.getModel().getRootAt(k))); } } Set<DefaultGraphCell> naries = map.keySet(); for (Object currentnary:naries){ if (currentnary instanceof NAryEdge){ Rectangle2D rect1= GraphConstants.getBounds(map.get(currentnary)); detectingOverlappingsAndRadialLayout(map, naryedgeatts, currentnary, rect1,graph); } } }
private static boolean detectEdgeIntersections(Rectangle rect1, JGraph graph, boolean intersectsline, Object port) { Iterator edges = graph.getModel().edges(port); while (edges.hasNext()){ Object edge=edges.next(); Object targetport = graph.getModel().getTarget(edge); Object sourceport = graph.getModel().getSource(edge); AttributeMap attargetport = graph.getModel().getAttributes(graph.getModel().getParent(targetport)); AttributeMap atsourceport = graph.getModel().getAttributes(graph.getModel().getParent(sourceport)); Rectangle b1 = GraphConstants.getBounds(attargetport).getBounds(); Rectangle b2 = GraphConstants.getBounds(atsourceport).getBounds(); Float line = new Line2D.Float(new Point((int)b1.getCenterX(),(int)b1.getCenterY()),new Point((int)b2.getCenterX(),(int)b2.getCenterY())); intersectsline=intersectsline||line.intersects(rect1); if (!(graph.getModel().getParent(targetport) instanceof NAryEdge) && !ListenerContainer.isContainer((DefaultGraphCell) graph.getModel().getParent(targetport), graph)){ intersectsline=intersectsline || b1.intersects(rect1); // System.err.println("overlapping1 with "+targetport+","+graph.getModel().getParent(targetport)+" "+rect1+":"+b1); } else if (!(graph.getModel().getParent(sourceport) instanceof NAryEdge) && !ListenerContainer.isContainer((DefaultGraphCell) graph.getModel().getParent(sourceport), graph)){ intersectsline=intersectsline || b2.intersects(rect1); // System.err.println("overlapping2 with "+sourceport+","+graph.getModel().getParent(sourceport)+" "+rect1+":"+b2); } } return intersectsline; }
/** * Clones special object entried in the given map. */ public AttributeMap cloneEntries(AttributeMap newMap) { // Clone Bounds Rectangle2D bounds = GraphConstants.getBounds(newMap); if (bounds != null) GraphConstants.setBounds(newMap, (Rectangle2D) (bounds.clone())); // Clone List Of Points List points = GraphConstants.getPoints(newMap); if (points != null) GraphConstants.setPoints(newMap, clonePoints(points)); // Clone extra label positions Point2D[] positions = GraphConstants.getExtraLabelPositions(newMap); if (positions != null) GraphConstants.setExtraLabelPositions(newMap, clonePoints(positions)); // Clone Edge Label Point2D label = GraphConstants.getLabelPosition(newMap); if (label != null) GraphConstants.setLabelPosition(newMap, (Point2D) label.clone()); return newMap; }