Example usage for java.awt.geom Rectangle2D getCenterX

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

Introduction

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

Prototype

public double getCenterX() 

Source Link

Document

Returns the X 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 ww .ja  v 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:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions//from  w  ww . 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:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) {
    g2.setPaint(Color.orange);/*from w ww.  j  a  v  a2s.  co  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);//from w  w w  .  j  a va2 s.  c  o  m
    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: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);
    }/* w  w  w  .  j  a v  a2 s.co 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:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   w ww  .  jav 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:eu.hydrologis.jgrass.charting.impl.LineDrawer.java

/**
 * Draws the circle.//  w w w  .  ja va2 s  .  c  o  m
 * 
 * @param g2 the graphics device.
 * @param area the area in which to draw.
 */
public void draw(Graphics2D g2, Rectangle2D area) {
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
    } else {
        g2.setPaint(Color.black);
        g2.setStroke(new BasicStroke(1.0f));
    }

    Line2D line = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
    g2.draw(line);
}

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

/**
 * Paints the panel./*from w  w  w .  ja v  a  2 s . 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.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 .  j a  v  a  2 s .c o  m*/

    // 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);
}