Java Code Examples for edu.uci.ics.jung.algorithms.layout.Layout#transform()
The following examples show how to use
edu.uci.ics.jung.algorithms.layout.Layout#transform() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeModelNodeRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>. */ protected void paintIconForVertex(RenderContext<V, E> rc, V v, Layout<V, E> layout) { GraphicsDecorator g = rc.getGraphicsContext(); boolean vertexHit = true; // get the shape to be rendered Shape shape = rc.getVertexShapeTransformer().transform(v); Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); float x = (float) p.getX(); float y = (float) p.getY(); // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x, y); // transform the vertex shape with xtransform shape = xform.createTransformedShape(shape); vertexHit = vertexHit(rc, shape); // rc.getViewTransformer().transform(shape).intersects(deviceRectangle); if (vertexHit) { if (rc.getVertexIconTransformer() != null) { Icon icon = rc.getVertexIconTransformer().transform(v); if (icon != null) { g.draw(icon, rc.getScreenDevice(), shape, (int) x, (int) y); } else { paintShapeForVertex(rc, v, shape); } } else { paintShapeForVertex(rc, v, shape); } } }
Example 2
Source File: ExtendedPickingGraphMousePlugin.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * If the mouse is over a picked vertex, drag all picked vertices with the mouse. If the mouse * is not over a Vertex, draw the rectangle to select multiple Vertices * */ @Override @SuppressWarnings("unchecked") public void mouseDragged(MouseEvent e) { if (locked == false) { VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource(); if (vertex != null) { Point p = e.getPoint(); Point2D graphPoint = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p); Point2D graphDown = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(down); Layout<V, E> layout = vv.getGraphLayout(); double dx = graphPoint.getX() - graphDown.getX(); double dy = graphPoint.getY() - graphDown.getY(); PickedState<V> ps = vv.getPickedVertexState(); for (V v : ps.getPicked()) { Point2D vp = layout.transform(v); vp.setLocation(vp.getX() + dx, vp.getY() + dy); layout.setLocation(v, vp); } down = p; } else { if (rectangleSelectionEnabled) { Point2D out = e.getPoint(); if (e.getModifiers() == this.addToSelectionModifiers || e.getModifiers() == modifiers) { rect.setFrameFromDiagonal(down, out); } } } if (vertex != null) { e.consume(); } vv.repaint(); } }
Example 3
Source File: VertexDemo.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public void paintIconForVertex(RenderContext<V,E> rc, V v, Layout<V,E> layout) { Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); float x = (float)p.getX(); float y = (float)p.getY(); GraphicsDecorator g = rc.getGraphicsContext(); boolean outlineImages = false; Transformer<V,Icon> vertexIconFunction = rc.getVertexIconTransformer(); if(vertexIconFunction instanceof DemoVertexIconTransformer) { outlineImages = ((DemoVertexIconTransformer<V>)vertexIconFunction).isOutlineImages(); } Icon icon = vertexIconFunction.transform(v); if(icon == null || outlineImages) { Shape s = AffineTransform.getTranslateInstance(x,y). createTransformedShape(rc.getVertexShapeTransformer().transform(v)); paintShapeForVertex(rc, v, s); } if(icon != null) { int xLoc = (int) (x - icon.getIconWidth()/2); int yLoc = (int) (y - icon.getIconHeight()/2); icon.paintIcon(rc.getScreenDevice(), g.getDelegate(), xLoc, yLoc); } }
Example 4
Source File: TreeModelEdgeLabelRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) { if (label == null || label.length() == 0) { return; } Graph<V, E> graph = layout.getGraph(); // don't draw edge if either incident vertex is not drawn Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v2))) { return; } Point2D p1 = layout.transform(v1); Point2D p2 = layout.transform(v2); p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); GraphicsDecorator g = rc.getGraphicsContext(); float distX = x2 - x1; float distY = y2 - y1; double totalLength = Math.sqrt(distX * distX + distY * distY); double closeness = rc.getEdgeLabelClosenessTransformer().transform(Context.<Graph<V, E>, E> getInstance(graph, e)) .doubleValue(); int posX = (int) (x1 + closeness * distX); int posY = (int) (y1 + closeness * distY); int xDisplacement = 0; int yDisplacement = 0; xDisplacement = (int) (rc.getLabelOffset() * (distX / totalLength)); yDisplacement = (int) (rc.getLabelOffset() * (-distY / totalLength)); AffineTransform old = g.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(posX + xDisplacement, posY + yDisplacement); double parallelOffset = 0.0d; Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize(); xform.translate(-d.width / 2.0d, -(d.height / 2.0d - parallelOffset)); g.setTransform(xform); g.setColor(Colors.WHITE); g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); g.setTransform(old); }
Example 5
Source File: TreeModelNodeLabelRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** * Labels the specified vertex with the specified label. Uses the font specified by this * instance's <code>VertexFontFunction</code>. (If the font is unspecified, the existing font * for the graphics context is used.) If vertex label centering is active, the label is centered * on the position of the vertex; otherwise the label is offset slightly. */ @Override public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) { Graph<V, E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v)) == false) { return; } Point2D pt = layout.transform(v); pt = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, pt); float x = (float) pt.getX(); float y = (float) pt.getY(); Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); GraphicsDecorator g = rc.getGraphicsContext(); Dimension d = component.getPreferredSize(); AffineTransform xform = AffineTransform.getTranslateInstance(x, y); Shape shape = rc.getVertexShapeTransformer().transform(v); shape = xform.createTransformedShape(shape); if (rc.getGraphicsContext() instanceof TransformingGraphics) { BidirectionalTransformer transformer = ((TransformingGraphics) rc.getGraphicsContext()).getTransformer(); if (transformer instanceof ShapeTransformer) { ShapeTransformer shapeTransformer = (ShapeTransformer) transformer; shape = shapeTransformer.transform(shape); } } Rectangle2D bounds = shape.getBounds2D(); Point p = null; if (position == Position.AUTO) { Dimension vvd = rc.getScreenDevice().getSize(); if (vvd.width == 0 || vvd.height == 0) { vvd = rc.getScreenDevice().getPreferredSize(); } p = getAnchorPoint(bounds, d, positioner.getPosition(x, y, vvd)); } else { p = getAnchorPoint(bounds, d, position); } if (graphCreator.isLeaf((String) v) && !graphCreator.getModel().getRoot().isNumerical()) { // shift the label if there is a frequency bar p.setLocation(p.x, p.y + LEAF_LABEL_OFFSET_Y); } g.draw(component, rc.getRendererPane(), p.x, p.y, d.width, d.height, true); }