public double getHeight() { return view.getBounds().getHeight(); }
public double getWidth() { return view.getBounds().getWidth(); }
public double getY() { return view.getBounds().getY(); }
public double getX() { return view.getBounds().getX(); }
/** * Returns the bounding rectangle of the specified cell. */ public Rectangle2D getCellBounds(Object cell) { CellView view = graphLayoutCache.getMapping(cell, false); if (view != null) return view.getBounds(); return null; }
public void setRect(double x, double y, double w, double h) { view.getBounds().setRect(x, y, w, h); }
/** * Return all root cells that intersect the given rectangle. */ public CellView[] getRoots(Rectangle2D clip) { java.util.List result = new ArrayList(); CellView[] views = getRoots(); for (int i = 0; i < views.length; i++) if (views[i].getBounds().intersects(clip)) result.add(views[i]); views = new CellView[result.size()]; result.toArray(views); return views; }
public static Point2D getCenterPoint(CellView vertex) { Rectangle2D r = vertex.getBounds(); if (r != null) return new Point2D.Double(r.getCenterX(), r.getCenterY()); return null; }
/** * Returns the bounding box for the specified views. * * @param views * the views for whom the bounding box is to be determined * @return the bounding box of the specified views */ public static Rectangle2D getBounds(CellView[] views) { if (views != null && views.length > 0) { Rectangle2D ret = null; for (int i = 0; i < views.length; i++) { if (views[i] != null) { Rectangle2D r = views[i].getBounds(); if (r != null) { if (ret == null) ret = new Rectangle2D.Double(r.getX(), r.getY(), r .getWidth(), r.getHeight()); else Rectangle2D.union(ret, r, ret); } } } return ret; } return null; }
/** * Returns the bounding box for the specified cell views. */ public static Rectangle2D getBounds(CellView[] views) { if (views != null && views.length > 0) { Rectangle2D r = (views[0] != null) ? views[0].getBounds() : null; Rectangle2D ret = (r != null) ? (Rectangle2D) r.clone() : null; for (int i = 1; i < views.length; i++) { r = (views[i] != null) ? views[i].getBounds() : null; if (r != null) { if (ret == null) ret = (r != null) ? (Rectangle2D) r.clone() : null; else Rectangle2D.union(ret, r, ret); } } return ret; } return null; }
/** * Returns the bounds to be used to highlight the given cell view. * * @param graph * @param cellView * @return */ protected Rectangle getHighlightBounds(JGraph graph, CellView cellView) { boolean offset = (GraphConstants.getOffset(cellView.getAllAttributes()) != null); Rectangle2D r = (offset) ? cellView.getBounds() : cellView .getParentView().getBounds(); r = graph.toScreen((Rectangle2D) r.clone()); int s = 3; return new Rectangle((int) (r.getX() - s), (int) (r.getY() - s), (int) (r.getWidth() + 2 * s), (int) (r.getHeight() + 2 * s)); }
protected void paintPort(Graphics g, CellView p) { boolean offset = (GraphConstants.getOffset(p.getAllAttributes()) != null); Rectangle2D r = (offset) ? p.getBounds() : p.getParentView() .getBounds(); r = graph.toScreen((Rectangle2D) r.clone()); int s = 3; r.setFrame(r.getX() - s, r.getY() - s, r.getWidth() + 2 * s, r .getHeight() + 2 * s); graph.getUI().paintCell(g, p, r, true); }
public Point2D getPoint(int index) { Object obj = points.get(index); if (obj instanceof PortView) { return ((PortView) obj).getLocation(this, getPointLocation((index == 0) ? 1 : points .size() - 2)); } else if (obj instanceof VirtualNode) { return ((VirtualNode) obj).getPosition(); } else if (obj instanceof CellView) { System.err.println("CellView!"); Rectangle2D r = ((CellView) obj).getBounds(); return getAttributes().createPoint(r.getX(), r.getY()); } else if (obj instanceof Point2D) // Regular Point return (Point2D) obj; return null; }
/** * Hook for subclassers. Current implementation checks if graph selection is * enabled. This is called from mouseReleased to execute the marquee * selection. */ public void handleMarqueeEvent(MouseEvent e, JGraph graph, Rectangle2D bounds) { CellView[] views = graph.getGraphLayoutCache().getRoots(bounds); ArrayList list = new ArrayList(); for (int i = 0; i < views.length; i++) // above returns intersection, we want containment if (bounds.contains(views[i].getBounds())) list.add(views[i].getCell()); Object[] cells = list.toArray(); graph.getUI().selectCellsForEvent(graph, cells, e); }
/** * Overriding this in order to set the size of an editor to that of an * edited view. */ public Component getGraphCellEditorComponent(JGraph graph, Object cell, boolean isSelected) { Component component = super.getGraphCellEditorComponent(graph, cell, isSelected); // set the size of an editor to that of the view CellView view = graph.getGraphLayoutCache().getMapping(cell, false); Rectangle2D tmp = view.getBounds(); editingComponent.setBounds((int) tmp.getX(), (int) tmp.getY(), (int) tmp.getWidth(), (int) tmp.getHeight()); // I have to set a font here instead of in the // RealCellEditor.getGraphCellEditorComponent() because // I don't know what cell is being edited when in the // RealCellEditor.getGraphCellEditorComponent(). Font font = GraphConstants.getFont(view.getAllAttributes()); editingComponent.setFont((font != null) ? font : graph.getFont()); return component; }
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()); } } } }
/** * Hook method to allow subclassers to alter just the cell painting * functionality * * @param g * the graphics object to paint to * @param realClipBounds * the bounds of the region being repainted */ protected void paintCells(Graphics g, Rectangle2D realClipBounds) { CellView[] views = graphLayoutCache.getRoots(); for (int i = 0; i < views.length; i++) { Rectangle2D bounds = views[i].getBounds(); if (bounds != null) { if (realClipBounds == null) { paintCell(g, views[i], bounds, false); } else if (bounds.intersects(realClipBounds)) { paintCell(g, views[i], bounds, false); } } } }
/** * Returns the topmost cell view at the specified location using the view's * bounds on non-leafs to check for containment. If reverse is true this * will return the innermost view. */ public CellView getTopmostViewAt(double x, double y, boolean reverse, boolean leafsOnly) { Rectangle2D r = new Rectangle2D.Double(x, y, 1, 1); Object[] cells = getDescendants(getRoots()); for (int i = (reverse) ? cells.length - 1 : 0; i >= 0 && i < cells.length; i += (reverse) ? -1 : +1) { CellView view = getGraphLayoutCache().getMapping(cells[i], false); if (view != null && (!leafsOnly || view.isLeaf()) && ((view.isLeaf() && view.intersects(this, r)) || (!view .isLeaf() && view.getBounds().contains(x, y)))) return view; } return null; }
/** * Used for move into group to find the target group. */ protected CellView findUnselectedInnermostGroup(double x, double y) { Object[] cells = graph.getDescendants(graph.getRoots()); for (int i = cells.length - 1; i >= 0; i--) { CellView view = graph.getGraphLayoutCache().getMapping( cells[i], false); if (view != null && !view.isLeaf() && !context.contains(view.getCell()) && view.getBounds().contains(x, y)) return view; } return null; }
/** * Description of the Method * *@param g Description of Parameter */ protected void paintPort(Graphics g) { // If Current Port is Valid if (port != null) { // If Not Floating Port... boolean o = (GraphConstants.getOffset(port.getAttributes()) != null); // ...Then use Parent's Bounds Rectangle r = (o) ? port.getBounds().getBounds() : port.getParentView().getBounds().getBounds(); // Scale from Model to Screen r = getGraph().toScreen(new Rectangle(r)).getBounds(); // Add Space For the Highlight Border r.setBounds(r.x - 3, r.y - 3, r.width + 6, r.height + 6); // Paint Port in Preview (=Highlight) Mode //getGraph().getUI().paintCell(g, port, r, true); } }