Example usage for java.awt.geom Rectangle2D getHeight

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

Introduction

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

Prototype

public abstract double getHeight();

Source Link

Document

Returns the height of the framing rectangle in double precision.

Usage

From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java

/**
 * Draws the visual representation of a single wind arrow.
 *//*  w w  w .  ja  v  a2 s .  c o  m*/
@Override
public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    resizeArrowByPlotHeight((int) plotArea.getHeight());
    // Needs a new graphics object to use translate() and rotate()
    Graphics2D g2 = (Graphics2D) g2d.create();
    g2.setRenderingHints(renderHints);
    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    double middleY = plotArea.getCenterY();

    WindDataset windData = (WindDataset) dataset;

    Number x = windData.getX(series, item);
    Number windDir = windData.getWindDirection(series, item);
    Number wforce = windData.getWindForce(series, item);

    double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation);

    g2.translate((int) middleX, (int) middleY);
    g2.setColor(Color.BLACK);

    if (wforce.doubleValue() <= zeroWindLimit) {
        drawCircle(g2);
    } else {
        g2.rotate(Math.toRadians(windDir.doubleValue() - 180));
        drawArrow(g2, wforce.doubleValue());

        if (useArrowHead) {
            g2.fill(getPolygonHead(arrowHeadSize, arrowHeight));
        } else {
            g2.draw(getCircleHead(arrowHeadSize, arrowHeight));
        }
    }
}

From source file:Bouncer.java

protected void setClip(Graphics2D g2) {
    if (mClip == false)
        return;// w  w w  . j  av a 2s  . com
    if (mClipShape == null) {
        Dimension d = getSize();
        FontRenderContext frc = g2.getFontRenderContext();
        Font font = new Font("Serif", Font.PLAIN, 144);
        String s = "Java Source and Support!";
        GlyphVector gv = font.createGlyphVector(frc, s);
        Rectangle2D bounds = font.getStringBounds(s, frc);
        mClipShape = gv.getOutline((d.width - (float) bounds.getWidth()) / 2,
                (d.height + (float) bounds.getHeight()) / 2);
    }
    g2.clip(mClipShape);
}

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:WeatherWizard.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();/*w w  w.  j  a v a  2 s  .  com*/
    Composite origComposite;

    setupWeatherReport();

    origComposite = g2.getComposite();
    if (alpha0 != null)
        g2.setComposite(alpha0);
    g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null);
    if (img1 != null) {
        if (alpha1 != null)
            g2.setComposite(alpha1);
        g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null),
                null);
    }
    g2.setComposite(origComposite);

    // Freezing, Cold, Cool, Warm, Hot,
    // Blue, Green, Yellow, Orange, Red
    Font font = new Font("Serif", Font.PLAIN, 36);
    g.setFont(font);

    String tempString = feels + " " + temperature + "F";
    FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
    Rectangle2D boundsTemp = font.getStringBounds(tempString, frc);
    Rectangle2D boundsCond = font.getStringBounds(condStr, frc);
    int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth());
    int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight();
    int rX = (size.width - wText) / 2;
    int rY = (size.height - hText) / 2;

    g.setColor(Color.LIGHT_GRAY);
    g2.fillRect(rX, rY, wText, hText);

    g.setColor(textColor);
    int xTextTemp = rX - (int) boundsTemp.getX();
    int yTextTemp = rY - (int) boundsTemp.getY();
    g.drawString(tempString, xTextTemp, yTextTemp);

    int xTextCond = rX - (int) boundsCond.getX();
    int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight();
    g.drawString(condStr, xTextCond, yTextCond);

}

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

/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 *///from   w  w w  .  j ava 2 s.co  m
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    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 .ja v 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: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 w w  .j  a  va 2  s.  c om

    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.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:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java

public void draw(final Graphics2D g2, final Rectangle2D bounds) {
    final Graphics2D gr2 = (Graphics2D) g2.create();
    try {//from   ww w .  j  av a  2 s.co m
        gr2.clip(bounds);
        if (scale) {
            final Dimension size = barcode.getPreferredSize();
            final double horzScale = bounds.getWidth() / size.getWidth();
            final double vertScale = bounds.getHeight() / size.getHeight();
            if (keepAspectRatio) {
                final double scale = Math.min(horzScale, vertScale);
                gr2.scale(scale, scale);
            } else {
                gr2.scale(horzScale, vertScale);
            }
        }
        barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY());
    } catch (OutputException e) {
        logger.error("Unable to draw barcode element", e);
    } finally {
        gr2.dispose();
    }

}