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:edu.uci.ics.jung.algorithms.layout.FRLayout2.java

protected void calcAttraction(E e) {
    Pair<V> endpoints = getGraph().getEndpoints(e);
    V v1 = endpoints.getFirst();/*from  ww w .  j ava 2 s .  c o m*/
    V v2 = endpoints.getSecond();
    boolean v1_locked = isLocked(v1);
    boolean v2_locked = isLocked(v2);

    if (v1_locked && v2_locked) {
        // both locked, do nothing
        return;
    }
    Point2D p1 = transform(v1);
    Point2D p2 = transform(v2);
    if (p1 == null || p2 == null)
        return;
    double xDelta = p1.getX() - p2.getX();
    double yDelta = p1.getY() - p2.getY();

    double deltaLength = Math.max(EPSILON, p1.distance(p2));

    double force = deltaLength / attraction_constant;

    assert Double.isNaN(force) == false : "Unexpected mathematical result in FRLayout:calcPositions [force]";

    double dx = xDelta * force;
    double dy = yDelta * force;
    Point2D fvd1 = frVertexData.get(v1);
    Point2D fvd2 = frVertexData.get(v2);
    if (v2_locked) {
        // double the offset for v1, as v2 will not be moving in
        // the opposite direction
        fvd1.setLocation(fvd1.getX() - 2 * dx, fvd1.getY() - 2 * dy);
    } else {
        fvd1.setLocation(fvd1.getX() - dx, fvd1.getY() - dy);
    }
    if (v1_locked) {
        // double the offset for v2, as v1 will not be moving in
        // the opposite direction
        fvd2.setLocation(fvd2.getX() + 2 * dx, fvd2.getY() + 2 * dy);
    } else {
        fvd2.setLocation(fvd2.getX() + dx, fvd2.getY() + dy);
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialScale.java

/**
 * Draws the scale on the dial plot./*from  w  w w .  j a  v  a2 s  .com*/
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius());
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength());
    Rectangle2D arcRectMinor = arcRect;
    if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(),
                this.getTickRadius() - this.getMinorTickLength());
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset());

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    Stroke arcStroke = new BasicStroke(0.75f);

    for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) {
        arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(arcStroke);
        g2.draw(arc);

        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(this.getMajorTickStroke());
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.getTickLabelsVisible()) {
            if (!firstLabel || this.getFirstTickLabelVisible()) {
                g2.setFont(this.getTickLabelFont());
                TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(),
                        (float) pt2.getY(), TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
            double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1);
            for (int i = 0; i < this.getMinorTickCount(); i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.getUpperBound()) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.getMinorTickStroke());
                g2.setPaint(this.getMinorTickPaint());
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}

From source file:org.opennms.features.topology.app.internal.jung.TopoFRLayout.java

