Graphics2D g = ...; Point2D loc = ...; Font font = Font.getFont("Helvetica-bold-italic"); FontRenderContext frc = g.getFontRenderContext(); TextLayout layout = new TextLayout("This is a string", font, frc); layout.draw(g, (float)loc.getX(), (float)loc.getY()); Rectangle2D bounds = layout.getBounds(); bounds.setRect(bounds.getX()+loc.getX(), bounds.getY()+loc.getY(), bounds.getWidth(), bounds.getHeight()); g.draw(bounds);
public void drawU(UGraphic ug) { final int xWing = 8; final int yAperture = 8; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D middle = new Point2D.Double(0, 0); Point2D left = new Point2D.Double(0, -yAperture); Point2D base = new Point2D.Double(-xWing, 0); Point2D right = new Point2D.Double(0, yAperture); rotate.transform(left, left); rotate.transform(base, base); rotate.transform(right, right); if (side == Side.WEST || side == Side.EAST) { left.setLocation(middle.getX(), left.getY()); right.setLocation(middle.getX(), right.getY()); } if (side == Side.SOUTH || side == Side.NORTH) { left.setLocation(left.getX(), middle.getY()); right.setLocation(right.getX(), middle.getY()); } drawLine(ug, contact.getX(), contact.getY(), base, left); drawLine(ug, contact.getX(), contact.getY(), base, right); drawLine(ug, contact.getX(), contact.getY(), base, middle); }
private Point2D putOnCircle(Point2D p) { p = at.transform(p, null); final double coef = p.distance(new Point2D.Double()) / radius; p = new Point2D.Double(p.getX() / coef, p.getY() / coef); return at2.transform(p, null); }
private Circle(Point2D p1, Point2D p2, Point2D p3) { final double num1 = p3.getX() * p3.getX() * (p1.getY() - p2.getY()) + (p1.getX() * p1.getX() + (p1.getY() - p2.getY()) * (p1.getY() - p3.getY())) * (p2.getY() - p3.getY()) + p2.getX() * p2.getX() * (-p1.getY() + p3.getY()); final double den1 = 2 * (p3.getX() * (p1.getY() - p2.getY()) + p1.getX() * (p2.getY() - p3.getY()) + p2.getX() * (-p1.getY() + p3.getY())); final double x = num1 / den1; final double den2 = p3.getY() - p2.getY(); final double y = (p2.getY() + p3.getY()) / 2 - (p3.getX() - p2.getX()) / den2 * (x - (p2.getX() + p3.getX()) / 2); center = new Point2D.Double(x, y); radius = center.distance(p1); }
public void move(double deltax, double deltay) { position.setLocation(position.getX() + deltax, position.getY() + deltay); } }
at.translate(x, y); -(icon.getIconWidth() * icoStyle.getAnchorPointX()), (icon.getIconHeight() * (icoStyle.getAnchorPointY() - 1))); graphics.setTransform(at); new Rectangle2D.Double( x, y, icon.getIconWidth(), icon.getIconHeight())); labelCache.put(transformedShape.getBounds2D()); if (anchorPoint != null) { alignedRect = new Rectangle2D.Double( Math.round(anchorPoint.getX()), Math.round(anchorPoint.getY()), cornerRect.getWidth(), cornerRect.getHeight()); } else { alignedRect = new Rectangle2D.Double( 0.0, 0.0, cornerRect.getWidth(),
public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final UPolygon shape = (UPolygon) ushape; g2d.setStroke(new BasicStroke((float) param.getStroke().getThickness())); final GeneralPath path = new GeneralPath(); final double xp = pt.getX() + x; final double yp = pt.getY() + y; visible.ensureVisible(xp, yp); if (first) { path.moveTo((float) xp, (float) yp); } else { path.lineTo((float) xp, (float) yp); .getColor2())); g2d.setPaint(paint); g2d.fill(path); } else if (back!=null) { g2d.setColor(mapper.getMappedColor(back));
@Override public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) { currentPath.moveTo((float) p0.getX(), (float) p0.getY()); currentPath.lineTo((float) p1.getX(), (float) p1.getY()); currentPath.lineTo((float) p2.getX(), (float) p2.getY()); currentPath.lineTo((float) p3.getX(), (float) p3.getY()); currentPath.closePath(); }
g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); x1 = x0 - state.getMax(); Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if(r==null || !r.intersects(area)) { Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); if (plotState != null && plotState.getOwner() != null) { EntityCollection entities r = bounds.getBounds2D(); r.add(r.getMaxX() + r.getWidth()/2, r.getCenterY()); r.add(r.getMinX() - r.getWidth()/2, r.getCenterY()); r.add(r.getCenterX(), r.getMinY() - r.getHeight()/2);
private void drawTextWithWhiteBackGround(Graphics2D g2, String text, Point2D p) { TextLayout tl = new TextLayout(text, g2.getFont(), g2.getFontRenderContext()); g2.setColor(Color.WHITE); Rectangle2D textBounds = tl.getBounds(); g2.fill(new Rectangle2D.Double(textBounds.getX() + p.getX(), textBounds.getY() + p.getY(), textBounds.getWidth(), textBounds.getHeight())); g2.setColor(Color.BLACK); tl.draw(g2, (float) p.getX(), (float) p.getY()); }
public void paint(Graphics g) { g.setColor(Color.gray); Graphics2D g2d = (Graphics2D)g; Point2D center = radialLayout.getCenter(); Ellipse2D ellipse = new Ellipse2D.Double(); for(double d : depths) { ellipse.setFrameFromDiagonal(center.getX()-d, center.getY()-d, center.getX()+d, center.getY()+d); Shape shape = vv.getRenderContext().getMultiLayerTransformer().transform(ellipse); g2d.draw(shape); } }
GlyphVector glyphVector = font.createGlyphVector(frc, text); GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; float moveX = 0, moveY = 0; / (float) glyphVector.getLogicalBounds().getWidth() : 1.0f; float height = (float) glyphVector.getLogicalBounds().getHeight(); float nextAdvance = 0; moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f; next = nextAdvance; Shape glyph = glyphVector.getGlyphOutline(currentChar); Point2D p = glyphVector.getGlyphPosition(currentChar); float px = (float) p.getX(); float py = (float) p.getY(); float x = lastX + next * dx * r; float y = lastY + next * dy * r;
Color curColor = g2.getColor(); g2.setColor(paintColor); g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent)); g2.setColor(curColor); double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip); double layerHeight = nodeHeight * layerMultiplier; if (t.isLeaf()) { yieldOffsets[leafCtr++] = (float) (nodeTab + start.getX()); return nodeWidth; double childStartX = start.getX() + childTab; double childStartY = start.getY() + layerHeight; double lineStartX = start.getX() + nodeCenter; double lineStartY = start.getY() + nodeHeight * (1.0 + belowLineSkip); double lineEndY = lineStartY + nodeHeight * parentSkip; if(matchedParts != null && matchedParts.contains(child)) { Point2D.Double coord = new Point2D.Double(childStartX, childStartY); matchedPartCoordinates.add(coord); cWidth = paintTree(child, coord, g2, fM, matchedColor); if(((CoreLabel) child.label()).containsKey(CoreAnnotations.DoAnnotation.class)) col = (((CoreLabel) child.label()).get(CoreAnnotations.DoAnnotation.class)) ? tdiffColor : defaultColor; cWidth = paintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM, col);
private void drawHighlightedVertex(Graphics2D g, Coordinate pt, Color clr) { Rectangle2D rect = new Rectangle2D.Double(); Point2D p = viewport.toView(pt); rect.setFrame( p.getX() - VERTEX_SIZE_OVER_2, p.getY() - VERTEX_SIZE_OVER_2, VERTEX_SIZE, VERTEX_SIZE); g.setColor(clr); g.fill(rect); Rectangle2D rectInner = new Rectangle2D.Double( p.getX() - INNER_SIZE_OVER_2, p.getY() - INNER_SIZE_OVER_2, INNER_SIZE, INNER_SIZE); g.setColor(AppConstants.VERTEX_HIGHLIGHT_CLR); g.fill(rectInner); }
Point2D inter = null; if (in.getX() > rect.getMinX() && in.getX() < rect.getMaxX()) { if (in.getY() < rect.getMinY()) { inter = new Point2D.Double(in.getX(), rect.getMinY()); } else if (in.getY() > rect.getMaxY()) { inter = new Point2D.Double(in.getX(), rect.getMaxY()); } else { throw new IllegalArgumentException(); } else if (in.getY() > rect.getMinY() && in.getY() < rect.getMaxY()) { if (in.getX() < rect.getMinX()) { inter = new Point2D.Double(rect.getMinX(), in.getY()); } else if (in.getX() > rect.getMaxX()) { inter = new Point2D.Double(rect.getMaxX(), in.getY()); } else { throw new IllegalArgumentException(); tangeante.getX1(), tangeante.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv);
Rectangle2D rect = new Rectangle2D.Double(x, y, width, height); Graphics2D g2d = (Graphics2D) g.create(); g2d.draw(rect); g2d.draw(line); g2d.setColor(Color.RED); Point2D[] ps = getIntersectionPoint(line, rect); for (Point2D p : ps) { if (p != null) { g2d.fill(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8)); g2d.dispose(); double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; p = new Point2D.Double(xi, yi);
public static Shape getDonutSliceShape( Rectangle2D pieBounds, double thickness, double start, double extent) { thickness = thickness / 2; GeneralPath generalPath = new GeneralPath(); GeneralPath dummy = new GeneralPath(); // used to find arc endpoints double x = pieBounds.getX(); double y = pieBounds.getY(); double width = pieBounds.getWidth(); double height = pieBounds.getHeight(); Shape outer = new Arc2D.Double(x, y, width, height, start, extent, Arc2D.OPEN); double wt = width * thickness; double ht = height * thickness; Shape inner = new Arc2D.Double( x + wt, y + ht, width - 2 * wt, height - 2 * ht, start + extent, -extent, Arc2D.OPEN); generalPath.append(outer, false); dummy.append( new Arc2D.Double( x + wt, y + ht, width - 2 * wt, height - 2 * ht, start, extent, Arc2D.OPEN), false); Point2D point = dummy.getCurrentPoint(); if (point != null) { generalPath.lineTo(point.getX(), point.getY()); } generalPath.append(inner, false); dummy.append(new Arc2D.Double(x, y, width, height, start + extent, -extent, Arc2D.OPEN), false); point = dummy.getCurrentPoint(); generalPath.lineTo(point.getX(), point.getY()); return generalPath; }
public void paintTool(Graphics g) { if (startOfLine != null && endOfLine != null) { Graphics2D gg = (Graphics2D) g; Color oldColor = gg.getColor(); Stroke oldStroke = gg.getStroke(); g.setColor(lineColor); gg.setStroke(stroke); g.drawLine((int) startOfLine.getX(), (int) startOfLine.getY(), (int) endOfLine.getX(), (int) endOfLine.getY()); g.setColor(oldColor); gg.setStroke(oldStroke); } }