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:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java

public Point2D computeTranslationVector(double pageWidth, double watermarkWidth, double pageHeight,
        double watermarkHeight, WatermarkProperties properties) {
    double xTranslation;
    double yTranslation;
    double xRotationOffset = 0;
    double yRotationOffset = 0;

    if (properties.getTextRotation() != 0) {
        Rectangle2D rectangle2D = new Rectangle2D.Double(0, -watermarkHeight, watermarkWidth, watermarkHeight);
        AffineTransform at = AffineTransform.getRotateInstance(-Math.toRadians(properties.getTextRotation()), 0,
                0);/*ww  w . j  a  va2 s.c o  m*/
        Shape shape = at.createTransformedShape(rectangle2D);
        Rectangle2D rotated = shape.getBounds2D();

        watermarkWidth = rotated.getWidth();
        if (!properties.isInvertX() || properties.isRelativeCoordinates()) {
            xRotationOffset = -rotated.getX();
        } else {
            xRotationOffset = rotated.getX();
        }

        watermarkHeight = rotated.getHeight();
        if (!properties.isInvertY() || properties.isRelativeCoordinates()) {
            yRotationOffset = rotated.getY() + rotated.getHeight();
        } else {
            yRotationOffset = -(rotated.getY() + rotated.getHeight());
        }

    }

    if (properties.isRelativeCoordinates()) {
        xTranslation = (pageWidth - watermarkWidth) * properties.getxPosition() + xRotationOffset;
        yTranslation = (pageHeight - watermarkHeight) * properties.getyPosition() + yRotationOffset;
    } else {
        xTranslation = properties.getxPosition() + xRotationOffset;
        yTranslation = properties.getyPosition() + yRotationOffset;
        if (properties.isInvertX())
            xTranslation = pageWidth - watermarkWidth - xTranslation;
        if (properties.isInvertY())
            yTranslation = pageHeight - watermarkHeight - yTranslation;
    }
    return new Point2D.Double(xTranslation, yTranslation);
}

From source file:Clip.java

/**
 * Indicates if this Clip intersects the given rectangle expanded
 * by the additional margin pace./*from  w  w  w  .java2 s . com*/
 * @param r the rectangle to test for intersect
 * @param margin additional margin "bleed" to include in the intersection
 * @return true if the clip intersects the expanded region, false otherwise
 */
public boolean intersects(Rectangle2D r, double margin) {
    double tw = clip[6] - clip[0];
    double th = clip[7] - clip[1];
    double rw = r.getWidth();
    double rh = r.getHeight();
    if (rw < 0 || rh < 0 || tw < 0 || th < 0) {
        return false;
    }
    double tx = clip[0];
    double ty = clip[1];
    double rx = r.getX() - margin;
    double ry = r.getY() - margin;
    rw += rx + 2 * margin;
    rh += ry + 2 * margin;
    tw += tx;
    th += ty;
    //      overflow || intersect
    return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
}

From source file:org.tsho.dmc2.core.chart.BasinRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {
    basinComponent.setDataobject(null);/*w w w  . j  a v a 2  s  .  c o  m*/
    attractorsSamplePoints = new Vector();

    state = STATE_RUNNING;

    gridWidth = (int) dataArea.getWidth();
    gridHeight = (int) dataArea.getHeight();

    this.imageX = (int) dataArea.getX() + 1;
    this.imageY = (int) dataArea.getY();

    this.image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB);
    this.g2 = g2;
    WritableRaster raster = image.getRaster();

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    double maxCoordinate = Math.abs(domainAxis.getUpperBound());
    if (Math.abs(domainAxis.getLowerBound()) > maxCoordinate)
        maxCoordinate = Math.abs(domainAxis.getLowerBound());
    if (Math.abs(rangeAxis.getLowerBound()) > maxCoordinate)
        maxCoordinate = Math.abs(rangeAxis.getLowerBound());
    if (Math.abs(rangeAxis.getUpperBound()) > maxCoordinate)
        maxCoordinate = Math.abs(rangeAxis.getUpperBound());
    if (infinity < maxCoordinate)
        infinity = maxCoordinate + 1;

    grid = new Grid(new double[] { domainAxis.getLowerBound(), domainAxis.getUpperBound(),
            rangeAxis.getLowerBound(), rangeAxis.getUpperBound() }, gridHeight, gridWidth);
    imageData = ((DataBufferInt) raster.getDataBuffer()).getData();
    rate = gridHeight * gridWidth / 100;
    attractorsSamplePoints = new Vector();

    BasinsAlgorithm bA = null;
    if (type == FAST_ALGORITHM)
        bA = new FastBasinsAlgorithm(this);
    else if (type == SLOW_ALGORITHM)
        bA = new SlowBasinsAlgorithm(this);
    bA.run();

    /** Now that grid is computed, pass it to the BasinComponent for possible storing */
    int[] tmp = grid.getData();
    grid.setData((int[]) tmp.clone());//from now on, grid data is disconnected from image data
    basinComponent.setDataobject(grid);

    drawImage();
    state = STATE_FINISHED;
}

