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.XYCloudSymbolRenderer.java

/**
 * Draws the visual representation of a single symbol.
 *//*  ww  w.j  a v  a 2  s.  co  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) {
    // Needs a new graphics object to use translate() and rotate()
    Graphics2D g2 = (Graphics2D) g2d.create();
    g2.setRenderingHints(renderHints);

    double middleY = plotArea.getCenterY();
    CloudDataset cloudData = (CloudDataset) dataset;
    Number x = cloudData.getX(series, item);
    double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, plot.getDomainAxisEdge());
    g2.translate((int) middleX, (int) middleY); // make x=0, y=0 the middle of the symbol
    g2.setStroke(new BasicStroke());
    double height = plotArea.getHeight() - 2;

    // we set the width to be 20 which is the same as the weather symbols 
    double width = calculateWidth(plotArea.getWidth());
    double startX = -(width / 2);
    double startY[] = { -(height / 2), -(height / 4), 0, (height / 4) };
    double values[] = { (cloudData.getHighClouds(series, item).doubleValue() / 100.0),
            (cloudData.getMediumClouds(series, item).doubleValue() / 100.0),
            (cloudData.getLowClouds(series, item).doubleValue() / 100.0),
            (cloudData.getFog(series, item).doubleValue() / 100.0) };

    for (int i = 0; i < values.length; i++) { // for each cloud type
        g2.setColor(new Color(96, 96, 96));
        g2.fill(new Rectangle2D.Double(startX, startY[i], (width * values[i]), (height / 4 - 1))); // plot could
        g2.setColor(new Color(97, 204, 247));
        g2.fill(new Rectangle2D.Double(startX + (width * values[i]), startY[i], (width * (1 - values[i])),
                (height / 4 - 1))); // plot sky
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.LineReadHandler.java

private void createLineElementFromBounds(final float x1, final float y1, final float x2, final float y2,
        final Stroke stroke, final String name, final Color c, final Rectangle2D bounds) {
    if (x1 == x2) {
        // assume that we have a vertical line
        final VerticalLineElementFactory elementFactory = new VerticalLineElementFactory();
        elementFactory.setName(name);/*w  w w .j  a  v  a 2 s  .c  o m*/
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(bounds.getX()));
        elementFactory.setY(new Float(bounds.getY()));
        elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    } else if (y1 == y2) {
        // assume that we have a horizontal line
        final HorizontalLineElementFactory elementFactory = new HorizontalLineElementFactory();
        elementFactory.setName(name);
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(bounds.getX()));
        elementFactory.setY(new Float(bounds.getY()));
        elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    } else {
        // here comes the magic - we transform the line into the absolute space;
        // this should preserve the general appearance. Heck, and if not, then
        // it is part of the users reponsibility to resolve that. Magic does not
        // solve all problems, you know.
        final Line2D line = new Line2D.Float(Math.abs(x1), Math.abs(y1), Math.abs(x2), Math.abs(y2));
        final Rectangle2D shapeBounds = line.getBounds2D();
        final Shape transformedShape = ShapeTransform.translateShape(line, -shapeBounds.getX(),
                -shapeBounds.getY());
        // and use that shape with the user's bounds to create the element.
        final ContentElementFactory elementFactory = new ContentElementFactory();
        elementFactory.setName(name);
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(shapeBounds.getX()));
        elementFactory.setY(new Float(shapeBounds.getY()));
        elementFactory.setMinimumWidth(new Float(shapeBounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(shapeBounds.getHeight()));
        elementFactory.setContent(transformedShape);
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    }
}

From source file:org.pentaho.di.core.gui.SwingGC.java

public SwingGC(Graphics2D gc, Rectangle2D rect, int iconsize, int xOffset, int yOffset) throws KettleException {
    this(null, gc, null, new Point((int) rect.getWidth(), (int) rect.getHeight()), iconsize, xOffset, yOffset);
}

From source file:statechum.analysis.learning.Visualiser.java

