Example usage for java.awt.geom Rectangle2D getWidth

List of usage examples for java.awt.geom Rectangle2D getWidth

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getWidth.

Prototype

public abstract double getWidth();

Source Link

Document

Returns the width of the framing rectangle in double precision.

Usage

From source file:VASSAL.tools.image.svg.SVGRenderer.java

public BufferedImage render(double angle, double scale) {
    // The renderer needs the bounds unscaled---scaling comes from the
    // width and height hints.
    AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0);
    r.setTransform(px);/*from   w  ww  .ja va  2  s  . c o  m*/

    px = new AffineTransform(px);
    px.scale(scale, scale);

    final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH);
    final Rectangle2D b = px.createTransformedShape(rect).getBounds2D();

    r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) b.getWidth());
    r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) b.getHeight());

    try {
        r.transcode(new TranscoderInput(doc), null);
        return r.getBufferedImage();
    }
    // FIXME: review error message
    catch (BridgeException e) {
        logger.error("", e);
    } catch (TranscoderException e) {
        logger.error("", e);
    }

    return null;
}

From source file:net.sf.jasperreports.engine.JRImageRenderer.java

@Override
public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle)
        throws JRException {
    Image img = getImage(jasperReportsContext);

    grx.drawImage(img, (int) rectangle.getX(), (int) rectangle.getY(), (int) rectangle.getWidth(),
            (int) rectangle.getHeight(), null);
}

From source file:haven.Utils.java

static void aligntext(Graphics g, String text, Coord c, double ax, double ay) {
    java.awt.FontMetrics m = g.getFontMetrics();
    java.awt.geom.Rectangle2D ts = m.getStringBounds(text, g);
    g.drawString(text, (int) (c.x - ts.getWidth() * ax), (int) (c.y + m.getAscent() - ts.getHeight() * ay));
}

From source file:org.jfree.demo.TextBlockPanel.java

/**
 * Paints the panel./*from  w  w w  . jav a  2s . co  m*/
 *
 * @param g  the graphics device.
 */
public void paintComponent(final Graphics g) {

    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    final Dimension size = getSize();
    final Insets insets = getInsets();
    final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
            size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

    final double x = available.getX();
    final double y = available.getY();
    final float width = (float) available.getWidth();
    final TextBlock block = TextUtilities.createTextBlock(this.text, this.font, Color.black, width,
            new G2TextMeasurer(g2));
    g2.setPaint(Color.black);
    block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0);

}

From source file:net.sourceforge.processdash.ui.lib.chart.DiscPlot.java

private Rectangle2D getDataArea(Rectangle2D plotArea) {
    double hGap = plotArea.getWidth() * this.interiorGap;
    double vGap = plotArea.getHeight() * this.interiorGap;

    return new Rectangle2D.Double(plotArea.getX() + hGap, plotArea.getY() + vGap,
            plotArea.getWidth() - 2 * hGap, plotArea.getHeight() - 2 * vGap);
}

From source file:Clip.java

/**
 * Set the clip contents, and set the status to valid and in use.
 * @param r the clip contents to copy/*from w w w .jav  a 2s . c  o  m*/
 */
public void setClip(Rectangle2D r) {
    setClip(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}

From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java

/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 *//*from   www . j  av a 2  s .c  om*/
public Shape getWindow(Rectangle2D frame) {
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    return new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());
}

From source file:org.jfree.experimental.chart.plot.dial.DialCap.java

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 *///from  w  w w.j a  v  a 2s . c  om
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setPaint(this.fillPaint);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());
    g2.fill(e);
    g2.setPaint(this.outlinePaint);
    g2.setStroke(this.outlineStroke);
    g2.draw(e);

}

From source file:TextBouncer.java

public TextBouncer(String s, Font f) {
    previousTimes = new long[128];
    previousTimes[0] = System.currentTimeMillis();
    previousIndex = 1;//from   w w w  . jav a2 s  . c o m
    previousFilled = false;

    mString = s;
    setFont(f);
    Random random = new Random();
    mX = random.nextFloat() * 500;
    mY = random.nextFloat() * 500;
    mDeltaX = random.nextFloat() * 3;
    mDeltaY = random.nextFloat() * 3;
    mShearX = random.nextFloat() / 2;
    mShearY = random.nextFloat() / 2;
    mShearDeltaX = mShearDeltaY = .05f;
    FontRenderContext frc = new FontRenderContext(null, true, false);
    Rectangle2D bounds = getFont().getStringBounds(mString, frc);
    mWidth = (float) bounds.getWidth();
    mHeight = (float) bounds.getHeight();
    // Make sure points are within range.
    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent ce) {
            Dimension d = getSize();
            if (mX < 0)
                mX = 0;
            else if (mX + mWidth >= d.width)
                mX = d.width - mWidth - 1;
            if (mY < 0)
                mY = 0;
            else if (mY + mHeight >= d.height)
                mY = d.height - mHeight - 1;
        }
    });
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Transform a value in the units of the X axis of the chart into a mouse x value
 * Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one
 * @param xValue//w  ww  .j a v  a  2  s  .  c om
 * @return
 */
protected double transformXValueToMouse(double xValue) {
    Rectangle2D screenDataArea = _chartPanel.getScreenDataArea();

    double leftmostOnAxis = domainAxis.getLowerBound();
    double rightmostOnAxis = domainAxis.getUpperBound();
    double leftmostonscreen = screenDataArea.getX();
    double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth();
    double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen);
    double result = ((xValue - leftmostOnAxis) / slope) + leftmostonscreen;
    //System.err.println("***Transform: " + xValue + ", left=" + leftmostOnAxis + ", right=" + rightmostOnAxis +
    //              ", screenl=" + leftmostonscreen + ", screenr=" + rightmostonscreen + ", slope=" + slope + ", result=" + result);
    return result;
}