From source file:LineGraphDrawable.java

/**
 * Draws the bar-graph into the given Graphics2D context in the given area.
 * This method will not draw a graph if the data given is null or empty.
 * /*from  w  ww .j  av  a2  s  .  com*/
 * @param graphics
 *          the graphics context on which the bargraph should be rendered.
 * @param drawArea
 *          the area on which the bargraph should be drawn.
 */
public void draw(final Graphics2D graphics, final Rectangle2D drawArea) {
    if (graphics == null) {
        throw new NullPointerException();
    }
    if (drawArea == null) {
        throw new NullPointerException();
    }

    final int height = (int) drawArea.getHeight();
    if (height <= 0) {
        return;
    }

    final Graphics2D g2 = (Graphics2D) graphics.create();
    if (background != null) {
        g2.setPaint(background);
        g2.draw(drawArea);
    }

    if (data == null || data.length == 0) {
        g2.dispose();
        return;
    }

    g2.translate(drawArea.getX(), drawArea.getY());

    float d = getDivisor(data, height);
    final int spacing = getSpacing();
    final int w = (((int) drawArea.getWidth()) - (spacing * (data.length - 1))) / (data.length - 1);

    float min = Float.MAX_VALUE;
    for (int index = 0; index < data.length; index++) {
        Number i = data[index];
        if (i == null) {
            continue;
        }
        final float value = i.floatValue();
        if (value < min) {
            min = value;
        }
    }

    int x = 0;
    int y = -1;

    if (d == 0.0) {
        // special case -- a horizontal straight line
        d = 1.0f;
        y = -height / 2;
    }

    final Line2D.Double line = new Line2D.Double();
    for (int i = 0; i < data.length - 1; i++) {
        final int px1 = x;
        x += (w + spacing);
        final int px2 = x;

        g2.setPaint(color);

        final Number number = data[i];
        final Number nextNumber = data[i + 1];
        if (number == null && nextNumber == null) {
            final float delta = height - ((0 - min) / d);
            line.setLine(px1, y + delta, px2, y + delta);
        } else if (number == null) {
            line.setLine(px1, y + (height - ((0 - min) / d)), px2,
                    y + (height - ((nextNumber.floatValue() - min) / d)));
        } else if (nextNumber == null) {
            line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2,
                    y + (height - ((0 - min) / d)));
        } else {
            line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2,
                    y + (height - ((nextNumber.floatValue() - min) / d)));
        }
        g2.draw(line);

    }

    g2.dispose();

}

From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Retrieves the shape template for <code>e</code> and
 * transforms it according to the positions of its endpoints
 * in <code>layout</code>.//from   w w w .ja v a 2  s. co m
 * @param layout the <code>Layout</code> which specifies
 * <code>e</code>'s endpoints' positions
 * @param e the edge whose shape is to be returned
 * @return
 */
private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) {
    Pair<V> pair = layout.getGraph().getEndpoints(e);
    V v1 = pair.getFirst();
    V v2 = pair.getSecond();
    boolean isLoop = v1.equals(v2);
    Point2D p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1));
    Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2));
    if (p1 == null || p2 == null)
        return null;
    float x1 = (float) p1.getX();
    float y1 = (float) p1.getY();
    float x2 = (float) p2.getX();
    float y2 = (float) p2.getY();

    // translate the edge to the starting vertex
    AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1);

    Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer()
            .transform(Context.<Graph<V, E>, E>getInstance(vv.getGraphLayout().getGraph(), e));
    if (isLoop) {
        // make the loops proportional to the size of the vertex
        Shape s2 = vv.getRenderContext().getVertexShapeTransformer().transform(v2);
        Rectangle2D s2Bounds = s2.getBounds2D();
        xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight());
        // move the loop so that the nadir is centered in the vertex
        xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2);
    } else {
        float dx = x2 - x1;
        float dy = y2 - y1;
        // rotate the edge to the angle between the vertices
        double theta = Math.atan2(dy, dx);
        xform.rotate(theta);
        // stretch the edge to span the distance between the vertices
        float dist = (float) Math.sqrt(dx * dx + dy * dy);
        xform.scale(dist, 1.0f);
    }

    // transform the edge to its location and dimensions
    edgeShape = xform.createTransformedShape(edgeShape);
    return edgeShape;
}

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

/**
  * Draws an axis line at the current cursor position and edge.
  * /*ww w  .j  a  va2 s. c  o m*/
  * This always uses RectangleEdge.RIGHT, so the cursor is the x position.
  * 
  * @param g2  the graphics device.
  * @param cursor  the cursor position. 
  * @param dataArea  the data area.
  * @param edge  the edge.
  * 
  * Original method is in <code>org.jfree.chart.axis.ValueAxis</code>
  */
