/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and shape. * * @return Returns true, if the polygon is inside of the image bounds. */ private boolean writePolyAttributes(IXMLElement elem, SVGFigure f, Shape shape) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } StringBuilder buf = new StringBuilder(); float[] coords = new float[6]; GeneralPath path = new GeneralPath(); for (PathIterator i = shape.getPathIterator(t, 1.5f); ! i.isDone(); i.next()) { switch (i.currentSegment(coords)) { case PathIterator.SEG_MOVETO : if (buf.length() != 0) { throw new IllegalArgumentException("Illegal shape "+shape); } if (buf.length() != 0) { buf.append(','); } buf.append((int) coords[0]); buf.append(','); buf.append((int) coords[1]); path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO : if (buf.length() != 0) { buf.append(','); } buf.append((int) coords[0]); buf.append(','); buf.append((int) coords[1]); path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_CLOSE : path.closePath(); break; default : throw new InternalError("Illegal segment type "+i.currentSegment(coords)); } } elem.setAttribute("shape", "poly"); elem.setAttribute("coords", buf.toString()); writeHrefAttribute(elem, f); return path.intersects(new Rectangle2D.Float(bounds.x, bounds.y, bounds.width, bounds.height)); }
public void setAdvance(float adv) { advance = adv; advp = new GeneralPath(); advp.moveTo(-2, -2); advp.lineTo(2, 2); advp.moveTo(-2, 2); advp.lineTo(2, -2); advp.moveTo(adv - 2, -2); advp.lineTo(adv, 0); advp.lineTo(adv + 2, -2); advp.moveTo(adv, 0); advp.lineTo(adv, -8); }
void drawCrosses() { GeneralPath path = new GeneralPath(); float arm = 5; for (int h = 0; h < linesV; h++) { for (int v = 0; v < linesH; v++) { float x = (float) (xstart + h * tileWidth); float y = (float) (ystart + v * tileHeight); path.moveTo(x - arm, y); path.lineTo(x + arm, y); path.moveTo(x, y - arm); path.lineTo(x, y + arm); } } showGrid(path); }
void drawLines() { GeneralPath path = new GeneralPath(); int width = imp.getWidth(); int height = imp.getHeight(); for (int i = 0; i < linesV; i++) { float xoff = (float) (xstart + i * tileWidth); path.moveTo(xoff, 0f); path.lineTo(xoff, height); } for (int i = 0; i < linesH; i++) { float yoff = (float) (ystart + i * tileHeight); path.moveTo(0f, yoff); path.lineTo(width, yoff); } showGrid(path); }
public Shape getShape() { GeneralPath gp = new GeneralPath(); gp.moveTo((float) d.getPosition().getX(), (float) d.getPosition().getY()); for (Node n : Arrays.asList(dt, tv, v)) { gp.lineTo((float) n.getPosition().getX(), (float) n.getPosition().getY()); } gp.closePath(); return gp; }
public GlyphPoint(float x, float y, boolean curvectrl) { this.x = x; this.y = y; this.curvecontrol = curvectrl; gp = new GeneralPath(); if (curvectrl) { gp.moveTo(x - 4, y - 4); gp.lineTo(x + 4, y + 4); gp.moveTo(x - 4, y + 4); gp.lineTo(x + 4, y - 4); } else { gp.moveTo(x - 4, y - 4); gp.lineTo(x - 4, y + 4); gp.lineTo(x + 4, y + 4); gp.lineTo(x + 4, y - 4); gp.closePath(); } }
void drawPoints() { int one = 1; int two = 2; GeneralPath path = new GeneralPath(); for (int h = 0; h < linesV; h++) { for (int v = 0; v < linesH; v++) { float x = (float) (xstart + h * tileWidth); float y = (float) (ystart + v * tileHeight); path.moveTo(x - two, y - one); path.lineTo(x - two, y + one); path.moveTo(x + two, y - one); path.lineTo(x + two, y + one); path.moveTo(x - one, y - two); path.lineTo(x + one, y - two); path.moveTo(x - one, y + two); path.lineTo(x + one, y + two); } } showGrid(path); }
void draw(Graphics2D g) { // toX/toY is tip of arrow and fx/fy is a point on the line - // fx/fy is used to determine direction & angle AffineTransform at = AffineTransform.getTranslateInstance(toX, toY); int b = 9; double theta = Math.toRadians(20); // The idea of using a GeneralPath is so we can // create the (three lines that make up the) arrow // (only) one time and then use AffineTransform to // place it anywhere we want. GeneralPath path = new GeneralPath(); // distance between line and the arrow mark <** not ** // Start a new line segment from the position of (0,0). path.moveTo(0, 0); // Create one of the two arrow head lines. int x = (int) (-b * Math.cos(theta)); int y = (int) (b * Math.sin(theta)); path.lineTo(x, y); // distance between line and the arrow mark <** not ** // Make the other arrow head line. int x2 = (int) (-b * Math.cos(-theta)); int y2 = (int) (b * Math.sin(-theta)); // path.moveTo(0,0); path.lineTo(x2, y2); path.closePath(); // theta is in radians double s, t; s = toY - fy; // calculate slopes. t = toX - fx; if (t != 0) { s = s / t; theta = Math.atan(s); if (t < 0) theta += Math.PI; } else if (s < 0) theta = -(Math.PI / 2); else theta = Math.PI / 2; at.rotate(theta); // at.rotate(theta,toX,toY); Shape shape = at.createTransformedShape(path); if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK); else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN); else g.setColor(ORANGE_RED); g.fill(shape); g.draw(shape); }
/** * method to draw the tail of the balloon * * @param ellipseHeight the height of the ellipse * @param fillColor the color to bill the balloon with * @param outlineColor the color to outline the balloon with * @param g2 the 2d graphics context */ protected void drawTail(int ellipseHeight, Color fillColor, Color outlineColor, Graphics2D g2) { Point tailEnd = getTailEnd(); Point upperLeft = getUpperLeft(); int margin = getMargin(); int halfWidth = getWidth() / 2; int topY = upperLeft.y + ellipseHeight; int startX = upperLeft.x + halfWidth - margin; int endX = upperLeft.x + halfWidth + margin; GeneralPath triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); triangle.moveTo(startX, topY); triangle.lineTo(endX, topY); triangle.lineTo(tailEnd.x, tailEnd.y); triangle.lineTo(startX, topY); g2.setColor(fillColor); g2.fill(triangle); g2.setColor(outlineColor); g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, startX, topY)); g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, endX, topY)); }
/** Paints the <tt>visualEdge</tt>. No arrowhead is drawn. */ public void paint(VisualGraphComponent component, Graphics2D g2d) { VisualEdge vEdge = (VisualEdge) component; Rectangle fromvertexBounds; Rectangle tovertexBounds; GeneralPath drawPath; VisualVertex visualVertexA = vEdge.getVisualVertexA(); VisualVertex visualVertexB = vEdge.getVisualVertexB(); GraphLayoutManager layoutmanager = vEdge.getVisualGraph().getGraphLayoutManager(); drawPath = vEdge.getGeneralPath(); // If there is no layoutmanager or there is one but the layout has not // been initialised, by default, let us route edges as straight lines. if (layoutmanager == null || (layoutmanager != null && !layoutmanager.isInitialized())) { fromvertexBounds = visualVertexA.getBounds(); tovertexBounds = visualVertexB.getBounds(); // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous // path will be redrawn as well. drawPath.reset(); // Start the line from the center of the vEdgertex drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY()); drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY()); } else { // Let the layout manager determine how the edge will be routed. layoutmanager.routeEdge(g2d, vEdge); } // Draw the line g2d.setColor(vEdge.getOutlinecolor()); g2d.draw(drawPath); // Draw the edge label this.paintText(vEdge, g2d); }
public Shape createStrokedShape(Shape shape) { GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; float moveX = 0, moveY = 0; float lastX = 0, lastY = 0; float thisX = 0, thisY = 0; int type = 0; boolean first = false; float next = 0; int phase = 0; float factor = 1; while (!it.isDone()) { type = it.currentSegment(points); switch (type) { case PathIterator.SEG_MOVETO: moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); first = true; next = wavelength / 2; break; case PathIterator.SEG_CLOSE: points[0] = moveX; points[1] = moveY; // Fall into.... case PathIterator.SEG_LINETO: thisX = points[0]; thisY = points[1]; float dx = thisX - lastX; float dy = thisY - lastY; float distance = (float) Math.sqrt(dx * dx + dy * dy); if (distance >= next) { float r = 1.0f / distance; float angle = (float) Math.atan2(dy, dx); while (distance >= next) { float x = lastX + next * dx * r; float y = lastY + next * dy * r; float tx = amplitude * dy * r; float ty = amplitude * dx * r; if ((phase & 1) == 0) result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r); else result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r); next += wavelength; phase++; } } next -= distance; first = false; lastX = thisX; lastY = thisY; if (type == PathIterator.SEG_CLOSE) result.closePath(); break; } it.next(); } // return stroke.createStrokedShape( result ); return result; }
public void moveTo(float x, float y) { gp.moveTo(x, y); this.x = x; this.y = y; points.add(new GlyphPoint(x, y, false)); }
public Shape getShape() { int R = Integer.parseInt(hexcolor.substring(0, 2), 16); int G = Integer.parseInt(hexcolor.substring(2, 4), 16); int B = Integer.parseInt(hexcolor.substring(4, 6), 16); color = new Color(R, G, B); Shape geom; if (shape.equals("circle")) { geom = new Ellipse2D.Float(-0.05f * size, -0.05f * size, 1.1f * size, 1.1f * size); center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("square")) { geom = new Rectangle2D.Float(0, 0, size, size); center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("roundsquare")) { geom = new RoundRectangle2D.Float(0, 0, size, size, size / 2, size / 2); center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("triangle")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); float height = (float) (Math.sqrt(3) * size / 2); path.moveTo(size / 2, size - height); path.lineTo(size, size); path.lineTo(0, size); path.closePath(); geom = path; center = new Point2D.Float(size / 2, size - height / 2); } else if (shape.equals("star")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); path.moveTo(size / 2, 0); path.lineTo(7 * size / 10, 3 * size / 10); path.lineTo(size, size / 2); path.lineTo(7 * size / 10, 7 * size / 10); path.lineTo(size / 2, size); path.lineTo(3 * size / 10, 7 * size / 10); path.lineTo(0, size / 2); path.lineTo(3 * size / 10, 3 * size / 10); path.closePath(); AffineTransform trans = AffineTransform.getRotateInstance(Math.PI / 4, size / 2, size / 2); Shape shape = trans.createTransformedShape(path); Area area = new Area(path); area.add(new Area(shape)); trans = AffineTransform.getScaleInstance(1.2, 1.2); shape = trans.createTransformedShape(area); trans = AffineTransform.getTranslateInstance(-0.1 * size, -0.1 * size); shape = trans.createTransformedShape(shape); geom = shape; center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("octagon")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); path.moveTo(size / 4, 0); path.lineTo(3 * size / 4, 0); path.lineTo(size, size / 4); path.lineTo(size, 3 * size / 4); path.lineTo(3 * size / 4, size); path.lineTo(size / 4, size); path.lineTo(0, 3 * size / 4); path.lineTo(0, size / 4); path.closePath(); geom = path; path.closePath(); geom = path; center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("ellipse")) { geom = new Ellipse2D.Float(0, 0, 3 * size / 4, size); center = new Point2D.Float(3 * size / 8, size / 2); } else if (shape.equals("cross")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); path.moveTo(size / 4, 0); path.lineTo(3 * size / 4, 0); path.lineTo(3 * size / 4, size / 4); path.lineTo(size, size / 4); path.lineTo(size, 3 * size / 4); path.lineTo(3 * size / 4, 3 * size / 4); path.lineTo(3 * size / 4, size); path.lineTo(size / 4, size); path.lineTo(size / 4, 3 * size / 4); path.lineTo(0, 3 * size / 4); path.lineTo(0, size / 4); path.lineTo(size / 4, size / 4); path.closePath(); geom = path; center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("pentagon")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); path.moveTo(size / 2, size); float x, y, a; for (int i = 1; i < 5; i++) { a = (float) ((2 * Math.PI / 5) * i); x = (float) (size / 2 + size / 2 * Math.sin(a)); y = (float) (size / 2 + size / 2 * Math.cos(a)); path.lineTo(x, y); } path.closePath(); AffineTransform trans = AffineTransform.getScaleInstance(1.1, 1.1); Shape shape = trans.createTransformedShape(path); trans = AffineTransform.getTranslateInstance(-0.05 * size, -0.05 * size); shape = trans.createTransformedShape(shape); geom = shape; center = new Point2D.Float(size / 2, size / 2); } else if (shape.equals("hexagon")) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2); path.moveTo(size / 2, size); float x, y, a; for (int i = 1; i < 6; i++) { a = (float) ((2 * Math.PI / 6) * i); x = (float) (size / 2 + size / 2 * Math.sin(a)); y = (float) (size / 2 + size / 2 * Math.cos(a)); path.lineTo(x, y); } path.closePath(); geom = path; center = new Point2D.Float(size / 2, size / 2); } else { geom = new Ellipse2D.Float(0, 0, size, size); center = new Point2D.Float(size / 2, size / 2); } return geom; }