protected void calcAttraction(E e) {
    Pair<V> endpoints = getGraph().getEndpoints(e);
    V v1 = endpoints.getFirst();// w  w w  .j a  v a 2s  . co m
    V v2 = endpoints.getSecond();
    boolean v1_locked = isLocked(v1);
    boolean v2_locked = isLocked(v2);

    if (v1_locked && v2_locked) {
        // both locked, do nothing
        return;
    }
    Point2D p1 = transform(v1);
    Point2D p2 = transform(v2);
    if (p1 == null || p2 == null)
        return;
    double xDelta = p1.getX() - p2.getX();
    double yDelta = p1.getY() - p2.getY();

    xDelta = Math.abs(xDelta) > EPSILON ? xDelta : xDelta == 0 ? epsilon() : Math.signum(xDelta) * EPSILON;
    yDelta = Math.abs(yDelta) > EPSILON ? yDelta : yDelta == 0 ? epsilon() : Math.signum(yDelta) * EPSILON;

    double deltaLength = Math.sqrt((xDelta * xDelta) + (yDelta * yDelta));

    double force = (deltaLength * deltaLength) / attraction_constant;

    if (Double.isNaN(force)) {
        throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [force]");
    }

    double dx = (xDelta / deltaLength) * force;
    double dy = (yDelta / deltaLength) * force;
    if (v1_locked == false) {
        FRVertexData fvd1 = getFRData(v1);
        fvd1.offset(-dx, -dy);
    }
    if (v2_locked == false) {
        FRVertexData fvd2 = getFRData(v2);
        fvd2.offset(dx, dy);
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialScale.java

/**
 * Draws the scale on the dial plot.//from   ww w .j a v  a2s . com
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius());
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength());
    Rectangle2D arcRectMinor = arcRect;
    if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(),
                this.getTickRadius() - this.getMinorTickLength());
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset());

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    Stroke arcStroke = new BasicStroke(0.75f);

    for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) {
        arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(arcStroke);
        g2.draw(arc);

        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(this.getMajorTickStroke());
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.getTickLabelsVisible()) {
            if (!firstLabel || this.getFirstTickLabelVisible()) {
                g2.setFont(this.getTickLabelFont());
                TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(),
                        (float) pt2.getY(), TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
            double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1);
            for (int i = 0; i < this.getMinorTickCount(); i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.getUpperBound()) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.getMinorTickStroke());
                g2.setPaint(this.getMinorTickPaint());
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}

From source file:com.projity.pm.graphic.network.NetworkRenderer.java

protected void updateLinkConnections(GraphicNode node, double[] linkPoints) {
    GeneralPath shape = getShape(node);
    if (shape == null)
        return;/*  w  ww.  j  a v  a  2 s. c  o  m*/
    Point2D center = getCenter(node);
    linkPoints[0] = center.getX();
    linkPoints[1] = center.getX();
    linkPoints[2] = center.getY();
    linkPoints[3] = center.getY();
    double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, x, y;
    for (PathIterator j = shape.getPathIterator(null); !j.isDone(); j.next()) {
        int segmentType = j.currentSegment(segment);
        switch (segmentType) {
        case PathIterator.SEG_MOVETO:
            x0 = segment[0];
            y0 = segment[1];
            x2 = x0;
            y2 = y0;
            break;
        case PathIterator.SEG_LINETO:
            x2 = segment[0];
            y2 = segment[1];
        case PathIterator.SEG_CLOSE:
            if (segmentType == PathIterator.SEG_CLOSE) {
                x2 = x0;
                y2 = y0;
            }
            //works only convex shapes
            double lambda;
            if (y2 != y1) {
                x = (center.getY() - y1) * (x2 - x1) / (y2 - y1) + x1;
                lambda = (x2 == x1) ? 0 : (x - x1) / (x2 - x1);
                if (x1 == x2 || (lambda >= 0 && lambda <= 1)) {
                    if (x < linkPoints[0])
                        linkPoints[0] = x;
                    if (x > linkPoints[1])
                        linkPoints[1] = x;
                }
            }
            if (x2 != x1) {
                y = (center.getX() - x1) * (y2 - y1) / (x2 - x1) + y1;
                lambda = (y2 == x1) ? 0 : (y - y1) / (y2 - y1);
                if (y1 == y2 || (lambda >= 0 && lambda <= 1)) {
                    if (y < linkPoints[2])
                        linkPoints[2] = y;
                    if (y > linkPoints[3])
                        linkPoints[3] = y;
                }
            }

            break;
        }
        x1 = x2;
        y1 = y2;
    }
}

From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java

/**
 *
 * @param xyie/*from w ww .j  a v a2  s .c o m*/
 */
public void addAnnotation(final XYItemEntity xyie) {
    Shape s = xyie.getArea();
    Point2D center = getCenter(s);
    final double xd = center.getX();
    final double yd = center.getY();
    addXYPeakAnnotation(xd, yd, null, true);
}

From source file:edu.uci.ics.jung.algorithms.layout.FRLayout2.java

protected synchronized void calcPositions(V v) {
    Point2D fvd = this.frVertexData.get(v);
    if (fvd == null)
        return;//from   www . jav  a2  s  .  com
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, Math.sqrt(fvd.getX() * fvd.getX() + fvd.getY() * fvd.getY()));

    double newXDisp = fvd.getX() / deltaLength * Math.min(deltaLength, temperature);

    assert Double.isNaN(newXDisp) == false : "Unexpected mathematical result in FRLayout:calcPositions [xdisp]";

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    double newX = xyd.getX() + Math.max(-5, Math.min(5, newXDisp));
    double newY = xyd.getY() + Math.max(-5, Math.min(5, newYDisp));

    newX = Math.max(innerBounds.getMinX(), Math.min(newX, innerBounds.getMaxX()));
    newY = Math.max(innerBounds.getMinY(), Math.min(newY, innerBounds.getMaxY()));

    xyd.setLocation(newX, newY);

}