protected void drawAxisLine(Graphics2D g2, double cursor, Rectangle2D dataArea) {

    if (!isAxisLineVisible()) {
        // originally in drawTickMarksAndLabels
        return;
    }

    Line2D axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getHeight());

    g2.setPaint(getAxisLinePaint());
    g2.setStroke(getAxisLineStroke());
    g2.draw(axisLine);

}

From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java

/**
 * Undraw the previous selected region (if it was drawn), calculate the new regions, draw again, save
 * the points, and draw the numeric ratio in its little box
 * @param e//w ww .j ava  2  s.c om
 */
public void mouseDragged(MouseEvent e) {

    if (this.selectedRegionStart == null || e.getX() < this.selectedRegionStart.getX()) {
        return;
    }

    if (this.selectedRegion != null)
        drawOrUndrawRegion();

    // Erase the previous zoom rectangle (if any)...
    Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea();

    this.selectedRegion = new Rectangle2D.Double(this.selectedRegionStart.getX(), scaledDataArea.getMinY(),
            Math.min(Math.abs(e.getX() - selectedRegionStart.getX()),
                    _chartPanel.getWidth() - this.selectedRegionStart.getX()),
            scaledDataArea.getHeight());
    transformAndSaveSelectedRegion();

    // Draw the new zoom rectangle...
    drawOrUndrawRegion();

    lastMousedRatio = Rounder.round(Math.exp(transformMouseXValue(e.getX())), 2);
    drawRatioInBox(getChartPanelGraphics());
}

From source file:org.zanata.util.TestEventForScreenshotListener.java

private Rectangle getScreenRectangle() {
    // http://stackoverflow.com/a/13380999/14379
    Rectangle2D result = new Rectangle2D.Double();
    GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (GraphicsDevice gd : localGE.getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
            Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
        }//from w  w w.  ja v  a  2s .c o  m
    }
    return new Rectangle((int) result.getWidth(), (int) result.getHeight());
}

From source file:org.apache.pdfbox.rendering.TilingPaint.java

/**
 * Returns the pattern image in parent stream coordinates.
 *//*  w  w w .  j a v  a2  s . c o  m*/
private BufferedImage getImage(PageDrawer drawer, PDTilingPattern pattern, PDColorSpace colorSpace,
        PDColor color, AffineTransform xform, Rectangle2D anchorRect) throws IOException {
    ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);

    float width = (float) Math.abs(anchorRect.getWidth());
    float height = (float) Math.abs(anchorRect.getHeight());

    // device scale transform (i.e. DPI) (see PDFBOX-1466.pdf)
    Matrix xformMatrix = new Matrix(xform);
    float xScale = Math.abs(xformMatrix.getScalingFactorX());
    float yScale = Math.abs(xformMatrix.getScalingFactorY());
    width *= xScale;
    height *= yScale;

    int rasterWidth = Math.max(1, ceiling(width));
    int rasterHeight = Math.max(1, ceiling(height));

    // create raster
    WritableRaster raster = cm.createCompatibleWritableRaster(rasterWidth, rasterHeight);
    BufferedImage image = new BufferedImage(cm, raster, false, null);

    Graphics2D graphics = image.createGraphics();

    // flip a -ve YStep around its own axis (see gs-bugzilla694385.pdf)
    if (pattern.getYStep() < 0) {
        graphics.translate(0, rasterHeight);
        graphics.scale(1, -1);
    }

    // flip a -ve XStep around its own axis
    if (pattern.getXStep() < 0) {
        graphics.translate(rasterWidth, 0);
        graphics.scale(-1, 1);
    }

    // device scale transform (i.e. DPI)
    graphics.scale(xScale, yScale);

    // apply only the scaling from the pattern transform, doing scaling here improves the
    // image quality and prevents large scale-down factors from creating huge tiling cells.
    Matrix newPatternMatrix;
    newPatternMatrix = Matrix.getScaleInstance(Math.abs(patternMatrix.getScalingFactorX()),
            Math.abs(patternMatrix.getScalingFactorY()));

    // move origin to (0,0)
    newPatternMatrix.concatenate(Matrix.getTranslateInstance(-pattern.getBBox().getLowerLeftX(),
            -pattern.getBBox().getLowerLeftY()));

    // render using PageDrawer
    drawer.drawTilingPattern(graphics, pattern, colorSpace, color, newPatternMatrix);
    graphics.dispose();

    return image;
}

From source file:org.uva.itast.blended.omr.pages.PDFPageImage.java

private Rectangle2D toPDFUnits(Rectangle2D rect) {
    float ratioHeight = PREFERRED_PIXELS_HEIGHT_A4 / getPage().getHeight();
    float ratioWidth = PREFERRED_PIXELS_WIDTH_A4 / getPage().getWidth();
    Rectangle2D rectNew = new Rectangle();
    rectNew.setFrame(rect.getX() / ratioWidth, rect.getY() / ratioHeight, rect.getWidth() / ratioWidth,
            rect.getHeight() / ratioHeight);
    return rectNew;
}