Example usage for java.awt.geom Rectangle2D.Double getCenterX

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

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D.Double 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:mulavito.gui.components.LayerViewer.java

public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) {
    if (vv == null || home == null)
        return;//from  w  w w  .ja va2 s  .  c  o  m

    // reset transforms
    MutableTransformer layoutTrans = vv.getRenderContext().getMultiLayerTransformer()
            .getTransformer(edu.uci.ics.jung.visualization.Layer.LAYOUT);
    layoutTrans.setToIdentity();
    MutableTransformer viewTrans = vv.getRenderContext().getMultiLayerTransformer()
            .getTransformer(edu.uci.ics.jung.visualization.Layer.VIEW);
    viewTrans.setToIdentity();

    Dimension dim = vv.getSize();
    Rectangle2D.Double graphBounds = home.getGraphBoundsCache();

    CrossoverScalingControl scaler = new CrossoverScalingControl();

    // Scale using crossover scaler, so vertices will not grow
    // larger than they are in original
    double factor = Double.POSITIVE_INFINITY;

    if (direction == Directions.HORIZONTAL || direction == Directions.BOTH)
        factor = dim.getWidth() / graphBounds.width;
    if (direction == Directions.VERTICAL || direction == Directions.BOTH || Double.isInfinite(factor))
        factor = Math.min(factor, dim.getHeight() / graphBounds.height);
    scaler.scale(vv, (float) factor, vv.getCenter());

    // Translate center of graph to center of vv.
    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
    double dx = (lvc.getX() - graphBounds.getCenterX());
    double dy = (lvc.getY() - graphBounds.getCenterY());
    layoutTrans.translate(dx, dy);
}

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

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D graphics2d = (Graphics2D) g;
    Dimension dimension = getSize();
    Insets insets = getInsets();/*from ww w  .  j a v  a2  s .  co  m*/
    java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(insets.left, insets.top,
            dimension.getWidth() - (double) insets.left - (double) insets.right,
            dimension.getHeight() - (double) insets.top - (double) insets.bottom);
    double d = double1.getCenterX();
    double d1 = double1.getCenterY();
    java.awt.geom.Line2D.Double double2 = new java.awt.geom.Line2D.Double(d - 2D, d1 + 2D, d + 2D, d1 - 2D);
    java.awt.geom.Line2D.Double double3 = new java.awt.geom.Line2D.Double(d - 2D, d1 - 2D, d + 2D, d1 + 2D);
    graphics2d.setPaint(Color.red);
    graphics2d.draw(double2);
    graphics2d.draw(double3);
    graphics2d.setFont(font);
    graphics2d.setPaint(Color.black);
    if (rotate)
        TextUtilities.drawRotatedString(text, graphics2d, (float) d, (float) d1, anchor, angle, rotationAnchor);
    else
        TextUtilities.drawAlignedString(text, graphics2d, (float) d, (float) d1, anchor);
}