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:net.sf.jasperreports.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer.//ww  w  .j  av  a 2s .com
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*from w ww.ja  v  a 2s .  c o m*/
 */
@Override
public void mouseReleased(MouseEvent e) {
    //Don't create node or edge with right click !
    if (!e.isPopupTrigger()) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();

        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphWithOperations graph = (GraphWithOperations) layout.getGraph();

        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();

        if (pickSupport != null) {
            CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            // if no vertex create one on the fly
            if (vertex == null) {
                final CNode newNode = vertexFactory.create();
                final Point2D newPos = vv.getRenderContext().getMultiLayerTransformer()
                        .inverseTransform(e.getPoint());
                graph.addVertex(newNode, new CPoint(newPos.getX(), newPos.getY()));
                layout.lock(newNode, false);
                vertex = newNode;
            } else {
                //reset to initial color if needed
                if (startVertex != null && !startVertex.equals(vertex)) {
                    if (pointedVertices.containsKey(vertex)) {
                        vertex.setColor(pointedVertices.get(vertex));
                    }
                }
                layout.lock(vertex, false);
            }
            // if the source & destination vertex are not the same : create edge
            if (vertex != null && startVertex != null) {
                if (!startVertex.equals(vertex)) {
                    transformEdgeShape(down, down);
                    transformArrowShape(down, e.getPoint());
                    graph.addEdge(edgeFactory.create(), startVertex, vertex, edgeIsDirected);
                }
            }
        }
        //Reset fields
        startVertex = null;
        down = null;
        edgeIsDirected = EdgeType.UNDIRECTED;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);

        //clear color mapping map
        pointedVertices.clear();
        dragVertex = null;
        lastDragVertex = null;

        vv.repaint();
    }
}

From source file:grafix.telas.MolduraAreaDados.java

private Point2D converterPontoNoPlotParaMoldura_EixoLog(final Point2D pontoPlot) {
    XYPlot plot = getPlot();//from  ww  w . j a v  a2  s.c o  m
    ValueAxis vAxis = plot.getRangeAxis();
    ValueAxis dAxis = plot.getDomainAxis();
    double dX = dAxis.getUpperBound() - dAxis.getLowerBound();
    double dYlog = Math.log10(vAxis.getUpperBound()) - Math.log10(vAxis.getLowerBound());
    double proporcaoX = this.getWidth() / dX;
    double fracaoX = pontoPlot.getX() - dAxis.getLowerBound();
    double fracaoYlog = Math.log10(pontoPlot.getY()) - Math.log10(vAxis.getLowerBound());
    double coefYlog = fracaoYlog / dYlog;
    return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (coefYlog * this.getHeight()));
}

From source file:thesaurusEditor.gui.graph.MainGraph.java

public void zoomToVertex(Konzept k) {
    Layout<Konzept, EdgeClass> layout = vv.getGraphLayout();
    Point2D newCenter = layout.transform(k);
    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
    final double dx = (lvc.getX() - newCenter.getX()) / 100;
    final double dy = (lvc.getY() - newCenter.getY()) / 100;
    vv.getPickedVertexState().pick(k, true);
    Runnable animator = new Runnable() {

        public void run() {
            for (int i = 0; i < 100; i++) {
                vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy);
                try {
                    Thread.sleep(5);
                } catch (InterruptedException ex) {
                }/*from  w w  w  . jav a  2  s.c  o m*/
            }
        }
    };
    Thread thread = new Thread(animator);
    thread.start();
}

From source file:de.fhg.igd.mapviewer.server.ClippingTileProviderDecorator.java

/**
 * Constructor//w  w  w .  ja  v  a 2s .  c  o m
 * 
 * @param tileProvider the tile provider
 * @param topLeft the top left constraint
 * @param bottomRight the bottom right constraint
 * @param minRange the minimum visible range
 * @param customOverlayColor custom overlay color to use, may be
 *            <code>null</code>
 */
