Example usage for java.awt.geom Point2D setLocation

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

Introduction

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

Prototype

public abstract void setLocation(double x, double y);

Source Link

Document

Sets the location of this Point2D to the specified double coordinates.

Usage

From source file:com.anrisoftware.globalpom.format.point.PointFormat.java

private Point2D parsePoint(String string, Point2D point) throws ParseException {
    if (point == null) {
        point = new Point2D.Double();
    }//w w  w  .ja va 2 s.  c  o m
    string = remove(string, "(");
    string = remove(string, ")");
    String[] split = StringUtils.split(string, ",");
    if (split.length != 2) {
        throw log.errorTwoPointsNeeded(string);
    }
    double x = numberFormat.parse(split[0].trim()).doubleValue();
    double y = numberFormat.parse(split[1].trim()).doubleValue();
    point.setLocation(x, y);
    return point;
}

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

protected synchronized void calcPositions(V v) {
    FRVertexData fvd = getFRData(v);/*from www .j  a  va 2 s .  co m*/
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, fvd.norm());

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

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

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java

protected synchronized void calcPositions(V v) {
    VertexData fvd = getData(v);//from   w w  w  .ja  va  2  s. c o m
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, fvd.norm());

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

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

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

From source file:Visualizer.FRWeightedLayout.java

protected synchronized void calcPositions(Functionality.Node v) {
    FRVertexData fvd = getFRData(v);/* w ww .  j a v  a2s.c  o m*/
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, fvd.norm());

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

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

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

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

protected synchronized void calcPositions(V v) {
    FRVertexData fvd = getFRData(v);//from  ww  w.j a v  a  2 s . c o  m
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = fvd.norm();
    if (deltaLength <= 0.005)
        return;

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

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

    double newYDisp = fvd.getY() * percentage() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

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

public void setLocation(Virtualizable<V> picked, double x, double y) {
    Point2D coord = getCoordinates(picked);
    coord.setLocation(x, y);
}

From source file:org.apache.fop.svg.AbstractFOPTextPainter.java

private void updateLocationFromACI(AttributedCharacterIterator aci, Point2D loc) {
    //Adjust position of span
    Float xpos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.X);
    Float ypos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.Y);
    Float dxpos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DX);
    Float dypos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DY);
    if (xpos != null) {
        loc.setLocation(xpos.doubleValue(), loc.getY());
    }/*from w  w w .  j a  v  a  2  s .  c  o  m*/
    if (ypos != null) {
        loc.setLocation(loc.getX(), ypos.doubleValue());
    }
    if (dxpos != null) {
        loc.setLocation(loc.getX() + dxpos.doubleValue(), loc.getY());
    }
    if (dypos != null) {
        loc.setLocation(loc.getX(), loc.getY() + dypos.doubleValue());
    }
}

From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java

/** {@inheritDoc} */
public IFPainter startPageContent() throws IFException {
    int bitmapWidth;
    int bitmapHeight;
    double scale;
    Point2D offset = null;
    if (targetBitmapSize != null) {
        //Fit the generated page proportionally into the given rectangle (in pixels)
        double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth();
        double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight();
        bitmapWidth = targetBitmapSize.width;
        bitmapHeight = targetBitmapSize.height;

        //Centering the page in the given bitmap
        offset = new Point2D.Double();
        if (scale2w < scale2h) {
            scale = scale2w;/*w ww . j  a  v a 2 s .  c o m*/
            double h = this.currentPageDimensions.height * scale / 1000;
            offset.setLocation(0, (bitmapHeight - h) / 2.0);
        } else {
            scale = scale2h;
            double w = this.currentPageDimensions.width * scale / 1000;
            offset.setLocation((bitmapWidth - w) / 2.0, 0);
        }
    } else {
        //Normal case: just scale according to the target resolution
        scale = scaleFactor * getUserAgent().getTargetResolution()
                / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
        bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f);
        bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f);
    }

    //Set up bitmap to paint on
    this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
    Graphics2D graphics2D = this.currentImage.createGraphics();

    // draw page background
    if (!getSettings().hasTransparentPageBackground()) {
        graphics2D.setBackground(getSettings().getPageBackgroundColor());
        graphics2D.setPaint(getSettings().getPageBackgroundColor());
        graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight);
    }

    //Set rendering hints
    graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }
    if (getSettings().isQualityRenderingEnabled()) {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    }
    graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

    //Set up initial coordinate system for the page
    if (offset != null) {
        graphics2D.translate(offset.getX(), offset.getY());
    }
    graphics2D.scale(scale / 1000f, scale / 1000f);

    return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}

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   w ww.j  a v  a  2s  .  c  o  m*/
    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:edu.uci.ics.jung.algorithms.layout.SpringLayout2.java

@Override
protected void moveNodes() {
    synchronized (getSize()) {
        try {//ww w. jav a2 s . c o m
            for (V v : getGraph().getVertices()) {
                if (isLocked(v))
                    continue;
                SpringVertexData vd = springVertexData.get(v);
                if (vd == null)
                    continue;
                Point2D xyd = transform(v);

                vd.dx += vd.repulsiondx + vd.edgedx;
                vd.dy += vd.repulsiondy + vd.edgedy;

                //                    int currentCount = currentIteration % this.loopCountMax;
                //                    System.err.println(averageCounter+" --- vd.dx="+vd.dx+", vd.dy="+vd.dy);
                //                    System.err.println("averageDelta was "+averageDelta);

                averageDelta.setLocation(
                        ((averageDelta.getX() * averageCounter) + vd.dx) / (averageCounter + 1),
                        ((averageDelta.getY() * averageCounter) + vd.dy) / (averageCounter + 1));
                //                    System.err.println("averageDelta now "+averageDelta);
                //                    System.err.println();
                averageCounter++;

                // keeps nodes from moving any faster than 5 per time unit
                xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)),
                        xyd.getY() + Math.max(-5, Math.min(5, vd.dy)));

                Dimension d = getSize();
                int width = d.width;
                int height = d.height;

                if (xyd.getX() < 0) {
                    xyd.setLocation(0, xyd.getY());//                     setX(0);
                } else if (xyd.getX() > width) {
                    xyd.setLocation(width, xyd.getY()); //setX(width);
                }
                if (xyd.getY() < 0) {
                    xyd.setLocation(xyd.getX(), 0);//setY(0);
                } else if (xyd.getY() > height) {
                    xyd.setLocation(xyd.getX(), height); //setY(height);
                }

            }
        } catch (ConcurrentModificationException cme) {
            moveNodes();
        }
    }
}