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.ISOMLayout.java

private synchronized void adjustVertex(V v, Point2D tempXYD) {
    queue.clear();//ww w .  j  av a  2s.  com
    ISOMVertexData ivd = getISOMVertexData(v);
    ivd.distance = 0;
    ivd.visited = true;
    queue.add(v);
    V current;

    while (!queue.isEmpty()) {
        current = queue.remove(0);
        ISOMVertexData currData = getISOMVertexData(current);
        Point2D currXYData = transform(current);

        double dx = tempXYD.getX() - currXYData.getX();
        double dy = tempXYD.getY() - currXYData.getY();
        double factor = adaption / Math.pow(2, currData.distance);

        currXYData.setLocation(currXYData.getX() + (factor * dx), currXYData.getY() + (factor * dy));

        if (currData.distance < radius) {
            Collection<V> s = getGraph().getNeighbors(current);
            while (true) {
                try {
                    for (V child : s) {
                        ISOMVertexData childData = getISOMVertexData(child);
                        if (childData != null && !childData.visited) {
                            childData.visited = true;
                            childData.distance = currData.distance + 1;
                            queue.add(child);
                        }
                    }
                    break;
                } catch (ConcurrentModificationException cme) {
                }
            }
        }
    }
}

From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/** 
  * Iterates over Vertices, checking to see if x,y is contained in the
  * Vertex's Shape. If (x,y) is contained in more than one vertex, use
  * the vertex whose center is closest to the pick point.
  * @see edu.uci.ics.jung.visualization.picking.PickSupport#getVertex(double, double)
  *///from w w  w  . j a v  a2s. com
public V getVertex(Layout<V, E> layout, double x, double y) {

    V closest = null;
    double minDistance = Double.MAX_VALUE;
    Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW,
            new Point2D.Double(x, y));
    x = ip.getX();
    y = ip.getY();

    while (true) {
        try {
            for (V v : getFilteredVertices(layout)) {

                Shape shape = vv.getRenderContext().getVertexShapeTransformer().transform(v);
                // get the vertex location
                Point2D p = layout.transform(v);
                if (p == null)
                    continue;
                // transform the vertex location to screen coords
                p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p);

                double ox = x - p.getX();
                double oy = y - p.getY();

                if (shape.contains(ox, oy)) {

                    if (style == Style.LOWEST) {
                        // return the first match
                        return v;
                    } else if (style == Style.HIGHEST) {
                        // will return the last match
                        closest = v;
                    } else {

                        // return the vertex closest to the
                        // center of a vertex shape
                        Rectangle2D bounds = shape.getBounds2D();
                        double dx = bounds.getCenterX() - ox;
                        double dy = bounds.getCenterY() - oy;
                        double dist = dx * dx + dy * dy;
                        if (dist < minDistance) {
                            minDistance = dist;
                            closest = v;
                        }
                    }
                }
            }
            break;
        } catch (ConcurrentModificationException cme) {
        }
    }
    return closest;
}

From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Returns an edge whose shape intersects the 'pickArea' footprint of the passed
 * x,y, coordinates./* ww w  .  j  av a2  s . com*/
 */
