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:org.eclipse.titanium.graph.gui.layouts.BaseHierarchicalLayout.java

/**
 * Implementation of max distance This distance is defined as the maximum of
 * the distances to the predecessor nodes
 * /*from   ww w .  j a  v  a 2  s .  c  om*/
 * @param pos
 *            : The suspected position of the node
 * @param neighbours
 *            : The list of used neighbour nodes (predecessors, or
 *            successors)
 * @return The distance
 */
protected double getMaxDistance(final double pos, final Collection<V> neighbours) {
    double distance = Double.NEGATIVE_INFINITY;

    for (final V v : neighbours) {
        final Point2D pv = places.get(v);
        if (pv == null) {
            continue;
        }

        final double actDist = Math.abs(pv.getX() - pos);
        if (actDist > distance) {
            distance = actDist;
        }
    }
    return distance;
}

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

protected void calculateRepulsion() {
    try {/*from  ww w.jav  a  2s .c om*/
        for (V v : getGraph().getVertices()) {
            if (isLocked(v))
                continue;

            SpringVertexData svd = springVertexData.get(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 distanceSq = p.distanceSq(p2);
                if (distanceSq == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distanceSq < repulsion_range_sq) {
                    double factor = 1;
                    dx += factor * vx / distanceSq;
                    dy += factor * vy / distanceSq;
                }
            }
            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:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java

protected Shape getOuterWindow(Rectangle2D frame) {
    double radiusMargin = 0.02;
    double angleMargin = 1.5;
    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius - radiusMargin,
            this.innerRadius - radiusMargin);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius + radiusMargin,
            this.outerRadius + radiusMargin);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - angleMargin, this.extent + 2 * angleMargin,
            Arc2D.OPEN);// w w w .java  2 s .  c o m
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + angleMargin + this.extent,
            -this.extent - 2 * angleMargin, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}

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

protected void calcRepulsion(V v1) {
    FRVertexData fvd1 = getFRData(v1);/*  w w w . ja va 2s.  c  o  m*/
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (V v2 : getGraph().getVertices()) {
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                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 = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }
                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

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

protected void calcRepulsion(V v1) {
    Point2D fvd1 = frVertexData.get(v1);
    if (fvd1 == null)
        return;//from   www .  j  a v a2  s.  c o  m
    fvd1.setLocation(0, 0);
    boolean v1_locked = isLocked(v1);

    try {
        for (V v2 : getGraph().getVertices()) {

            boolean v2_locked = isLocked(v2);
            if (v1_locked && v2_locked)
                continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

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

                double force = (repulsion_constant * repulsion_constant);// / deltaLength;

                double forceOverDeltaLength = force / deltaLength;

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

                if (v2_locked) {
                    // double the offset for v1, as v2 will not be moving in
                    // the opposite direction
                    fvd1.setLocation(fvd1.getX() + 2 * xDelta * forceOverDeltaLength,
                            fvd1.getY() + 2 * yDelta * forceOverDeltaLength);
                } else {
                    fvd1.setLocation(fvd1.getX() + xDelta * forceOverDeltaLength,
                            fvd1.getY() + yDelta * forceOverDeltaLength);
                }
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

From source file:StrokeChooserPanel.java

/**
 * Draws a line using the sample stroke.
 *
 * @param g  the graphics device./*  w  ww.  j  av  a  2s . c o m*/
 */
public void paintComponent(final Graphics g) {

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final Dimension size = getSize();
    final Insets insets = getInsets();
    final double xx = insets.left;
    final double yy = insets.top;
    final double ww = size.getWidth() - insets.left - insets.right;
    final double hh = size.getHeight() - insets.top - insets.bottom;

    // calculate point one
    final Point2D one = new Point2D.Double(xx + 6, yy + hh / 2);
    // calculate point two
    final Point2D two = new Point2D.Double(xx + ww - 6, yy + hh / 2);
    // draw a circle at point one
    final Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10);
    final Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10);

    // draw a circle at point two
    g2.draw(circle1);
    g2.fill(circle1);
    g2.draw(circle2);
    g2.fill(circle2);

    // draw a line connecting the points
    final Line2D line = new Line2D.Double(one, two);
    if (this.stroke != null) {
        g2.setStroke(this.stroke);
        g2.draw(line);
    }

}

From source file:Visualizer.FRWeightedLayout.java

protected void calcRepulsion(Functionality.Node v1) {
    FRVertexData fvd1 = getFRData(v1);/* w w w.  java  2  s.  co m*/
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (Functionality.Node v2 : getGraph().getVertices()) {

            //                if (isLocked(v2)) continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

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

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

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

                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java

private void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item,
        Rectangle2D bar, boolean negative) {

    XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
    if (generator == null)
        return;//from  w ww.ja va2  s . c o  m

    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return; // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    } else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, orientation);

    TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}

From source file:net.panthema.BispanningGame.MyEditingGraphMousePlugin.java

/**
 * If the mouse is pressed in an empty area, create a new vertex there. If
 * the mouse is pressed on an existing vertex, prepare to create an edge
 * from that vertex to another//from   w  ww  .ja  va 2  s .c o m
 */
@SuppressWarnings("unchecked")
public void mousePressed(MouseEvent e) {
    if (checkModifiers(e)) {
        final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
        final Point2D p = e.getPoint();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Graph<V, E> graph = vv.getModel().getGraphLayout().getGraph();

            final V vertex = pickSupport.getVertex(vv.getModel().getGraphLayout(), p.getX(), p.getY());
            if (vertex != null) { // get ready to make an edge
                startVertex = vertex;
                down = e.getPoint();
                transformEdgeShape(down, down);
                vv.addPostRenderPaintable(edgePaintable);
            } else { // make a new vertex
                V newVertex = vertexFactory.create();
                Layout<V, E> layout = vv.getModel().getGraphLayout();
                graph.addVertex(newVertex);
                layout.setLocation(newVertex,
                        vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint()));

                if (graph instanceof MyGraph)
                    ((MyGraph) graph).graphChanged();
            }
        }
        vv.repaint();
    }
}

From source file:Visualizer.SpringLayoutWeighted.java

protected void relaxEdges() {
    try {/*from w  w w  .j  a va2 s .  c  o m*/
        for (Functionality.Edge e : getGraph().getEdges()) {
            Pair<Functionality.Node> endpoints = getGraph().getEndpoints(e);
            Functionality.Node v1 = endpoints.getFirst();
            Functionality.Node v2 = endpoints.getSecond();

            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);

            double desiredLen = lengthFunction.transform(e);

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

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

            if (DataModule.displayedGraph.edgeIsDotted(v1, v2)) {
                f = f / 2.5;
            }

            if (DataModule.displayedGraph.edgeIsNormal(v1, v2)) {
                f = f / 1.7;
            }

            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 = springVertexData.get(v1);
            v2D = springVertexData.get(v2);

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