From source file:com.mycompany.complexity.tool.mvn.TreeLayout.java

public int lastDimensionX() {
    Point2D p;
    int maxX = 0;
    for (V value : locations.keySet()) {
        p = locations.get(value);/*from  w  w w. j  a v  a 2s  .com*/
        if (p.getX() > maxX) {
            maxX = (int) p.getX() + 1;
        }
    }
    return maxX;
}

From source file:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java

@Override
public Blob applyTextWatermark(Blob input, String text, WatermarkProperties properties) {

    // Set up the graphic state to handle transparency
    // Define a new extended graphic state
    PDExtendedGraphicsState extendedGraphicsState = new PDExtendedGraphicsState();
    // Set the transparency/opacity
    extendedGraphicsState.setNonStrokingAlphaConstant((float) properties.getAlphaColor());

    try (PDDocument pdfDoc = PDDocument.load(input.getStream())) {

        PDFont font = PDType1Font.getStandardFont(properties.getFontFamily());
        float watermarkWidth = (float) (font.getStringWidth(text) * properties.getFontSize() / 1000f);
        int[] rgb = PDFUtils.hex255ToRGB(properties.getHex255Color());

        for (Object o : pdfDoc.getDocumentCatalog().getAllPages()) {
            PDPage page = (PDPage) o;/* w  ww.j  av  a 2 s  . c  o  m*/
            PDRectangle pageSize = page.findMediaBox();
            PDResources resources = page.findResources();

            // Get the defined graphic states.
            HashMap<String, PDExtendedGraphicsState> graphicsStateDictionary = (HashMap<String, PDExtendedGraphicsState>) resources
                    .getGraphicsStates();
            if (graphicsStateDictionary != null) {
                graphicsStateDictionary.put("TransparentState", extendedGraphicsState);
                resources.setGraphicsStates(graphicsStateDictionary);
            } else {
                Map<String, PDExtendedGraphicsState> m = new HashMap<>();
                m.put("TransparentState", extendedGraphicsState);
                resources.setGraphicsStates(m);
            }

            try (PDPageContentStream contentStream = new PDPageContentStream(pdfDoc, page, true, true, true)) {
                contentStream.beginText();
                contentStream.setFont(font, (float) properties.getFontSize());
                contentStream.appendRawCommands("/TransparentState gs\n");
                contentStream.setNonStrokingColor(rgb[0], rgb[1], rgb[2]);
                Point2D position = computeTranslationVector(pageSize.getWidth(), watermarkWidth,
                        pageSize.getHeight(), properties.getFontSize(), properties);
                contentStream.setTextRotation(Math.toRadians(properties.getTextRotation()), position.getX(),
                        position.getY());
                contentStream.drawString(text);
                contentStream.endText();
            }
        }
        return saveInTempFile(pdfDoc);

    } catch (Exception e) {
        throw new NuxeoException(e);
    }
}

From source file:inflor.core.gates.ui.PolygonGateAdapter.java

private void updateTemporaryAnnotation() {
    Point2D previousVertex = null;
    if (segments != null) {
        segments.stream().forEach(panel::removeTemporaryAnnotation);
    }/*w  ww . j a  v  a  2 s  . c o m*/
    segments = new ArrayList<>();
    for (Point2D v : vertices) {
        if (previousVertex == null) {
            previousVertex = v;
        } else {
            segments.add(
                    new XYLineAnnotation(previousVertex.getX(), previousVertex.getY(), v.getX(), v.getY()));
            previousVertex = v;
        }
    }
    segments.stream().forEach(panel::addTemporaryAnnotation);
}