public E getEdge(Layout<V, E> layout, double x, double y) {

    Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW,
            new Point2D.Double(x, y));
    x = ip.getX();
    y = ip.getY();

    // as a Line has no area, we can't always use edgeshape.contains(point) so we
    // make a small rectangular pickArea around the point and check if the
    // edgeshape.intersects(pickArea)
    Rectangle2D pickArea = new Rectangle2D.Float((float) x - pickSize / 2, (float) y - pickSize / 2, pickSize,
            pickSize);
    E closest = null;
    double minDistance = Double.MAX_VALUE;
    while (true) {
        try {
            for (E e : getFilteredEdges(layout)) {

                Shape edgeShape = getTransformedEdgeShape(layout, e);
                if (edgeShape == null)
                    continue;

                // because of the transform, the edgeShape is now a GeneralPath
                // see if this edge is the closest of any that intersect
                if (edgeShape.intersects(pickArea)) {
                    float cx = 0;
                    float cy = 0;
                    float[] f = new float[6];
                    PathIterator pi = new GeneralPath(edgeShape).getPathIterator(null);
                    if (pi.isDone() == false) {
                        pi.next();
                        pi.currentSegment(f);
                        cx = f[0];
                        cy = f[1];
                        if (pi.isDone() == false) {
                            pi.currentSegment(f);
                            cx = f[0];
                            cy = f[1];
                        }
                    }
                    float dx = (float) (cx - x);
                    float dy = (float) (cy - y);
                    float dist = dx * dx + dy * dy;
                    if (dist < minDistance) {
                        minDistance = dist;
                        closest = e;
                    }
                }
            }
            break;
        } catch (ConcurrentModificationException cme) {
        }
    }
    return closest;
}

From source file:org.jcurl.demo.tactics.old.MenuView.java

private void zoom(final Point2D center, final double ratio, final int dt) {
    if (getModel() == null)
        return;/*from  w  w  w. j a  v a  2s  .co  m*/
    final RectangularShape src = getModel().getZoom();
    if (log.isDebugEnabled())
        log.debug(src);
    final double w = src.getWidth() * ratio;
    final double h = src.getHeight() * ratio;
    final double cx, cy;
    if (center == null) {
        cx = src.getCenterX();
        cy = src.getCenterY();
    } else {
        cx = center.getX();
        cy = center.getY();
    }
    zoom(new Rectangle2D.Double(cx - w / 2, cy - h / 2, Math.abs(w), Math.abs(h)), dt);
}

From source file:org.kalypso.model.wspm.tuhh.ui.chart.layers.PointMarkerLayer.java

@Override
public EditInfo drag(final Point newPos, final EditInfo dragStartData) {
    final IProfile profil = getProfil();

    final Point2D numericPos = ProfilLayerUtils.toNumeric(getCoordinateMapper(), newPos);

    final EmptyRectangleFigure startHoverFigure = (EmptyRectangleFigure) dragStartData.getHoverFigure();
    final Rectangle startRectangle = startHoverFigure.getRectangle();

    final IProfileRecord point = ProfileVisitors.findNearestPoint(profil, numericPos.getX());
    if (point == null)
        return null;

    final Double x = point.getBreite();
    if (!Doubles.isFinite(x))
        return null;

    final Point screen = getCoordinateMapper().numericToScreen(x, 0.0);

    final Rectangle hoverRect = new Rectangle(screen.x - 5, startRectangle.y, 10, startRectangle.height);

    final EmptyRectangleFigure hoverFigure = new EmptyRectangleFigure();
    hoverFigure.setStyle(getLineStyleHover());
    hoverFigure.setRectangle(hoverRect);

    return new EditInfo(this, null, hoverFigure, dragStartData.getData(), getTooltipInfo(point),
            dragStartData.getPosition());
}

From source file:lu.lippmann.cdb.graph.GenericGraphViewImpl.java

/**
 * {@inheritDoc}// www  .  ja v a 2 s  .  co m
 */