protected static PluggableRenderer constructRenderer(Graph g, final LayoutOptions options) {
    final LayoutOptions graphLayoutOptions = options != null ? options : new LayoutOptions();

    PluggableRenderer r = new PluggableRenderer() {
        /**/*from   w w  w.jav  a 2 s .  c  o m*/
         * Draws the edge <code>e</code>, whose endpoints are at <code>(x1,y1)</code>
         * and <code>(x2,y2)</code>, on the graphics context <code>g</code>.
         * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> instance
         * is scaled in the x-direction so that its width is equal to the distance between
         * <code>(x1,y1)</code> and <code>(x2,y2)</code>.
         */
        @Override
        protected void drawSimpleEdge(Graphics2D g2d, Edge e, int x1, int y1, int x2, int y2) {
            final Vertex v1 = (Vertex) e.getEndpoints().getFirst();
            final Vertex v2 = (Vertex) e.getEndpoints().getSecond();
            boolean isLoop = v1.equals(v2);
            final Shape s2 = vertexShapeFunction.getShape(v2);
            Shape edgeShape = edgeShapeFunction.getShape(e);
            final double dx = x2 - x1;
            final double dy = y2 - y1;

            boolean edgeHit = true;
            boolean arrowHit = true;
            Rectangle deviceRectangle = null;
            if (screenDevice != null) {
                Dimension d = screenDevice.getSize();
                if (d.width <= 0 || d.height <= 0) {
                    d = screenDevice.getPreferredSize();
                }
                deviceRectangle = new Rectangle(0, 0, d.width, d.height);
            }

            String label = edgeStringer.getLabel(e);
            assert (label != null);
            Component labelComponent = prepareRenderer(graphLabelRenderer, label, isPicked(e), e);
            Dimension d = labelComponent.getPreferredSize();
            Rectangle2D EdgeShapeBoundaries = edgeShape.getBounds2D();
            AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1);
            double yMin = 0, yMax = 0;
            double thetaRadians = 0;
            if (isLoop) {
                // this is a self-loop. scale it is larger than the vertex
                // it decorates and translate it so that its nadir is
                // at the center of the vertex.
                int edgeIndex = ParallelEdgeIndexSingleton.getInstance().getIndex(e);
                Rectangle2D s2Bounds = s2.getBounds2D();
                double scaleBy = 1 + (graphLayoutOptions.scaleLines - 1) * 1. / 3.;
                double translation = s2Bounds.getHeight() * (1. / 4. + edgeIndex / 4.);

                xform.translate(0, -scaleBy * translation);
                xform.scale(scaleBy * s2Bounds.getWidth(), scaleBy * s2Bounds.getHeight());
                yMin = scaleBy * (EdgeShapeBoundaries.getMinY() * s2Bounds.getHeight()) - translation;
                yMax = scaleBy * (EdgeShapeBoundaries.getMaxY() * s2Bounds.getHeight()) - translation;

            } else {
                // this is a normal edge. Rotate it to the angle between
                // vertex endpoints, then scale it to the distance between
                // the vertices
                thetaRadians = Math.atan2(dy, dx);
                double dist = Math.sqrt(dx * dx + dy * dy);
                xform.rotate(thetaRadians);
                xform.scale(dist, 1.0);
                yMin = EdgeShapeBoundaries.getMinY();
                yMax = EdgeShapeBoundaries.getMaxY();
            }

            edgeShape = xform.createTransformedShape(edgeShape);
            // Debug code
            /*
            if (!isLoop)
            {
            g2d.setPaint(new Color( 250, 250, 0));
               AffineTransform rect = AffineTransform.getTranslateInstance(x1, y1+yMin);
               rect.rotate(thetaRadians);
               g2d.fill(rect.createTransformedShape(
              new Rectangle(0,0,(int)Math.sqrt(dx*dx + dy*dy),(int)(yMax-yMin))));
            }
            else
            {
            g2d.setPaint(new Color( 100, 250, 0));
            AffineTransform rect = AffineTransform.getTranslateInstance(x1-s2.getBounds2D().getWidth()/2, y1+yMin);
               rect.rotate(thetaRadians);
               g2d.fill(rect.createTransformedShape(
              new Rectangle(0,0,(int)s2.getBounds2D().getWidth(),(int)(yMax-yMin))));
            }*/

            edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle);

            if (edgeHit == true) {
                Paint oldPaint = g2d.getPaint();

                // get Paints for filling and drawing
                // (filling is done first so that drawing and label use same Paint)
                Paint fill_paint = edgePaintFunction.getFillPaint(e);
                if (fill_paint != null) {
                    g2d.setPaint(fill_paint);
                    g2d.fill(edgeShape);
                }
                Paint draw_paint = edgePaintFunction.getDrawPaint(e);
                if (draw_paint != null) {
                    g2d.setPaint(draw_paint);
                    g2d.draw(edgeShape);
                }

                double scalex = g2d.getTransform().getScaleX();
                double scaley = g2d.getTransform().getScaleY();
                // see if arrows are too small to bother drawing
                if (scalex < .3 || scaley < .3)
                    return;

                if (edgeArrowPredicate.evaluate(e)) {

                    Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond());
                    AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2);
                    destVertexShape = xf.createTransformedShape(destVertexShape);

                    arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle);
                    if (arrowHit) {

                        AffineTransform at;
                        if (edgeShape instanceof GeneralPath)
                            at = getArrowTransform((GeneralPath) edgeShape, destVertexShape);
                        else
                            at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape);
                        if (at == null)
                            return;
                        Shape arrow = edgeArrowFunction.getArrow(e);
                        arrow = at.createTransformedShape(arrow);
                        // note that arrows implicitly use the edge's draw paint
                        g2d.fill(arrow);
                    }
                    assert !(e instanceof UndirectedEdge);
                }

                // For difference visualisation only
                boolean labelBelow = false;
                if (graphLayoutOptions.showDIFF && (draw_paint == null
                        || draw_paint instanceof Color && ((Color) draw_paint).equals(Color.BLACK)))
                    labelBelow = true;

                // Now draw the label.
                double xLabel = 0, yLabel = 0, xa = 0, ya = 0, rotation = thetaRadians;
                if (isLoop) {
                    double displacementY = labelBelow ? -yMin + d.height : -yMin + d.height,
                            displacementX = d.width / 2;
                    xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians);
                    ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians);
                    xLabel = xa - displacementX * Math.cos(thetaRadians);
                    yLabel = ya - displacementX * Math.sin(thetaRadians);
                } else if (dx < 0) {
                    double displacementY = labelBelow ? yMax - d.height : (-yMax - d.height),
                            displacementX = d.width / 2;
                    xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians);
                    ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians);
                    xLabel = xa + displacementX * Math.cos(thetaRadians);
                    yLabel = ya + displacementX * Math.sin(thetaRadians);
                    rotation = thetaRadians + Math.PI;
                } else {
                    double displacementY = labelBelow ? yMax : -yMax, displacementX = d.width / 2;
                    xa = x1 + dx / 2 + displacementY * Math.sin(thetaRadians);
                    ya = y1 + dy / 2 - displacementY * Math.cos(thetaRadians);
                    xLabel = xa - displacementX * Math.cos(thetaRadians);
                    yLabel = ya - displacementX * Math.sin(thetaRadians);
                }

                AffineTransform old = g2d.getTransform();
                AffineTransform labelTransform = new AffineTransform();
                // Debug code: 
                //g2d.drawLine((int)(x1+dx/2), (int)(y1+dy/2), (int)(xa), (int)(ya));g2d.drawLine((int)(xa), (int)(ya), (int)(xLabel), (int)(yLabel));
                labelTransform.translate(xLabel, yLabel);
                labelTransform.rotate(rotation);
                g2d.setTransform(labelTransform);
                rendererPane.paintComponent(g2d, labelComponent, screenDevice, 0, 0, d.width, d.height, true);
                g2d.setTransform(old);

                // restore old paint
                g2d.setPaint(oldPaint);
            } // if edgeHit == true
        }
    };
    r = labelEdges(g, r, graphLayoutOptions);
    r = labelVertices(r, g, graphLayoutOptions);
    r.setVertexIncludePredicate(new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            if (!graphLayoutOptions.showIgnored && graphLayoutOptions.ignoredStates != null
                    && graphLayoutOptions.ignoredStates.contains(object.toString()))
                return false;

            if (graphLayoutOptions.showNegatives)
                return true;
            else
                return DeterministicDirectedSparseGraph.isAccept((Vertex) object);
        }
    });
    return r;
}

