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:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

public void selectRectangle(Rectangle2D selection, MouseEvent selectionEvent) {
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if (selection.getHeight() > 0 && selection.getWidth() > 0) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof XYPlot) {
            XYPlot plot = (XYPlot) p;/*from  w w w. j av  a  2  s .  c o  m*/
            Selection selectionObject = new Selection();
            for (int i = 0; i < plot.getDomainAxisCount(); i++) {
                ValueAxis domain = plot.getDomainAxis(i);
                double lowerDomain = domain.getLowerBound();
                double upperDomain = domain.getUpperBound();
                Range axisRange = new Range(lowerDomain + (upperDomain - lowerDomain) * hLower,
                        lowerDomain + (upperDomain - lowerDomain) * hUpper);
                for (String axisName : axisNameResolver.resolveXAxis(i)) {
                    selectionObject.addDelimiter(axisName, axisRange);
                }
            }
            for (int i = 0; i < plot.getRangeAxisCount(); i++) {
                ValueAxis range = plot.getRangeAxis(i);
                double lowerRange = range.getLowerBound();
                double upperRange = range.getUpperBound();
                Range axisRange = new Range(lowerRange + (upperRange - lowerRange) * vLower,
                        lowerRange + (upperRange - lowerRange) * vUpper);
                for (String axisName : axisNameResolver.resolveYAxis(i)) {
                    selectionObject.addDelimiter(axisName, axisRange);
                }
            }
            informSelectionListener(selectionObject, selectionEvent);
        }
    }

}

From source file:org.squidy.designer.zoom.impl.DataTypeShape.java

/**
 * TODO [RR]: Needs refactoring for automatically computes visual hierarchy.
 *//*from  w  w  w  .  j a v a  2s . c o  m*/
private void buildDataHierarchy() {

    PBounds bounds = getBoundsReference();
    Rectangle2D rectBounds = roundedRectangleShape.getBounds2D();

    DataItemShape iData = new DataItemShape(IData.class, true);
    iData.setBounds(rectBounds);
    iData.setOffset(bounds.getCenterX() - rectBounds.getCenterX(), 0);
    addChild(iData);

    Class<? extends IData>[] typesFirstRow = DataUtility.DATA_FIRST_LEVEL;
    int amount = typesFirstRow.length;
    double spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1);
    for (int i = 0; i < amount; i++) {
        boolean selected = dataTypes.contains(typesFirstRow[i]);
        DataItemShape item = new DataItemShape(typesFirstRow[i], selected);
        item.setBounds(rectBounds);
        item.setOffset((i * rectBounds.getWidth()) + (i * spacing), rectBounds.getHeight() + 200);
        addChild(item);
    }

    Class<? extends IData>[] typesSecondRow = DataUtility.DATA_SECOND_LEVEL;
    amount = typesSecondRow.length;
    spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1);
    for (int i = 0; i < amount; i++) {
        boolean selected = dataTypes.contains(typesSecondRow[i]);
        DataItemShape item = new DataItemShape(typesSecondRow[i], selected);
        item.setBounds(rectBounds);
        item.setOffset((i * rectBounds.getWidth()) + (i * spacing), (2 * rectBounds.getHeight()) + (2 * 200));
        addChild(item);
    }

    amount = 4;
    spacing = (bounds.getWidth() - (amount * rectBounds.getWidth())) / (amount - 1);
    boolean selected = dataTypes.contains(DataUtility.DATA_THIRD_LEVEL[0]);
    DataItemShape item = new DataItemShape(DataUtility.DATA_THIRD_LEVEL[0], selected);
    item.setBounds(rectBounds);
    item.setOffset((1 * rectBounds.getWidth()) + (1 * spacing), (3 * rectBounds.getHeight()) + (3 * 200));
    addChild(item);
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

private int drawText(Graphics2D graphics, String text, int hOffset) {
    Rectangle r = getTextBoundsRectangle();
    Rectangle2D textBounds = graphics.getFontMetrics().getStringBounds(text, graphics);
    if (textBounds.getWidth() > r.getWidth() - 4) {
        int y = coords[1] + hOffset;
        AttributedString attributedString = new AttributedString(text);
        attributedString.addAttribute(TextAttribute.FONT, graphics.getFont());
        AttributedCharacterIterator characterIterator = attributedString.getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, graphics.getFontRenderContext());
        while (measurer.getPosition() < characterIterator.getEndIndex()) {
            TextLayout textLayout = measurer.nextLayout((float) r.getWidth() - 4);
            y += textLayout.getAscent();
            float x = (float) (r.getCenterX() + 2 - textLayout.getBounds().getCenterX());
            textLayout.draw(graphics, x, y);
            y += textLayout.getDescent() + textLayout.getLeading();
        }/*from   w w w.  j a  va  2 s .  c  o  m*/
        return y - coords[1];
    } else {
        graphics.drawString(text, (float) (r.getCenterX() + 2 - textBounds.getCenterX()),
                (float) (coords[1] + textBounds.getHeight() + hOffset));
        return (int) (textBounds.getHeight() + hOffset + 3);
    }
}