Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:tufts.vue.LWComponent.java

public final void setLocation(Point2D p) {
    setLocation((float) p.getX(), (float) p.getY());
}

From source file:tufts.vue.LWComponent.java

private Point2D.Float getSlideIconStackLocation() {
    final Point2D corner = getZeroSouthEastCorner();

    float xoff = (float) corner.getX() - 60;
    float yoff = (float) corner.getY() - 60;

    // If shape is small, try and keep it from overlapping too much (esp the label)
    if (xoff < getWidth() / 2f)
        xoff = getWidth() / 2f;//from w w w. jav  a2  s  .  com
    if (yoff < getHeight() * 0.75f)
        yoff = getHeight() * 0.75f;

    // todo: can reuse getZeroCorner point2D instead of creating anew...
    return new Point2D.Float(xoff, yoff);

}

From source file:ucar.unidata.idv.control.chart.MyXYPlot.java

/**
 * Draws the plot within the specified area on a graphics device.
 *
 * @param g2  the graphics device.//w  w w.  j  a va2 s.com
 * @param area  the plot area (in Java2D space).
 * @param anchor  an anchor point in Java2D space (<code>null</code>
 *                permitted).
 * @param parentState  the state from the parent plot, if there is one
 *                     (<code>null</code> permitted).
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    this.axisOffset.trim(dataArea);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    Map axisStateMap = drawAxes(g2, area, dataArea, info);

    if ((anchor != null) && !dataArea.contains(anchor)) {
        anchor = null;
    }
    CrosshairState crosshairState = new CrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    crosshairState.setCrosshairX(getDomainCrosshairValue());
    crosshairState.setCrosshairY(getRangeCrosshairValue());
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    AxisState domainAxisState = (AxisState) axisStateMap.get(getDomainAxis());
    if (domainAxisState == null) {
        if (parentState != null) {
            domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());
        }
    }
    if (domainAxisState != null) {
        drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
        drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    }

    AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (rangeAxisState != null) {
        drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
        drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        drawZeroRangeBaseline(g2, dataArea);
    }

    // draw the markers that are associated with a specific renderer...
    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }

    // now draw annotations and render data items...
    boolean foundData = false;
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    if (order == DatasetRenderingOrder.FORWARD) {

        // draw background annotations
        int rendererCount = this.renderers.size();
        for (int i = 0; i < rendererCount; i++) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
            }
        }

        // render data items...
        for (int i = 0; i < getDatasetCount(); i++) {
            foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
        }

        // draw foreground annotations
        for (int i = 0; i < rendererCount; i++) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
            }
        }

    } else if (order == DatasetRenderingOrder.REVERSE) {

        // draw background annotations
        int rendererCount = this.renderers.size();
        for (int i = rendererCount - 1; i >= 0; i--) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
            }
        }

        ucar.unidata.util.Trace.call1("renderData");
        for (int i = getDatasetCount() - 1; i >= 0; i--) {
            foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
        }
        ucar.unidata.util.Trace.call2("renderData");

        // draw foreground annotations
        for (int i = rendererCount - 1; i >= 0; i--) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
            }
        }

    }

    PlotOrientation orient = getOrientation();

    // draw domain crosshair if required...
    if (!this.domainCrosshairLockedOnData && (anchor != null)) {
        double xx = getDomainAxis().java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
        crosshairState.setCrosshairX(xx);
    }
    setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
    if (isDomainCrosshairVisible()) {
        double x = getDomainCrosshairValue();
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        if (orient == PlotOrientation.HORIZONTAL) {
            drawHorizontalLine(g2, dataArea, x, stroke, paint);
        } else if (orient == PlotOrientation.VERTICAL) {
            drawVerticalLine(g2, dataArea, x, stroke, paint);
        }
    }

    // draw range crosshair if required...
    if (!this.rangeCrosshairLockedOnData && (anchor != null)) {
        double yy = getRangeAxis().java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
        crosshairState.setCrosshairX(yy);
    }
    setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
    if (isRangeCrosshairVisible() && getRangeAxis().getRange().contains(getRangeCrosshairValue())) {
        double y = getRangeCrosshairValue();
        Paint paint = getRangeCrosshairPaint();
        Stroke stroke = getRangeCrosshairStroke();
        if (orient == PlotOrientation.HORIZONTAL) {
            drawVerticalLine(g2, dataArea, y, stroke, paint);
        } else if (orient == PlotOrientation.VERTICAL) {
            drawHorizontalLine(g2, dataArea, y, stroke, paint);
        }
    }

    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }

    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }

    drawAnnotations(g2, dataArea, info);
    g2.setClip(originalClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, dataArea);

}

From source file:Distortions.java

public void showWithRadialTangential(String[] preTitles, String title, double[][] preData, // [0] - dx, [1] - dy
        int width, int deciamte, double x0, double y0) {
    int indexDx = 0;
    int indexDy = 1;
    int indexDr = 0;
    int indexDt = 1;
    int indexDa = 2;
    String[] extraTitles = { "R-corr(pix)", "T-corr{pix)", "A-corr(pix)" };
    int newImages = extraTitles.length;
    int length = preData[0].length;
    int height = length / width;
    double[][] data = new double[preData.length + newImages][length];
    String[] titles = new String[preTitles.length + newImages];
    for (int i = 0; i < preData.length; i++) {
        data[i + newImages] = preData[i];
        titles[i + newImages] = preTitles[i];
    }/*from   w w  w  .  ja va 2 s.c o  m*/
    for (int i = 0; i < newImages; i++) {
        titles[i] = extraTitles[i];
        data[i] = new double[length];
    }
    Point2D Z = new Point2D.Double(0.0, 0.0);
    for (int i = 0; i < length; i++) {
        Point2D R = new Point2D.Double((deciamte * (i % width)) - x0, (deciamte * (i / width)) - y0);
        double r = R.distance(Z);
        Point2D uR = new Point2D.Double(1.0, 0.0);
        if (r > 0)
            uR.setLocation(R.getX() / r, R.getY() / r);
        Point2D dXY = new Point2D.Double(preData[indexDx][i], preData[indexDy][i]);
        data[indexDr][i] = dXY.getX() * uR.getX() + dXY.getY() * uR.getY();
        data[indexDt][i] = -dXY.getX() * uR.getY() + dXY.getY() * uR.getX();
        data[indexDa][i] = dXY.distance(Z);
    }
    this.SDFA_INSTANCE.showArrays(data, width, height, true, title, titles);
}