public ClippingTileProviderDecorator(final TileProvider tileProvider, final GeoPosition topLeft,
        final GeoPosition bottomRight, int minRange, Color customOverlayColor) {
    super(tileProvider);

    if (minRange <= 0)
        minRange = 1;

    int zoom = tileProvider.getMinimumZoom();
    boolean tryNextZoom = true;

    // determine valid zoom levels and their tile offsets/ranges
    while (tryNextZoom && zoom <= tileProvider.getMaximumZoom()) {
        try {
            Point2D topLeftPixel = tileProvider.getConverter().geoToPixel(topLeft, zoom);
            Point2D bottomRightPixel = tileProvider.getConverter().geoToPixel(bottomRight, zoom);

            int xMin = ((int) topLeftPixel.getX()) / tileProvider.getTileWidth(zoom);
            int yMin = ((int) topLeftPixel.getY()) / tileProvider.getTileHeight(zoom);
            int xMax = ((int) bottomRightPixel.getX()) / tileProvider.getTileWidth(zoom);
            int yMax = ((int) bottomRightPixel.getY()) / tileProvider.getTileHeight(zoom);

            // check for validity
            if (xMin <= xMax && yMin <= yMax && TileProviderUtils.isValidTile(tileProvider, xMin, yMin, zoom)
                    && TileProviderUtils.isValidTile(tileProvider, xMax, yMax, zoom)) {
                // valid tiles, enter offset and ranges
                xTileOffset.add(xMin);
                xTileRange.add(xMax - xMin + 1);

                yTileOffset.add(yMin);
                yTileRange.add(yMax - yMin + 1);

                this.topLeft.add(new Point((int) topLeftPixel.getX() - xMin * tileProvider.getTileWidth(zoom),
                        (int) topLeftPixel.getY() - yMin * tileProvider.getTileHeight(zoom)));
                this.bottomRight
                        .add(new Point((int) bottomRightPixel.getX() - xMin * tileProvider.getTileWidth(zoom),
                                (int) bottomRightPixel.getY() - yMin * tileProvider.getTileHeight(zoom)));

                if (xMax - xMin + 1 <= minRange || yMax - yMin + 1 <= minRange)
                    tryNextZoom = false; // we reached the max zoom
                else
                    zoom++; // prepare next zoom
            } else {
                // invalid tiles
                tryNextZoom = false;
                zoom--; // previous zoom
            }
        } catch (IllegalGeoPositionException e) {
            // invalid positions or conversion failed
            tryNextZoom = false;
            zoom--; // previous zoom
        }
    }

    if (zoom < getMinimumZoom()) {
        throw new IllegalArgumentException("No zoom levels are valid for clipping"); //$NON-NLS-1$
    } else {
        maxZoom = zoom;

        painter = new ClippingPainter(customOverlayColor);

        log.info("Initialized ClippingTileProviderDecorator with minZoom = " //$NON-NLS-1$
                + tileProvider.getMinimumZoom() + ", maxZoom = " + maxZoom); //$NON-NLS-1$
    }
}

From source file:util.ModSpringLayout1.java

protected void calculateRepulsion() {
    try {//from   w ww.j  a  v a  2s  .c  o m
        for (V v : getGraph().getVertices()) {
            if (isLocked(v)) {
                continue;
            }

            SpringVertexData svd = getSpringVertexData(v);
            if (svd == null) {
                continue;
            }
            double dx = 0, dy = 0;

            for (V v2 : getGraph().getVertices()) {
                if (v == v2) {
                    continue;
                }
                Point2D p = transform(v);
                Point2D p2 = transform(v2);
                if (p == null || p2 == null) {
                    continue;
                }
                double vx = p.getX() - p2.getX();
                double vy = p.getY() - p2.getY();
                double distance = vx * vx + vy * vy;
                if (distance == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distance < repulsion_range * repulsion_range) {
                    double factor = 1;
                    dx += factor * vx / Math.pow(distance, 2);
                    dy += factor * vy / Math.pow(distance, 2);
                }
            }
            double dlen = dx * dx + dy * dy;
            if (dlen > 0) {
                dlen = Math.sqrt(dlen) / 2;
                svd.repulsiondx += dx / dlen;
                svd.repulsiondy += dy / dlen;
            }
        }
    } catch (ConcurrentModificationException cme) {
        calculateRepulsion();
    }
}

From source file:util.ModSpringLayout2.java

protected void relaxEdges() {
    try {//  w w  w  .j  a  va 2 s.  c o m
        for (E e : getGraph().getEdges()) {

            V v1 = getAVertex(e);
            V v2 = getGraph().getOpposite(v1, e);

            Point2D p1 = transform(v1);
            Point2D p2 = transform(v2);
            if (p1 == null || p2 == null)
                continue;
            double vx = p1.getX() - p2.getX();
            double vy = p1.getY() - p2.getY();
            double len = Math.sqrt(vx * vx + vy * vy);

            SpringEdgeData<E> sed = getSpringDataEdge(e);
            if (sed == null) {
                continue;
            }
            double desiredLen = sed.length;

            // round from zero, if needed [zero would be Bad.].
            len = (len == 0) ? .0001 : len;

            double f = force_multiplier * (desiredLen - len) / len;

            f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

            // the actual movement distance 'dx' is the force multiplied by the
            // distance to go.
            double dx = f * vx;
            double dy = f * vy;
            SpringVertexData v1D, v2D;
            v1D = getSpringData(v1);
            v2D = getSpringData(v2);

            sed.f = f;

            v1D.edgedx += dx;
            v1D.edgedy += dy;
            v2D.edgedx += -dx;
            v2D.edgedy += -dy;
        }
    } catch (ConcurrentModificationException cme) {
        relaxEdges();
    }
}

