Example usage for java.awt.geom Rectangle2D getCenterY

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

Introduction

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

Prototype

public double getCenterY() 

Source Link

Document

Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision.

Usage

From source file:Main.java

public static void centerOnScreenAtLocation(Window window, Point desiredLocation) {
    GraphicsDevice currentScreen = getCurrentScreen(desiredLocation, window.getSize());
    Rectangle2D screenBounds = currentScreen.getDefaultConfiguration().getBounds();
    window.setLocation((int) screenBounds.getCenterX() - (window.getWidth() / 2),
            (int) screenBounds.getCenterY() - (window.getHeight() / 2));
}

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

/**
 * A utility method that computes a rectangle using relative radius values.
 * //w w  w.jav  a  2s. c o m
 * @param rect  the reference rectangle.
 * @param radiusW  the width radius (must be > 0.0)
 * @param radiusH  the height radius.
 * 
 * @return A new rectangle.
 */
public static Rectangle2D rectangleByRadius(Rectangle2D rect, double radiusW, double radiusH) {
    double x = rect.getCenterX();
    double y = rect.getCenterY();
    double w = rect.getWidth() * radiusW;
    double h = rect.getHeight() * radiusH;
    return new Rectangle2D.Double(x - w / 2.0, y - h / 2.0, w, h);
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Transform getTransformForBounds(Dimension canvasSize, Rectangle2D bounds, Double zoomStep) {
    double widthRatio = canvasSize.width / bounds.getWidth();
    double heightRatio = canvasSize.height / bounds.getHeight();
    double canvasCenterX = canvasSize.width / 2.0;
    double canvasCenterY = canvasSize.height / 2.0;
    double centerX = bounds.getCenterX();
    double centerY = bounds.getCenterY();

    double scale = Math.min(widthRatio, heightRatio);

    if (zoomStep != null) {
        int zoom = (int) (Math.log(scale) / Math.log(2.0));

        scale = Math.pow(2.0, zoom);
    }//from  w  ww  .j  a  v a  2  s  .  c  o m

    double scaleX = scale;
    double scaleY = scale;
    double translationX = canvasCenterX - centerX * scaleX;
    double translationY = canvasCenterY - centerY * scaleY;

    return new Transform(scaleX, scaleY, translationX, translationY);
}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions//  w w  w  .j  a v a  2 s . co m
 *          the dimensions for the rectangle.
 * @param frame
 *          the frame to align to.
 * @param hAlign
 *          the horizontal alignment.
 * @param vAlign
 *          the vertical alignment.
 * @return A rectangle.
 */
private static final Rectangle2D __createAlignedRectangle2D(final Size2D dimensions, final Rectangle2D frame,
        final HorizontalAlignment hAlign, final VerticalAlignment vAlign) {
    double x, y;

    x = y = Double.NaN;

    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    } else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    } else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    } else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    } else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width, dimensions.height);
}

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}/*from  www.j  a  v a  2  s . c  o  m*/
 */
@Override
public void mouseDragged(MouseEvent e) {
    if (source != null) {
        final ChartRenderingInfo info = getChartRenderingInfo();
        final Rectangle2D dataArea = info.getPlotInfo().getPlotArea();
        final double xx = dataArea.getCenterX();
        final double yy = dataArea.getCenterY();
        tx = e.getX() - xx;
        ty = e.getY() - yy;
        repaint();
    }
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) {
    g2.setPaint(Color.orange);//  w  w w. ja v  a2  s.c o m
    g2.setStroke(new BasicStroke(1));
    Rectangle2D frame = mask.getRectangleFrame();
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 10);
    g2.setPaint(fillColor);
    g2.fill(mask.getShape());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) {
    g2.setPaint(Color.orange);/*w ww . j  av  a 2  s  . com*/
    g2.setStroke(new BasicStroke(1));
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 30);
    g2.setPaint(fillColor);
    g2.fill(frame);
}

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

/**
 * Paints the panel.//  ww  w . j a v  a2s  .c  o  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.getCenterX();
    final double y = available.getCenterY();

    final Line2D line1 = new Line2D.Double(x - 2.0, y + 2.0, x + 2.0, y - 2.0);
    final Line2D line2 = new Line2D.Double(x - 2.0, y - 2.0, x + 2.0, y + 2.0);
    g2.setPaint(Color.red);
    g2.draw(line1);
    g2.draw(line2);

    g2.setFont(this.font);
    g2.setPaint(Color.black);
    if (this.rotate) {
        TextUtilities.drawRotatedString(this.text, g2, (float) x, (float) y, this.anchor, this.angle,
                this.rotationAnchor);
    } else {
        TextUtilities.drawAlignedString(this.text, g2, (float) x, (float) y, this.anchor);
    }

}

From source file:DrawTest.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // draw a rectangle

    double leftX = 100;
    double topY = 100;
    double width = 200;
    double height = 150;

    Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
    g2.draw(rect);/*w  w  w.ja  va  2s.c om*/

    // draw the enclosed ellipse

    Ellipse2D ellipse = new Ellipse2D.Double();
    ellipse.setFrame(rect);
    g2.draw(ellipse);

    // draw a diagonal line

    g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height));

    // draw a circle with the same center

    double centerX = rect.getCenterX();
    double centerY = rect.getCenterY();
    double radius = 150;

    Ellipse2D circle = new Ellipse2D.Double();
    circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
    g2.draw(circle);
}

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

/**
 * Draws the visual representation of a single symbol.
 *///from  w  ww.  j av a 2s  .  com
@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
    }
}