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:at.knowcenter.wag.egov.egiz.pdf.operator.path.construction.LineTo.java

@Override
public void process(PDFOperator operator, List<COSBase> operands) throws IOException {
    try {//from  w w w.  j  a v  a 2s  .c om
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x = (COSNumber) operands.get(0);
        COSNumber y = (COSNumber) operands.get(1);
        Point2D p = transform(x.doubleValue(), y.doubleValue());

        pdfPage.getCurrentPath().lineTo((float) p.getX(), (float) p.getY());

        if (log.isTraceEnabled()) {
            log.trace("Adding line to x:" + p.getX() + ",y:" + p.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'l'.", e);
    }
}

From source file:at.knowcenter.wag.egov.egiz.pdf.operator.path.construction.MoveTo.java

@Override
public void process(PDFOperator operator, List<COSBase> operands) throws IOException {
    try {/*w  w  w .  j  av a  2s.c om*/
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x = (COSNumber) operands.get(0);
        COSNumber y = (COSNumber) operands.get(1);
        Point2D p = transform(x.doubleValue(), y.doubleValue());

        pdfPage.getCurrentPath().moveTo((float) p.getX(), (float) p.getY());

        if (log.isTraceEnabled()) {
            log.trace("Moving current path to x:" + p.getX() + ",y:" + p.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'm'.", e);
    }
}

From source file:org.opennms.features.vaadin.topology.jung.BalloonLayoutAlgorithm.java

public void updateLayout(GraphContainer graph) {

    Graph g = new Graph(graph);

    int szl = g.getSemanticZoomLevel();

    Vertex rootItem = g.getDisplayVertex(g.getVertexByItemId(m_rootItemId), szl);

    Tree<Vertex, Edge> tree = new OrderedKAryTree<Vertex, Edge>(50);

    Queue<Vertex> q = new LinkedList<Vertex>();
    Set<Vertex> found = new HashSet<Vertex>();

    q.add(rootItem);//from  ww  w .  j  av  a 2 s . c o  m

    tree.addVertex(rootItem);

    Vertex v;
    while ((v = q.poll()) != null) {
        List<Edge> edges = g.getEdgesForVertex(v, szl);
        for (Edge e : edges) {
            Vertex neighbor = e.getSource() != v ? e.getSource() : e.getTarget();
            tree.addEdge(e, v, neighbor);
            if (!found.contains(neighbor)) {
                q.add(neighbor);
            }
        }
    }

    BalloonLayout<Vertex, Edge> layout = new BalloonLayout<Vertex, Edge>(tree);
    layout.setInitializer(new Transformer<Vertex, Point2D>() {
        public Point2D transform(Vertex v) {
            return new Point(v.getX(), v.getY());
        }
    });

    for (Vertex vertex : g.getVertices(szl)) {
        layout.lock(vertex, vertex.isLocked());
    }

    layout.setSize(new Dimension(750, 750));

    List<Vertex> vertices = g.getVertices(szl);
    for (Vertex vertex : vertices) {
        Point2D point = layout.transform(v);
        vertex.setX((int) point.getX());
        vertex.setY((int) point.getY());
    }

}

From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.operator.path.construction.LineTo.java

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    try {//from   ww w . jav a  2s .c  o m
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x = (COSNumber) operands.get(0);
        COSNumber y = (COSNumber) operands.get(1);
        Point2D p = transform(x.doubleValue(), y.doubleValue());

        pdfPage.getCurrentPath().lineTo((float) p.getX(), (float) p.getY());

        if (log.isTraceEnabled()) {
            log.trace("Adding line to x:" + p.getX() + ",y:" + p.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'l'.", e);
    }
}

From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.operator.path.construction.MoveTo.java

public void process(Operator operator, List<COSBase> operands) throws IOException {
    try {/*from   www. ja  v  a2s.  co m*/
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x = (COSNumber) operands.get(0);
        COSNumber y = (COSNumber) operands.get(1);
        Point2D p = transform(x.doubleValue(), y.doubleValue());

        pdfPage.getCurrentPath().moveTo((float) p.getX(), (float) p.getY());

        if (log.isTraceEnabled()) {
            log.trace("Moving current path to x:" + p.getX() + ",y:" + p.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'm'.", e);
    }
}

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

/**
 * /*  w  w w.  ja  v  a 2 s .  c  o  m*/
 * @param layout
 * @param picked
 */
public static Layout<CNode, CEdge> reorganize(Layout<CNode, CEdge> layout, Set<CNode> picked) {

    Layout<CNode, CEdge> subLayout = null;

    //create map that copy the transformer of existing layout
    final HashMap<CNode, CPoint> mapTransform1 = new LinkedHashMap<CNode, CPoint>();
    for (CNode v : layout.getGraph().getVertices()) {
        final Point2D tmp = layout.transform(v);
        mapTransform1.put(v, new CPoint(tmp.getX(), tmp.getY()));
    }
    //

    final Graph<CNode, CEdge> graph = layout.getGraph();

    final AggregateLayout<CNode, CEdge> clusteringLayout = new AggregateLayout<CNode, CEdge>(layout);

    // put the picked vertices into a new sublayout

    //final Set<CNode> picked = vv.getPickedVertexState().getPicked();
    if (picked != null && picked.size() >= 1) {

        final Point2D initCenter = GraphUtil.getCenter(picked, layout);

        final Graph<CNode, CEdge> subGraph = new DirectedSparseGraph<CNode, CEdge>();
        try {
            for (CNode vertex : picked) {
                subGraph.addVertex(vertex);
                final Collection<CEdge> incidentEdges = graph.getIncidentEdges(vertex);
                if (incidentEdges != null) {
                    for (final CEdge edge : incidentEdges) {
                        final Pair<CNode> endpoints = graph.getEndpoints(edge);
                        if (picked.containsAll(endpoints)) {
                            subGraph.addEdge(edge, endpoints.getFirst(), endpoints.getSecond());
                        }
                    }
                }
            }

            subLayout = buildMinimumSpanningForestLayout(subGraph);

            subLayout.setInitializer(layout);

            if (!(subLayout instanceof TreeLayout)) {
                subLayout.setSize(clusteringLayout.getSize());
            }

            final Point2D subGraphCenter = GraphUtil.getCenter(picked, subLayout);
            final Point2D subLayoutCenter = new Point2D.Double(subLayout.getSize().getWidth() / 2,
                    subLayout.getSize().getHeight() / 2);
            //System.out.println("Initial init center : " + initCenter);
            initCenter.setLocation(initCenter.getX() + (subLayoutCenter.getX() - subGraphCenter.getX()),
                    initCenter.getY() + (subLayoutCenter.getY() - subGraphCenter.getY()));
            //System.out.println("Corrected init center : " + initCenter);

            clusteringLayout.put(subLayout, initCenter);

            //create map that copy the transformer of new layout
            final HashMap<CNode, CPoint> mapTransform2 = new LinkedHashMap<CNode, CPoint>();
            for (CNode v : layout.getGraph().getVertices()) {
                final Point2D tmp = clusteringLayout.transform(v);
                mapTransform2.put(v, new CPoint(tmp.getX(), tmp.getY()));
            }
            //
            /** save the new layout and historize it !! */
            ((GraphWithOperations) layout.getGraph()).changeLayout(mapTransform1, mapTransform2);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return subLayout;
}

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

protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) {

    int childCount = kids.size();
    if (childCount == 0)
        return;//from  w ww  .  ja va2s .  co m
    // handle the 1-child case with 0 limit on angle.
    double angle = Math.max(0, Math.PI / 2 * (1 - 2.0 / childCount));
    double childRadius = parentRadius * Math.cos(angle) / (1 + Math.cos(angle));
    double radius = parentRadius - childRadius;

    double rand = Math.random();

    for (int i = 0; i < childCount; i++) {
        V child = kids.get(i);
        double theta = i * 2 * Math.PI / childCount + rand;
        radii.put(child, childRadius);

        PolarPoint pp = new PolarPoint(theta, radius);
        polarLocations.put(child, pp);

        Point2D p = PolarPoint.polarToCartesian(pp);
        p.setLocation(p.getX() + parentLocation.getX(), p.getY() + parentLocation.getY());
        locations.put(child, p);
        setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius);
    }
}

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

@Override
public void setLocation(V v, Point2D location) {
    Point2D c = getCenter(v);//from w ww.  j ava 2s  . com
    Point2D pv = new Point2D.Double(location.getX() - c.getX(), location.getY() - c.getY());
    PolarPoint newLocation = PolarPoint.cartesianToPolar(pv);
    polarLocations.get(v).setLocation(newLocation);

    Point2D center = getCenter(v);
    pv.setLocation(pv.getX() + center.getX(), pv.getY() + center.getY());
    locations.put(v, pv);
}

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

@Override
public Paint transform(ValueEdge ve) {
    Layout<HitVertex, ValueEdge> layout = vv.getGraphLayout();
    BlastGraph<HitVertex, ValueEdge> graph = (BlastGraph<HitVertex, ValueEdge>) layout.getGraph();
    Pair<HitVertex> p = graph.getEndpoints(ve);
    HitVertex b = p.getFirst();/*  ww w.j  a va2 s .  c  o m*/
    HitVertex f = p.getSecond();

    BasicStroke stroke = (BasicStroke) strokeTransformer.transform(ve);
    float lineWith = stroke.getLineWidth();

    Point2D pb = transformer.transform(layout.transform(b));
    Point2D pf = transformer.transform(layout.transform(f));

    float xB = (float) pb.getX();
    float yB = (float) pb.getY();
    float xF = (float) pf.getX();
    float yF = (float) pf.getY();

    return null;
}

From source file:joshua.ui.tree_visualizer.DerivationTreeTransformer.java

public Point2D transform(Node n) {
    double x, y;//from ww w  .  jav a2s  .c  om
    Point2D t = treeLayout.transform(n);
    if (n.isSource()) {
        x = /*treeLayout.transform(root).getX() +*/ (t.getX() - treeLayout.transform(sourceRoot).getX()
                + treeLayout.transform(root).getX());
        y = Y_DIST * (distanceToLeaf(n) + 1);
    } else {
        x = t.getX();
        y = Y_DIST * (-1) * distanceToLeaf(n);
    }
    if (isAnchored) {
        x += anchorPoint.getX();
        y += anchorPoint.getY();
    }
    return new Point2D.Double(x, y + Y_DIST * (1 + distanceToLeaf(root)));
}