From source file:grafix.telas.MolduraAreaDados.java

private Point2D converterPontoNoPlotParaMoldura_EixoLinear(final Point2D pontoPlot) {
    XYPlot plot = getPlot();/*from   ww  w.j ava2 s .c  o m*/
    ValueAxis vAxis = plot.getRangeAxis();
    ValueAxis dAxis = plot.getDomainAxis();
    double dX = dAxis.getUpperBound() - dAxis.getLowerBound();
    double dY = vAxis.getUpperBound() - vAxis.getLowerBound();
    double proporcaoX = this.getWidth() / dX;
    double proporcaoY = this.getHeight() / dY;
    double fracaoX = pontoPlot.getX() - dAxis.getLowerBound();
    double fracaoY = pontoPlot.getY() - vAxis.getLowerBound();
    return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (fracaoY * proporcaoY));
}

From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java

/**
 * Find way-points in a rectangular area defined by the given
 * {@link GeoPosition}s/*from ww  w .j  av  a 2  s  . c  o  m*/
 * 
 * @param topLeft the top left position
 * @param bottomRight the bottom right position
 * @param worldRect the bounding box in world pixel coordinates
 * @param converter the pixel converter
 * @param zoom the zoom level
 * 
 * @return the way-points in the area
 */
public Set<W> findWaypoints(GeoPosition topLeft, GeoPosition bottomRight, final Rectangle worldRect,
        final PixelConverter converter, final int zoom) {
    BoundingBox searchBox;
    try {
        searchBox = createSearchBB(topLeft, bottomRight);
        final BoundingBox verifyBox = searchBox;

        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox second) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);
                    int dx = (int) wpPixel.getX();
                    int dy = (int) wpPixel.getY();

                    worldRect.translate(-dx, -dy);
                    try {
                        Area area = wp.getMarker().getArea(zoom);
                        if (area != null) {
                            return area.containedIn(worldRect);
                        } else {
                            // something that has not been painted yet may
                            // not be selected
                            return false;
                        }
                    } finally {
                        worldRect.translate(dx, dy);
                    }
                } catch (IllegalGeoPositionException e) {
                    log.warn("Could not convert waypoint position to pixel", e);
                    // fall back to simple method
                    return verifyBox.covers(wp.getBoundingBox());
                }
            }

        });

        if (wps == null) {
            return new HashSet<W>();
        } else {
            return wps;
        }
    } catch (IllegalGeoPositionException e) {
        return new HashSet<W>();
    }
}

From source file:util.ModSpringLayout2.java

protected void calculateRepulsion() {
    try {//from w  ww  .  j a va2 s .co m
        for (V v : getGraph().getVertices()) {
            if (isLocked(v))
                continue;

            SpringVertexData svd = getSpringData(v);
            if (svd == null)
                continue;
            double dx = 0, dy = 0;

            for (V v2 : getGraph().getVertices()) {
                if (v == v2)
                    continue;
                Point2D p = transform(v);
                Point2D p2 = transform(v2);
                if (p == null || p2 == null)
                    continue;
                double vx = p.getX() - p2.getX();
                double vy = p.getY() - p2.getY();
                //                double distance = vx * vx + vy * vy;
                double distanceSq = p.distanceSq(p2);
                if (distanceSq == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distanceSq < repulsion_range) {// * repulsion_range) {
                    double factor = 1;
                    dx += factor * vx / distanceSq;//Math.pow(distance, 2);
                    dy += factor * vy / distanceSq;//Math.pow(distance, 2);
                }
            }
            double dlen = dx * dx + dy * dy;
            if (dlen > 0) {
                dlen = Math.sqrt(dlen) / 2;
                svd.repulsiondx += dx / dlen;
                svd.repulsiondy += dy / dlen;
            }
        }
    } catch (ConcurrentModificationException cme) {
        calculateRepulsion();
    }
}