GlyphVector gv = font.createGlyphVector(frc, "Cat"); Rectangle2D box = gv.getVisualBounds(); int xOff = 25+(int)-box.getX(); int yOff = 80+(int)-box.getY(); Shape shape = gv.getOutline(xOff,yOff);
rectangle.getX(), rectangle.getY(), rectangle.getX() + rectangle.getWidth(), rectangle.getY())); rectangle.getX(), rectangle.getY() + rectangle.getHeight(), rectangle.getX() + rectangle.getWidth(), rectangle.getY() + rectangle.getHeight())); rectangle.getX(), rectangle.getY(), rectangle.getX(), rectangle.getY() + rectangle.getHeight())); rectangle.getX() + rectangle.getWidth(), rectangle.getY(), rectangle.getX() + rectangle.getWidth(), rectangle.getY() + rectangle.getHeight()));
float x = (float)bounds.getX(); float y = (float)bounds.getY(); float w = (float)bounds.getWidth(); float x = (float)bounds.getX(); float y = (float)bounds.getY(); float w = (float)bounds.getWidth(); float x = (float)bounds.getX(); float y = (float)bounds.getY(); float w = (float)bounds.getWidth(); float x = (float)bounds.getX(); float y = (float)bounds.getY(); float w = (float)bounds.getWidth();
public static Point2D getMin(RectangularShape r) { return new Point2D.Double(r.getX(), r.getY()); } }
/** * Defines the new range of values covered by the rectangle according to * the <var>y</var> axis. The values covered along the <var>x</var> axis * will not be changed. The values must be expressed in logical coordinates * * @see #getMinY * @see #getMaxY * @see #getCenterY */ public final void setY(final double min, final double max) { setFrame(logicalShape.getX(), Math.min(min, max), logicalShape.getWidth(), Math.abs(max - min)); }
/** * Method called automatically when the user presses a mouse button * anywhere within the component. The default implementation * checks if the button was pressed whilst the mouse cursor was * within the rectangle. If so, this object will track the mouse drags * to move or resize the rectangle. */ public void mousePressed(final MouseEvent e) { if (!e.isConsumed() && (e.getModifiers() & MouseEvent.BUTTON1_MASK)!= 0) { if (adjustingSides != 0 || moveable) { tmp.x = e.getX(); tmp.y = e.getY(); try { if (drawnShape.contains(transform.inverseTransform(tmp, tmp))) { mouseDX = tmp.x - drawnShape.getX(); mouseDY = tmp.y - drawnShape.getY(); isDragging = true; e.consume(); } } catch (NoninvertibleTransformException exception) { // Pas besoin de grer cette exception. // L'ignorer est correct. } } } }
public static void transformRectCoords(java.awt.geom.RectangularShape rect, java.awt.geom.AffineTransform xform, float[] rv) { double[] coords = {rect.getX(), rect.getY()}; double[] size = {rect.getWidth(), rect.getHeight()}; xform.transform(coords, 0, coords, 0, 1); xform.deltaTransform(size, 0, size, 0, 1); rv[0] = (float)coords[0]; rv[1] = (float)coords[1]; rv[2] = (float)size[0]; rv[3] = (float)size[1]; } /* public static java.awt.geom.Rectangle2D.Float transformRectCoords(java.awt.geom.RectangularShape rect, java.awt.geom.AffineTransform xform)
/** * Resizes a rectangle. This works for real rectangles and produces funny results for RoundRects etc .. * * @param rectangularShape * the rectangle * @param width * the new width of the rectangle * @param height * the new height of the rectangle. * @return the resized rectangle. */ public static Shape resizeRect( final RectangularShape rectangularShape, final double width, final double height ) { final RectangularShape retval = (RectangularShape) rectangularShape.clone(); retval.setFrame( retval.getX(), retval.getY(), width, height ); return retval; }
/** * Moves this rectangle by a given x- and y-offset * @param r the rectangle to move * @param dx the x-offset * @param dy the y-offset */ public static void translate(RectangularShape r, double dx, double dy) { r.setFrame(r.getX() + dx, r.getY() + dy, r.getWidth(), r.getHeight()); }
private void drawBorder(Graphics2D g, RectangularShape shape, int width, int height) { Paint p = getBorderPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.setStroke(new BasicStroke(getBorderWidth())); // shrink the border by 1 px if(shape instanceof Rectangle2D) { g.draw(new Rectangle2D.Double(shape.getX(), shape.getY(), shape.getWidth()-1, shape.getHeight()-1)); } else if(shape instanceof RoundRectangle2D) { g.draw(new RoundRectangle2D.Double(shape.getX(), shape.getY(), shape.getWidth()-1, shape.getHeight()-1, ((RoundRectangle2D)shape).getArcWidth(), ((RoundRectangle2D)shape).getArcHeight())); } else { g.draw(shape); } }
this.ymax = ymax; setFrame(logicalShape.getX(), logicalShape.getY(), logicalShape.getWidth(), logicalShape.getHeight());
generatorContext.domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_RECT_TAG); svgRect.setAttributeNS(null, SVG_X_ATTRIBUTE, doubleString(rect.getX())); svgRect.setAttributeNS(null, SVG_Y_ATTRIBUTE, doubleString(rect.getY())); svgRect.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, Line2D line = new Line2D.Double(rect.getX(), rect.getY(), rect.getX(), rect.getY() + rect.getHeight()); return svgLine.toSVG(line); Line2D line = new Line2D.Double(rect.getX(), rect.getY(), rect.getX() + rect.getWidth(), rect.getY()); return svgLine.toSVG(line);
generatorContext.domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_RECT_TAG); svgRect.setAttributeNS(null, SVG_X_ATTRIBUTE, doubleString(rect.getX())); svgRect.setAttributeNS(null, SVG_Y_ATTRIBUTE, doubleString(rect.getY())); svgRect.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, Line2D line = new Line2D.Double(rect.getX(), rect.getY(), rect.getX(), rect.getY() + rect.getHeight()); return svgLine.toSVG(line); Line2D line = new Line2D.Double(rect.getX(), rect.getY(), rect.getX() + rect.getWidth(), rect.getY()); return svgLine.toSVG(line);
x = r.getX(); y = r.getY(); w = r.getWidth();
@Override public SVGRectangle doBackward(RectangularShape r) { checkArgument(r instanceof RoundRectangle2D || r instanceof Rectangle2D, "Invalid shape: "+r); if (r instanceof RoundRectangle2D) { RoundRectangle2D rr = (RoundRectangle2D) r; return new SVGRectangle(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(), rr.getArcWidth(), rr.getArcHeight()); } else if (r instanceof Rectangle2D) { return new SVGRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } else { throw new IllegalStateException(); } }
/** * Translates a se. Special care is taken to preserve the shape's original class, if the shape is a rectangle or a * line. * * @param s * the shape * @param x * the x coordinate where the shape is translated to * @param y * the y coordinate where the shape is translated to * @return the translated shape */ public static Shape translateShape( final Shape s, final double x, final double y ) { if ( s instanceof RectangularShape ) { final RectangularShape rect = (RectangularShape) s; final RectangularShape retval = (RectangularShape) rect.clone(); retval.setFrame( retval.getX() + x, retval.getY() + y, retval.getWidth(), retval.getHeight() ); return retval; } if ( s instanceof Line2D ) { final Line2D line = (Line2D) s; final Line2D retval = (Line2D) line.clone(); retval.setLine( retval.getX1() + x, retval.getY1() + y, retval.getX2() + x, retval.getY2() + y ); return retval; } final AffineTransform af = AffineTransform.getTranslateInstance( x, y ); return af.createTransformedShape( s ); }
/** * Calculates the BoundsOffsets used for setBounds() method * * Implemented because the canvas has no layout manager * */ public void updateBounds() { int newHeight = noteText.getPreferredSize().height; if (noteText.getHeight() < newHeight && newHeight >= noteText.getMinimumSize().height) { noteText.setSize(noteText.getWidth(), newHeight); } int rectWidth = noteText.getWidth() + GUIConstants.RESERVED_BORDER; int rectHeight = noteText.getHeight() + GUIConstants.RESERVED_BORDER; noteRect.setFrame(GUIConstants.RESERVED_BORDER / 2, GUIConstants.RESERVED_BORDER / 2, rectWidth, rectHeight); setSize(rectWidth + GUIConstants.ANNOTATION_SIZE_OFFSET, rectHeight + GUIConstants.ANNOTATION_SIZE_OFFSET); noteText.setLocation((int) noteRect.getX() + (rectWidth - noteText.getWidth()) / 2, (int) noteRect.getY() + (rectHeight - noteText.getHeight()) / 2); bounds.setBounds(model.getX() - 20, model.getY() - 20, rectWidth + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20, rectHeight + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20); setBounds(bounds); }