List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath(Shape s)
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Draws the edge <code>e</code>, whose endpoints are at <code>(x1,y1)</code> * and <code>(x2,y2)</code>, on the graphics context <code>g</code>. * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> instance * is scaled in the x-direction so that its width is equal to the distance between * <code>(x1,y1)</code> and <code>(x2,y2)</code>. *///from www .j av a 2 s . c om protected void drawSimpleEdge(Graphics2D g, Edge e, int x1, int y1, int x2, int y2) { Pair endpoints = e.getEndpoints(); Vertex v1 = (Vertex) endpoints.getFirst(); Vertex v2 = (Vertex) endpoints.getSecond(); boolean isLoop = v1.equals(v2); Shape s2 = vertexShapeFunction.getShape(v2); Shape edgeShape = edgeShapeFunction.getShape(e); boolean edgeHit = true; boolean arrowHit = true; Rectangle deviceRectangle = null; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); if (isLoop) { // this is a self-loop. scale it is larger than the vertex // it decorates and translate it so that its nadir is // at the center of the vertex. Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); xform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { // this is a normal edge. Rotate it to the angle between // vertex endpoints, then scale it to the distance between // the vertices float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0); } edgeShape = xform.createTransformedShape(edgeShape); edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle); if (edgeHit == true) { Paint oldPaint = g.getPaint(); // get Paints for filling and drawing // (filling is done first so that drawing and label use same Paint) Paint fill_paint = edgePaintFunction.getFillPaint(e); if (fill_paint != null) { g.setPaint(fill_paint); g.fill(edgeShape); } Paint draw_paint = edgePaintFunction.getDrawPaint(e); if (draw_paint != null) { g.setPaint(draw_paint); g.draw(edgeShape); } float scalex = (float) g.getTransform().getScaleX(); float scaley = (float) g.getTransform().getScaleY(); // see if arrows are too small to bother drawing if (scalex < .3 || scaley < .3) return; if (edgeArrowPredicate.evaluate(e)) { Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond()); AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2); destVertexShape = xf.createTransformedShape(destVertexShape); arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getArrowTransform((GeneralPath) edgeShape, destVertexShape); else at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); // note that arrows implicitly use the edge's draw paint g.fill(arrow); } if (e instanceof UndirectedEdge) { Shape vertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getFirst()); xf = AffineTransform.getTranslateInstance(x1, y1); vertexShape = xf.createTransformedShape(vertexShape); arrowHit = viewTransformer.transform(vertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getReverseArrowTransform((GeneralPath) edgeShape, vertexShape, !isLoop); else at = getReverseArrowTransform(new GeneralPath(edgeShape), vertexShape, !isLoop); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); g.fill(arrow); } } } // use existing paint for text if no draw paint specified if (draw_paint == null) g.setPaint(oldPaint); String label = edgeStringer.getLabel(e); if (label != null) { labelEdge(g, e, label, x1, x2, y1, y2); } // restore old paint g.setPaint(oldPaint); } }
From source file:DefaultGraphics2D.java
/** * @return a deep copy of this context//from w w w. j av a 2 s .c om */ public Object clone() { GraphicContext copyGc = new GraphicContext(defaultTransform); // // Now, copy each GC element in turn // // Default transform /* Set in constructor */ // Transform copyGc.transform = new AffineTransform(this.transform); // Transform stack copyGc.transformStack = new ArrayList(transformStack.size()); for (int i = 0; i < this.transformStack.size(); i++) { TransformStackElement stackElement = (TransformStackElement) this.transformStack.get(i); copyGc.transformStack.add(stackElement.clone()); } // Transform stack validity copyGc.transformStackValid = this.transformStackValid; // Paint (immutable by requirement) copyGc.paint = this.paint; // Stroke (immutable by requirement) copyGc.stroke = this.stroke; // Composite (immutable by requirement) copyGc.composite = this.composite; // Clip if (clip != null) copyGc.clip = new GeneralPath(clip); else copyGc.clip = null; // RenderingHints copyGc.hints = (RenderingHints) this.hints.clone(); // Font (immutable) copyGc.font = this.font; // Background, Foreground (immutable) copyGc.background = this.background; copyGc.foreground = this.foreground; return copyGc; }
From source file:DefaultGraphics2D.java
/** * Intersects the current <code>Clip</code> with the interior of the * specified <code>Shape</code> and sets the <code>Clip</code> to the * resulting intersection. The specified <code>Shape</code> is transformed * with the current <code>Graphics2D</code> * <code>Transform</code> before * being intersected with the current <code>Clip</code>. This method is * used to make the current <code>Clip</code> smaller. To make the * <code>Clip</code> larger, use <code>setClip</code>. The <i>user clip</i> * modified by this method is independent of the clipping associated with * device bounds and visibility. If no clip has previously been set, or if the * clip has been cleared using/* ww w. jav a 2 s .c om*/ * {@link java.awt.Graphics#setClip(Shape) setClip} with a <code>null</code> * argument, the specified <code>Shape</code> becomes the new user clip. * * @param s * the <code>Shape</code> to be intersected with the current * <code>Clip</code>. If <code>s</code> is <code>null</code>, * this method clears the current <code>Clip</code>. */ public void clip(Shape s) { if (s != null) s = transform.createTransformedShape(s); if (clip != null) { Area newClip = new Area(clip); newClip.intersect(new Area(s)); clip = new GeneralPath(newClip); } else { clip = s; } }
From source file:org.apache.pdfbox.pdfviewer.font.CFFGlyph2D.java
private GeneralPath transformGlyph(GeneralPath glyph) { // we have to invert all y-coordinates due to the moved 0,0-reference PathIterator iter = glyph.getPathIterator(null); float[] currentSegment = new float[6]; Path2D.Float path = new Path2D.Float(iter.getWindingRule()); boolean glyphTransformed = false; while (!iter.isDone()) { glyphTransformed = true;// ww w . ja va2s . c o m int type = iter.currentSegment(currentSegment); switch (type) { case PathIterator.SEG_MOVETO: path.moveTo(currentSegment[0], -currentSegment[1]); break; case PathIterator.SEG_LINETO: path.lineTo(currentSegment[0], -currentSegment[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3]); break; case PathIterator.SEG_CUBICTO: path.curveTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3], currentSegment[4], -currentSegment[5]); break; case PathIterator.SEG_CLOSE: path.closePath(); break; } iter.next(); } if (glyphTransformed) { return new GeneralPath(path); } else { return glyph; } }
From source file:org.apache.pdfbox.pdmodel.graphics.PDGraphicsState.java
/** * Constructor with a given pagesize to initialize the clipping path. * @param page the size of the page//from w ww . j av a2 s . c o m */ public PDGraphicsState(PDRectangle page) { currentClippingPath = new GeneralPath(new Rectangle(page.createDimension())); if (page.getLowerLeftX() != 0 || page.getLowerLeftY() != 0) { //Compensate for offset this.currentTransformationMatrix = this.currentTransformationMatrix .multiply(Matrix.getTranslatingInstance(-page.getLowerLeftX(), -page.getLowerLeftY())); } }
From source file:org.dwfa.ace.graph.AceGraphRenderer.java
/** * Draws the edge <code>e</code>, whose endpoints are at * <code>(x1,y1)</code> and <code>(x2,y2)</code>, on the graphics context * <code>g</code>.//from www . j a v a2 s .c om * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> * instance * is scaled in the x-direction so that its width is equal to the distance * between <code>(x1,y1)</code> and <code>(x2,y2)</code>. */ protected void drawSimpleEdge(Graphics2D g, Edge e, int x1, int y1, int x2, int y2) { Pair endpoints = e.getEndpoints(); Vertex v1 = (Vertex) endpoints.getFirst(); Vertex v2 = (Vertex) endpoints.getSecond(); boolean isLoop = v1.equals(v2); Shape s2 = vertexShapeFunction.getShape(v2); Shape edgeShape = edgeShapeFunction.getShape(e); boolean edgeHit = true; boolean arrowHit = true; Rectangle deviceRectangle = null; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); if (isLoop) { // this is a self-loop. scale it is larger than the vertex // it decorates and translate it so that its nadir is // at the center of the vertex. Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); xform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { // this is a normal edge. Rotate it to the angle between // vertex endpoints, then scale it to the distance between // the vertices float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0); } edgeShape = xform.createTransformedShape(edgeShape); if (deviceRectangle == null) { edgeHit = false; } else { edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle); } if (edgeHit == true) { Paint oldPaint = g.getPaint(); // get Paints for filling and drawing // (filling is done first so that drawing and label use same Paint) Paint fill_paint = edgePaintFunction.getFillPaint(e); if (fill_paint != null) { g.setPaint(fill_paint); g.fill(edgeShape); } Paint draw_paint = edgePaintFunction.getDrawPaint(e); if (draw_paint != null) { g.setPaint(draw_paint); g.draw(edgeShape); } float scalex = (float) g.getTransform().getScaleX(); float scaley = (float) g.getTransform().getScaleY(); // see if arrows are too small to bother drawing if (scalex < .3 || scaley < .3) return; if (edgeArrowPredicate.evaluate(e)) { Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond()); AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2); destVertexShape = xf.createTransformedShape(destVertexShape); arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getArrowTransform((GeneralPath) edgeShape, destVertexShape); else at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); // note that arrows implicitly use the edge's draw paint g.fill(arrow); } if (e instanceof UndirectedEdge) { Shape vertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getFirst()); xf = AffineTransform.getTranslateInstance(x1, y1); vertexShape = xf.createTransformedShape(vertexShape); arrowHit = viewTransformer.transform(vertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getReverseArrowTransform((GeneralPath) edgeShape, vertexShape, !isLoop); else at = getReverseArrowTransform(new GeneralPath(edgeShape), vertexShape, !isLoop); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); g.fill(arrow); } } } // use existing paint for text if no draw paint specified if (draw_paint == null) g.setPaint(oldPaint); String label = edgeStringer.getLabel(e); if (label != null) { labelEdge(g, e, label, x1, x2, y1, y2); } // restore old paint g.setPaint(oldPaint); } }
From source file:se.ngm.ditaaeps.EpsRenderer.java
public static void renderToEps(Diagram diagram, PrintWriter out, RenderingOptions options) { //RenderedImage renderedImage = image; EpsGraphics2D g2 = new EpsGraphics2D(out, new Rectangle2D.Double(0, -diagram.getHeight(), diagram.getWidth(), diagram.getHeight())); g2.scale(1, -1); // g2 origo is top-left, eps is bottom-left Object antialiasSetting = antialiasSetting = RenderingHints.VALUE_ANTIALIAS_OFF; if (options.performAntialias()) antialiasSetting = RenderingHints.VALUE_ANTIALIAS_ON; //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting); g2.setColor(Color.white);//from w ww . j a v a 2 s .c o m //TODO: find out why the next line does not work //g2.fillRect(0, 0, image.getWidth()+10, image.getHeight()+10); /*for(int y = 0; y < diagram.getHeight(); y ++) g2.drawLine(0, y, diagram.getWidth(), y);*/ g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND)); ArrayList shapes = diagram.getAllDiagramShapes(); if (DEBUG) System.out.println("Rendering " + shapes.size() + " shapes (groups flattened)"); Iterator shapesIt; if (options.dropShadows()) { //render shadows shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getPoints().isEmpty()) continue; //GeneralPath path = shape.makeIntoPath(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); float offset = diagram.getMinimumOfCellDimension() / 3.333f; if (path != null && shape.dropsShadow()) { GeneralPath shadow = new GeneralPath(path); AffineTransform translate = new AffineTransform(); translate.setToTranslation(offset, offset); shadow.transform(translate); g2.setColor(new Color(150, 150, 150)); g2.fill(shadow); } } //blur shadows // if(true) { // int blurRadius = 6; // int blurRadius2 = blurRadius * blurRadius; // float blurRadius2F = blurRadius2; // float weight = 1.0f / blurRadius2F; // float[] elements = new float[blurRadius2]; // for (int k = 0; k < blurRadius2; k++) // elements[k] = weight; // Kernel myKernel = new Kernel(blurRadius, blurRadius, elements); // // //if EDGE_NO_OP is not selected, EDGE_ZERO_FILL is the default which creates a black border // ConvolveOp simpleBlur = // new ConvolveOp(myKernel, ConvolveOp.EDGE_NO_OP, null); // //BufferedImage destination = new BufferedImage(image.getWidth()+blurRadius, image.getHeight()+blurRadius, image.getType()); // BufferedImage destination = // new BufferedImage( // image.getWidth(), // image.getHeight(), // image.getType()); // simpleBlur.filter(image, destination); // //destination = destination.getSubimage(blurRadius/2, blurRadius/2, image.getWidth(), image.getHeight()); // g2 = destination.createGraphics(); // g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting); // renderedImage = destination; // } } //fill and stroke float dashInterval = Math.min(diagram.getCellWidth(), diagram.getCellHeight()) / 2; //Stroke normalStroke = g2.getStroke(); float strokeWeight = diagram.getMinimumOfCellDimension() / 10; Stroke normalStroke = new BasicStroke(strokeWeight, //10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); Stroke dashStroke = new BasicStroke(strokeWeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { dashInterval }, 0); //find storage shapes ArrayList storageShapes = new ArrayList(); shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getType() == DiagramShape.TYPE_STORAGE) { storageShapes.add(shape); continue; } } //render storage shapes //special case since they are '3d' and should be //rendered bottom to top //TODO: known bug: if a storage object is within a bigger normal box, it will be overwritten in the main drawing loop //(BUT this is not possible since tags are applied to all shapes overlaping shapes) Collections.sort(storageShapes, new Shape3DOrderingComparator()); g2.setStroke(normalStroke); shapesIt = storageShapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); if (!shape.isStrokeDashed()) { if (shape.getFillColor() != null) g2.setColor(shape.getFillColor()); else g2.setColor(Color.white); g2.fill(path); } if (shape.isStrokeDashed()) g2.setStroke(dashStroke); else g2.setStroke(normalStroke); g2.setColor(shape.getStrokeColor()); g2.draw(path); } //render the rest of the shapes ArrayList pointMarkers = new ArrayList(); shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getType() == DiagramShape.TYPE_POINT_MARKER) { pointMarkers.add(shape); continue; } if (shape.getType() == DiagramShape.TYPE_STORAGE) { continue; } if (shape.getPoints().isEmpty()) continue; int size = shape.getPoints().size(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); if (path != null && shape.isClosed() && !shape.isStrokeDashed()) { if (shape.getFillColor() != null) g2.setColor(shape.getFillColor()); else g2.setColor(Color.white); g2.fill(path); } if (shape.getType() != DiagramShape.TYPE_ARROWHEAD) { g2.setColor(shape.getStrokeColor()); if (shape.isStrokeDashed()) g2.setStroke(dashStroke); else g2.setStroke(normalStroke); g2.draw(path); } } //render point markers g2.setStroke(normalStroke); shapesIt = pointMarkers.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); //if(shape.getType() != DiagramShape.TYPE_POINT_MARKER) continue; GeneralPath path; path = shape.makeIntoRenderPath(diagram); g2.setColor(Color.white); g2.fill(path); g2.setColor(shape.getStrokeColor()); g2.draw(path); } //handle text //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); Iterator textIt = diagram.getTextObjects().iterator(); while (textIt.hasNext()) { DiagramText text = (DiagramText) textIt.next(); g2.setColor(text.getColor()); g2.setFont(text.getFont()); g2.drawString(text.getText(), text.getXPos(), text.getYPos()); } if (options.renderDebugLines() || DEBUG) { Stroke debugStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); g2.setStroke(debugStroke); g2.setColor(new Color(170, 170, 170)); g2.setXORMode(Color.white); for (int x = 0; x < diagram.getWidth(); x += diagram.getCellWidth()) g2.drawLine(x, 0, x, diagram.getHeight()); for (int y = 0; y < diagram.getHeight(); y += diagram.getCellHeight()) g2.drawLine(0, y, diagram.getWidth(), y); } g2.dispose(); }
From source file:statechum.analysis.learning.Visualiser.java
protected static PluggableRenderer constructRenderer(Graph g, final LayoutOptions options) { final LayoutOptions graphLayoutOptions = options != null ? options : new LayoutOptions(); PluggableRenderer r = new PluggableRenderer() { /**//from ww w . j a va2 s . co m * Draws the edge <code>e</code>, whose endpoints are at <code>(x1,y1)</code> * and <code>(x2,y2)</code>, on the graphics context <code>g</code>. * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> instance * is scaled in the x-direction so that its width is equal to the distance between * <code>(x1,y1)</code> and <code>(x2,y2)</code>. */ @Override protected void drawSimpleEdge(Graphics2D g2d, Edge e, int x1, int y1, int x2, int y2) { final Vertex v1 = (Vertex) e.getEndpoints().getFirst(); final Vertex v2 = (Vertex) e.getEndpoints().getSecond(); boolean isLoop = v1.equals(v2); final Shape s2 = vertexShapeFunction.getShape(v2); Shape edgeShape = edgeShapeFunction.getShape(e); final double dx = x2 - x1; final double dy = y2 - y1; boolean edgeHit = true; boolean arrowHit = true; Rectangle deviceRectangle = null; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } String label = edgeStringer.getLabel(e); assert (label != null); Component labelComponent = prepareRenderer(graphLabelRenderer, label, isPicked(e), e); Dimension d = labelComponent.getPreferredSize(); Rectangle2D EdgeShapeBoundaries = edgeShape.getBounds2D(); AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); double yMin = 0, yMax = 0; double thetaRadians = 0; if (isLoop) { // this is a self-loop. scale it is larger than the vertex // it decorates and translate it so that its nadir is // at the center of the vertex. int edgeIndex = ParallelEdgeIndexSingleton.getInstance().getIndex(e); Rectangle2D s2Bounds = s2.getBounds2D(); double scaleBy = 1 + (graphLayoutOptions.scaleLines - 1) * 1. / 3.; double translation = s2Bounds.getHeight() * (1. / 4. + edgeIndex / 4.); xform.translate(0, -scaleBy * translation); xform.scale(scaleBy * s2Bounds.getWidth(), scaleBy * s2Bounds.getHeight()); yMin = scaleBy * (EdgeShapeBoundaries.getMinY() * s2Bounds.getHeight()) - translation; yMax = scaleBy * (EdgeShapeBoundaries.getMaxY() * s2Bounds.getHeight()) - translation; } else { // this is a normal edge. Rotate it to the angle between // vertex endpoints, then scale it to the distance between // the vertices thetaRadians = Math.atan2(dy, dx); double dist = Math.sqrt(dx * dx + dy * dy); xform.rotate(thetaRadians); xform.scale(dist, 1.0); yMin = EdgeShapeBoundaries.getMinY(); yMax = EdgeShapeBoundaries.getMaxY(); } edgeShape = xform.createTransformedShape(edgeShape); // Debug code /* if (!isLoop) { g2d.setPaint(new Color( 250, 250, 0)); AffineTransform rect = AffineTransform.getTranslateInstance(x1, y1+yMin); rect.rotate(thetaRadians); g2d.fill(rect.createTransformedShape( new Rectangle(0,0,(int)Math.sqrt(dx*dx + dy*dy),(int)(yMax-yMin)))); } else { g2d.setPaint(new Color( 100, 250, 0)); AffineTransform rect = AffineTransform.getTranslateInstance(x1-s2.getBounds2D().getWidth()/2, y1+yMin); rect.rotate(thetaRadians); g2d.fill(rect.createTransformedShape( new Rectangle(0,0,(int)s2.getBounds2D().getWidth(),(int)(yMax-yMin)))); }*/ edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle); if (edgeHit == true) { Paint oldPaint = g2d.getPaint(); // get Paints for filling and drawing // (filling is done first so that drawing and label use same Paint) Paint fill_paint = edgePaintFunction.getFillPaint(e); if (fill_paint != null) { g2d.setPaint(fill_paint); g2d.fill(edgeShape); } Paint draw_paint = edgePaintFunction.getDrawPaint(e); if (draw_paint != null) { g2d.setPaint(draw_paint); g2d.draw(edgeShape); } double scalex = g2d.getTransform().getScaleX(); double scaley = g2d.getTransform().getScaleY(); // see if arrows are too small to bother drawing if (scalex < .3 || scaley < .3) return; if (edgeArrowPredicate.evaluate(e)) { Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond()); AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2); destVertexShape = xf.createTransformedShape(destVertexShape); arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getArrowTransform((GeneralPath) edgeShape, destVertexShape); else at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); // note that arrows implicitly use the edge's draw paint g2d.fill(arrow); } assert !(e instanceof UndirectedEdge); } // For difference visualisation only boolean labelBelow = false; if (graphLayoutOptions.showDIFF && (draw_paint == null || draw_paint instanceof Color && ((Color) draw_paint).equals(Color.BLACK))) labelBelow = true; // Now draw the label. double xLabel = 0, yLabel = 0, xa = 0, ya = 0, rotation = thetaRadians; if (isLoop) { double displacementY = labelBelow ? -yMin + d.height : -yMin + d.height, displacementX = d.width / 2; xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians); ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians); xLabel = xa - displacementX * Math.cos(thetaRadians); yLabel = ya - displacementX * Math.sin(thetaRadians); } else if (dx < 0) { double displacementY = labelBelow ? yMax - d.height : (-yMax - d.height), displacementX = d.width / 2; xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians); ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians); xLabel = xa + displacementX * Math.cos(thetaRadians); yLabel = ya + displacementX * Math.sin(thetaRadians); rotation = thetaRadians + Math.PI; } else { double displacementY = labelBelow ? yMax : -yMax, displacementX = d.width / 2; xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians); ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians); xLabel = xa - displacementX * Math.cos(thetaRadians); yLabel = ya - displacementX * Math.sin(thetaRadians); } AffineTransform old = g2d.getTransform(); AffineTransform labelTransform = new AffineTransform(); // Debug code: //g2d.drawLine((int)(x1+dx/2), (int)(y1+dy/2), (int)(xa), (int)(ya));g2d.drawLine((int)(xa), (int)(ya), (int)(xLabel), (int)(yLabel)); labelTransform.translate(xLabel, yLabel); labelTransform.rotate(rotation); g2d.setTransform(labelTransform); rendererPane.paintComponent(g2d, labelComponent, screenDevice, 0, 0, d.width, d.height, true); g2d.setTransform(old); // restore old paint g2d.setPaint(oldPaint); } // if edgeHit == true } }; r = labelEdges(g, r, graphLayoutOptions); r = labelVertices(r, g, graphLayoutOptions); r.setVertexIncludePredicate(new Predicate() { @Override public boolean evaluate(Object object) { if (!graphLayoutOptions.showIgnored && graphLayoutOptions.ignoredStates != null && graphLayoutOptions.ignoredStates.contains(object.toString())) return false; if (graphLayoutOptions.showNegatives) return true; else return DeterministicDirectedSparseGraph.isAccept((Vertex) object); } }); return r; }