From source file:Polygon2D.java

/**
 * Tests if the interior of this <code>Polygon</code> entirely
 * contains the specified <code>Rectangle2D</code>.
 * @param r the specified <code>Rectangle2D</code>
 * @return <code>true</code> if this <code>Polygon</code> entirely
 *                         contains the specified <code>Rectangle2D</code>;
 *                        <code>false</code> otherwise.
 * @see #contains(double, double, double, double)
 *//*from  w  w w.  j  a v  a 2 s .c o m*/
public boolean contains(Rectangle2D r) {
    return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}

From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java

public void calcGrids() {
    Rectangle2D rect = getBounds2D();
    double w = rect.getWidth();

    double h = rect.getHeight();

    if (h > 150 || w > 150) {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").fine("Error: " + this);
        return;/* w  w w . j  a  va2s . c  o  m*/
    }

    int x = (int) rect.getX();
    int y = (int) rect.getY();

    int xSteps = (int) (w / (int) Grid.SIZE);
    int ySteps = (int) (h / (int) Grid.SIZE);

    for (int i = 0; i < xSteps; i++) {
        for (int j = 0; j < ySteps; j++) {
            Polygon p = new Polygon();
            p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
            if (this.contains(p.getBounds().x + Grid.SIZE / 2, p.getBounds().y + Grid.SIZE / 2)) {
                Pnt topLeft = new Pnt(x + i * Grid.SIZE, y + j * Grid.SIZE);
                Pnt bottomRight = new Pnt(x + i * Grid.SIZE + Grid.SIZE, y + Grid.SIZE + j * Grid.SIZE);
                Grid grid = new Grid(topLeft, bottomRight);
                grids.add(grid);
            }
        }
    }
}