@Override
public void fitGraphToSubPanel(double panelWidth, double panelHeigth, final double ratioPanel) {
    int w = 10;
    int h = 10;

    vv.setPreferredSize(new Dimension((int) panelWidth, (int) panelHeigth));
    vv.setMinimumSize(new Dimension((int) panelWidth, (int) panelHeigth));
    vv.setMaximumSize(new Dimension((int) panelWidth, (int) panelHeigth));

    double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE,
            maxY = Integer.MIN_VALUE;

    final MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer()
            .getTransformer(Layer.VIEW);
    //final MutableTransformer layoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);

    //Reset graph layout (zoom level & translation)
    resetLayout();

    final Graph<V, E> graph = vv.getModel().getGraphLayout().getGraph();

    if (graph.getVertices().size() == 0) {
        return;
    } else if (graph.getVertices().size() == 1) {
        final V n = graph.getVertices().iterator().next();
        final Point2D point = vv.getModel().getGraphLayout().transform(n); //center of the node
        minX = point.getX();
        maxX = point.getX();
        minY = point.getY();
        maxY = point.getY();
    } else {
        for (final V n : graph.getVertices()) {
            final Point2D point = vv.getModel().getGraphLayout().transform(n); //center of the node

            double nodeMinX = point.getX() - w / 2;
            double nodeMaxX = point.getX() + w / 2;
            double nodeMinY = point.getY() - h / 2;
            double nodeMaxY = point.getY() + h / 2;

            if (nodeMinX < minX) {
                minX = nodeMinX;
            }
            if (nodeMaxX > maxX) {
                maxX = nodeMaxX;
            }
            if (nodeMinY < minY) {
                minY = nodeMinY;
            }
            if (nodeMaxY > maxY) {
                maxY = nodeMaxY;
            }
        }
    }

    final int graphWidth = (int) (maxX - minX);
    final int graphHeigth = (int) (maxY - minY);

    //System.out.println("Graph heigth : " + graphHeigth);
    //System.out.println("Graph graphWidth : " + graphWidth);

    final double scale1 = ratioPanel / 100.0d * panelWidth / graphWidth;
    final double scale2 = panelHeigth / graphHeigth;

    final double ratio = Math.min(Math.min(scale1, scale2), 1.0f); //offset margin
    //final double ratio = Math.min(scale1,scale2); //offset margin

    //System.out.println("Ratio used : " + ratio);

    viewTransformer.scale(ratio, ratio, new Point2D.Double());
    viewTransformer.translate(((panelWidth * ratioPanel / 100.0f - graphWidth * ratio) / 2.0f) / ratio - minX,
            ((panelHeigth - graphHeigth * ratio) / 2.0f) / ratio - minY);
}

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

private void processWaypoint(W w, int minX, int minY, int width, int height, PixelConverter converter, int zoom,
        Graphics2D g) {/*from w w  w . j  a  va  2s.  c o m*/
    try {
        Point2D point = converter.geoToPixel(w.getPosition(), zoom);
        int x = (int) (point.getX() - minX);
        int y = (int) (point.getY() - minY);
        PixelConverter converterWrapper = new TranslationPixelConverterDecorator(converter, (int) point.getX(),
                (int) point.getY());
        g.translate(x, y);
        Rectangle gBounds = new Rectangle(minX - (int) point.getX(), minY - (int) point.getY(), width, height);
        renderer.paintWaypoint(g, converterWrapper, zoom, w, gBounds);
        g.translate(-x, -y);
    } catch (IllegalGeoPositionException e) {
        // waypoint not in map bounds or position invalid
        // log.warn("Error painting waypoint", e);
    }
}

From source file:org.opensha.commons.data.function.EvenlyDiscretizedFunc.java

/**
 *
 * @return value of each point in the function in String format
 *///www  .  ja va 2s.c o m
public String getMetadataString() {
    StringBuffer b = new StringBuffer();
    Iterator<Point2D> it2 = this.iterator();

    while (it2.hasNext()) {

        Point2D point = (Point2D) it2.next();
        double x = point.getX();
        double y = point.getY();
        b.append((float) x + "\t  " + (float) y + '\n');
    }
    return b.toString();
}

From source file:util.ModSpringLayout1.java

protected void relaxEdges() {
    try {/*from w  ww  .  j  a  v  a2 s .c  om*/
        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 = getSpringEdgeData(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 = getSpringVertexData(v1);
            v2D = getSpringVertexData(v2);

            sed.f = f;

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

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

/**
 * Draws the pointer./*from www. j av a 2  s .  co m*/
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
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);
}