Example usage for java.awt.geom Ellipse2D.Double getWidth

List of usage examples for java.awt.geom Ellipse2D.Double getWidth

Introduction

In this page you can find the example usage for java.awt.geom Ellipse2D.Double getWidth.

Prototype

public abstract double getWidth();

Source Link

Document

Returns the width of the framing rectangle in double precision.

Usage

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2             the graphics device.
 * @param state          the renderer state.
 * @param dataArea       the area within which the data is being drawn.
 * @param info           collects information about the drawing.
 * @param plot           the plot (can be used to obtain standard color
 *                       information etc).
 * @param domainAxis     the domain (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (a {@link edu.ucla.stat.SOCR.motionchart.MotionDataSet} is expected).
 * @param series         the series index (zero-based).
 * @param item           the item index (zero-based).
 * @param crosshairState crosshair information for the plot
 *                       (<code>null</code> permitted).
 * @param pass           the pass index.
 *///  w  w  w.  j  av  a2 s  . c  om
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    if (!(dataset instanceof MotionDataSet)) {
        throw new IllegalArgumentException("The dataset must be of type MotionDataSet.");
    }

    // return straight away if the item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();

    Ellipse2D.Double shape = (Ellipse2D.Double) getItemShape(series, item);

    if (shape.getWidth() != 0 && shape.getHeight() != 0) {
        Ellipse2D.Double circle = translateShape(shape, plot, dataArea);
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            currCircle = circle;
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterX(), circle.getCenterY(),
                        false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterY(), circle.getCenterX(),
                        false);
            }
        }

        // add an entity if this info is being collected
        EntityCollection entities;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
            if (entities != null && circle.intersects(dataArea)) {
                addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY());
            }
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, shape.getCenterX(), shape.getCenterY(), domainAxisIndex,
                rangeAxisIndex, circle.getCenterX(), circle.getCenterY(), orientation);
    }
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Translates the shape so that it displays correctly given the plot and dataArea.
 *
 * @param shape     the shape to translate
 * @param plot      the plot that will be used to translate the shape
 * @param dataArea  the dataArea that the shape will be translated to
 * @return          The translated shape
 *//*from  w w w. ja  va2s  . c o  m*/
@SuppressWarnings({ "SuspiciousNameCombination" })
protected Ellipse2D.Double translateShape(Ellipse2D.Double shape, XYPlot plot, Rectangle2D dataArea) {
    Ellipse2D.Double circle = null;

    //double x = shape.getCenterX();
    //double y = shape.getCenterY();
    double z = shape.getWidth();

    PlotOrientation orientation = plot.getOrientation();

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();
    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    double transX1 = domainAxis.valueToJava2D(shape.getX(), dataArea, domainAxisLocation);
    double transX2 = domainAxis.valueToJava2D(shape.getX() + shape.getWidth(), dataArea, domainAxisLocation);
    //The upper-left corner is the lower-left on the graph (screen origin vs. graph origin)
    double transY1 = rangeAxis.valueToJava2D(shape.getY() + shape.getHeight(), dataArea, rangeAxisLocation);
    double transY2 = rangeAxis.valueToJava2D(shape.getY(), dataArea, rangeAxisLocation);

    double width = z * domainAxis.getRange().getLength() * domainZoomMultiplier * SIZE_MULTIPLIER;
    double height = z * rangeAxis.getRange().getLength() * rangeZoomMultiplier * SIZE_MULTIPLIER;
    double transWidth = domainAxis.lengthToJava2D(width, dataArea, domainAxisLocation);//transX2 - transX1;
    double transHeight = rangeAxis.lengthToJava2D(height, dataArea, rangeAxisLocation);//transY2 - transY1;

    double transX = (transX1 + transX2) / 2.0;
    double transY = (transY1 + transY2) / 2.0;

    switch (getScaleType()) {
    case SCALE_ON_DOMAIN_AXIS:
        transHeight = transWidth;
        break;
    case SCALE_ON_RANGE_AXIS:
        transWidth = transHeight;
        break;
    default:
        break;
    }
    transWidth = Math.abs(transWidth);
    transHeight = Math.abs(transHeight);

    if (orientation == PlotOrientation.VERTICAL) {
        circle = new Ellipse2D.Double(transX - transWidth / 2.0, transY - transHeight / 2.0, transWidth,
                transHeight);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        circle = new Ellipse2D.Double(transY - transHeight / 2.0, transX - transWidth / 2.0, transHeight,
                transWidth);
    }

    return circle;
}