From source file:com.projity.pm.graphic.pert.PertLayout.java

public void updateBounds() {
    dependencyGraph.updatePertLevels();//from  w ww.  ja  v a2  s.c om

    GraphicConfiguration config = GraphicConfiguration.getInstance();

    Point2D origin = new Point2D.Double(config.getPertXOffset(), config.getPertYOffset());
    Rectangle2D ref = new Rectangle2D.Double(config.getPertXOffset(), config.getPertYOffset(),
            config.getPertCellWidth(), config.getPertCellHeight());
    int row = 0;
    int col = -1;
    setEmpty();
    for (Iterator i = cache.getIterator(); i.hasNext();) {
        GraphicNode current = (GraphicNode) i.next();
        int currentCol = cache.getPertLevel(current) - 1;
        if (currentCol <= col)
            row++;
        col = currentCol;

        TexturedShape texturedShape = findShape(current);
        if (texturedShape == null)
            continue;
        double centerX = origin.getX() + ref.getMaxX() * col + ref.getWidth() / 2;
        double centerY = origin.getY() + ref.getMaxY() * row + ref.getHeight() / 2;
        //System.out.println(centerX+"/"+centerY);
        GeneralPath shape = texturedShape.toGeneralPath(ref.getWidth(), ref.getHeight(),
                centerX - ref.getWidth() / 2, centerY, null);
        current.setPertShape(shape, centerX, centerY);
        Rectangle cellBounds = network.scale(shape.getBounds());
        if (isEmpty())
            bounds.setBounds(cellBounds);
        else
            Rectangle.union(bounds, cellBounds, bounds);
    }
    fireLayoutChanged();
}

From source file:Polygon2D.java

/**
 * Tests if the interior of this <code>Polygon</code> intersects the
 * interior of a specified <code>Rectangle2D</code>.
 * @param r a specified <code>Rectangle2D</code>
 * @return <code>true</code> if this <code>Polygon</code> and the
 *                         interior of the specified <code>Rectangle2D</code>
 *                         intersect each other; <code>false</code>
 *                         otherwise.//from  w w  w.  j  av a  2 s. c  o m
 */
public boolean intersects(Rectangle2D r) {
    return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}

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

@Override
public void fillPath(int windingRule) throws IOException {
    graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    graphics.setPaint(getNonStrokingPaint());
    setClip();//from   w  w w . j  a  v a2 s.  c  o m
    linePath.setWindingRule(windingRule);

    // disable anti-aliasing for rectangular paths, this is a workaround to avoid small stripes
    // which occur when solid fills are used to simulate piecewise gradients, see PDFBOX-2302
    // note that we ignore paths with a width/height under 1 as these are fills used as strokes,
    // see PDFBOX-1658 for an example
    Rectangle2D bounds = linePath.getBounds2D();
    boolean noAntiAlias = isRectangular(linePath) && bounds.getWidth() > 1 && bounds.getHeight() > 1;
    if (noAntiAlias) {
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }

    if (!(graphics.getPaint() instanceof Color)) {
        // apply clip to path to avoid oversized device bounds in shading contexts (PDFBOX-2901)
        Area area = new Area(linePath);
        area.intersect(new Area(graphics.getClip()));
        graphics.fill(area);
    } else {
        graphics.fill(linePath);
    }

    linePath.reset();

    if (noAntiAlias) {
        // JDK 1.7 has a bug where rendering hints are reset by the above call to
        // the setRenderingHint method, so we re-set all hints, see PDFBOX-2302
        setRenderingHints();
    }
}

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

private AffineTransform createTransform(double x, double y, BufferedImage image, Rectangle2D dataArea) {
    int wi = image.getWidth();
    wi--;//from  ww  w .  j  a v a  2s.  c o  m
    int hi = image.getHeight();
    hi--;
    double wd = dataArea.getWidth();
    wd--;
    double hd = dataArea.getHeight();
    hd--;
    double a = wd / wi;
    double b = hd / hi;
    double m00 = a;
    double m01 = 0;
    double m02 = -x * a + x;
    double m10 = 0;
    double m11 = b;
    double m12 = -y * b + y;
    AffineTransform at = new AffineTransform(m00, m10, m01, m11, m02, m12);
    return at;
}