Example usage for java.awt.geom Point2D.Double getX

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

Introduction

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

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:Main.java

public static Area getArrowFromTo(Point2D.Double from, Point2D.Double to) {
    double dx = 8;
    double dy = Math.floor(dx / 2);
    if (from.getX() < to.getX())
        dx *= -1;/* w  ww .  j a va2s  .  c o m*/

    GeneralPath arrowHeadFrom = new GeneralPath();
    arrowHeadFrom.moveTo(to.getX() + dx, to.getY() - dy);
    arrowHeadFrom.lineTo(to.getX(), to.getY());
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + dy);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + 0.1);
    arrowHeadFrom.lineTo(from.getX(), from.getY() + 0.1);
    arrowHeadFrom.lineTo(from.getX(), from.getY() - 0.1);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - 0.1);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - dy);

    Area b = new Area(arrowHeadFrom);

    return b;
}

From source file:Main.java

public static Rectangle2D.Double toSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at);
    Point2D.Double pSheetX = toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at);
    Point2D.Double pSheetY = toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at);
    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), pSheet.distance(pSheetY));

    return res;/*  www .  ja  va 2s. co  m*/
}

From source file:Main.java

public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY());
    Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY());
    Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY());
    Point2D.Double pScreen = new Point2D.Double();
    Point2D.Double pScreenX = new Point2D.Double();
    Point2D.Double pScreenY = new Point2D.Double();

    try {//from w ww . j a v  a  2  s.com
        at.transform(pSheet, pScreen);
        at.transform(pSX, pScreenX);
        at.transform(pSY, pScreenY);
    } catch (Exception e) {
        System.err.print(e.getMessage());
    }

    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY));

    return res;
}

From source file:net.anthonypoon.fintech.assignment.one.part2.Plotter.java

void addList(String seriesName, List<Point2D.Double> ptList) {
    XYSeries dataSeries = new XYSeries(seriesName, false);
    for (Point2D.Double pt : ptList) {
        dataSeries.add(pt.getX(), pt.getY());
    }/*from   w  ww  .  j ava  2  s  .com*/
    dataObj.addSeries(dataSeries);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.InstrumentInterfaceClasses.XYZMotionInterface.java

public int gotoFOV(FOV fov) {

    try {//  ww w  .  j a v a  2s .c om
        Point2D.Double stage = fovXYtoStageXY(fov);
        core_.setXYPosition(xystage_, stage.getX(), stage.getY());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    return 1;
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.InstrumentInterfaceClasses.XYZMotionInterface.java

public FOV getCurrentFOV() {

    try {//from  ww w.  j  a v a 2s .  c  o  m
        Point2D.Double xy = stageXYtoFOVXY(core_.getXYStagePosition(xystage_));
        Double z = getZAbsolute();
        return new FOV(xy.getX(), xy.getY(), z, pp_);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    return new FOV("A1", pp_, 0); // replace with something that more clearly
    // indicated error?
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Point2D.Double getTargetPoint(Point2D.Double darkTarget, Point2D.Double lightTarget, double slope) {
    Point2D.Double normalizedStart = new Point2D.Double();
    normalizedStart.setLocation(lightTarget.getX() - darkTarget.getX(), lightTarget.getY() - darkTarget.getY());

    Point2D.Double normalizedResult = new Point2D.Double();
    double normX = (Math.pow(slope, 2.0) * normalizedStart.getX() - (normalizedStart.getY() * slope))
            / (Math.pow(slope, 2.0) - 1.0);
    normalizedResult.setLocation(normX, normX / slope);
    Point2D.Double result = new Point2D.Double();

    result.setLocation(normalizedResult.getX() + darkTarget.getX(),
            normalizedResult.getY() + darkTarget.getY());
    return result;
}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateSquare(Point2D.Double center, double radius) {
    return new VisualPeakAnnotation(new Rectangle2D.Double(center.getX() - (radius / 2.0d),
            center.getY() - (radius / 2.0d), radius, radius), center, PeakAnnotationType.POINTER);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private void drawMarker(Point2D.Double point, Graphics2D g2, Color color) {
    Stroke oldStroke = g2.getStroke();
    Paint oldPaint = g2.getPaint();
    g2.setPaint(color);//w w w .j  av  a 2  s. c  om
    //Shape line = new Line2D.Double(point, point);
    Shape marker = new Ellipse2D.Double(point.getX() - 1.5, point.getY() - 1.5, 3, 3);
    g2.fill(marker);
    g2.setPaint(oldPaint);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

/**<!====== drawItem ======================================================>
   Draws a 3D bar to represent one data item.
   <!      Name       Description>
   @param  g2         the graphics device.
   @param  state      the renderer state.
   @param  dataArea   the area for plotting the data.
   @param  plot       the plot.//  www.  j a  va  2  s . co m
   @param  domainAxis the domain axis.
   @param  rangeAxis  the range axis.
   @param  dataset    the dataset.
   @param  row        the row index (zero-based).
   @param  column     the column index (zero-based).
   @param  pass       the pass index.
<!=======================================================================>*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    g2.setStroke(new BasicStroke(1));
    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color endColor = getFrontDark((Color) itemPaint);
        Color startColor = (Color) itemPaint;
        Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor,
                (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor);
        g2.setPaint(paint);
    }
    g2.fill(bar);

    double x0 = bar.getMinX(); // left
    double x1 = x0 + getXOffset(); // offset left
    double x2 = bar.getMaxX(); // right
    double x3 = x2 + getXOffset(); // offset right

    double y0 = bar.getMinY() - getYOffset(); // offset top
    double y1 = bar.getMinY(); // bar top
    double y2 = bar.getMaxY() - getYOffset(); // offset bottom
    double y3 = bar.getMaxY(); // bottom

    //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight());

    Line2D.Double line = new Line2D.Double(x2, y1, x2, y3);
    g2.draw(line);

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    g2.setPaint(itemPaint);

    // Draw the right side
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            Color startColor = getSideLight((Color) itemPaint);
            Color endColor = getSideDark((Color) itemPaint);
            Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3,
                    endColor);
            g2.setPaint(paint);
        }
        g2.fill(bar3dRight);
    }

    // Draw the top
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1); // bottom left
    bar3dTop.lineTo((float) x1, (float) y0); // top left
    bar3dTop.lineTo((float) x3, (float) y0); // top right
    bar3dTop.lineTo((float) x2, (float) y1); // bottom right
    bar3dTop.closePath();
    if (itemPaint instanceof Color) {
        Color endColor = getTopDark((Color) itemPaint);
        Color startColor = getTopLight((Color) itemPaint);
        //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor);
        Point2D.Double topRight = new Point2D.Double(x3, y0);
        Point2D.Double bottomLeft = new Point2D.Double(x0, y1);
        //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2)));
        Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2)));
        Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor,
                (float) darkEnd.getX(), (float) darkEnd.getY(), endColor);
        g2.setPaint(paint);
        //drawMarker(topRight, g2, startColor);
    }
    g2.fill(bar3dTop);
    g2.setPaint(itemPaint);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }

}