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:ca.sqlpower.dao.session.Point2DConverter.java

public String convertToSimpleType(Point2D convertFrom, Object... additionalInfo) {
    StringBuilder result = new StringBuilder();

    result.append(convertFrom.getX());
    result.append(DELIMITER);//  www.  ja va  2  s .c  o  m
    result.append(convertFrom.getY());

    return result.toString();
}

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

/**
 * // www .ja  v a 2 s  .  co  m
 * @param layout
 * @return
 */
public static Point2D getCenter(Set<CNode> picked, Layout<CNode, CEdge> layout) {
    double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE,
            maxY = Integer.MIN_VALUE;

    for (final CNode n : picked) {
        final Point2D point = layout.transform(n); // center of the node
        if (point.getX() < minX) {
            minX = point.getX();
        }
        if (point.getX() > maxX) {
            maxX = point.getX();
        }
        if (point.getY() < minY) {
            minY = point.getY();
        }
        if (point.getY() > maxY) {
            maxY = point.getY();
        }
    }

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

    return new Point2D.Double(minX + graphWidth / 2.0f, minY + graphHeigth / 2.0f);
}

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

public void updateLayout(GraphContainer graph) {

    Graph g = new Graph(graph);

    int szl = g.getSemanticZoomLevel();

    DirectedSparseGraph<Vertex, Edge> jungGraph = new DirectedSparseGraph<Vertex, Edge>();

    List<Vertex> vertices = g.getVertices(szl);

    for (Vertex v : vertices) {
        jungGraph.addVertex(v);//  www .ja v  a 2s.  c om
    }

    List<Edge> edges = g.getEdges(szl);

    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource(), e.getTarget());
    }

    DelegateForest<Vertex, Edge> forest = new DelegateForest<Vertex, Edge>(jungGraph);

    TreeLayout<Vertex, Edge> layout = new TreeLayout<Vertex, Edge>(forest);
    layout.setInitializer(new Transformer<Vertex, Point2D>() {
        public Point2D transform(Vertex v) {
            return new Point(v.getX(), v.getY());
        }
    });
    layout.setSize(new Dimension(750, 750));

    for (Vertex v : vertices) {
        Point2D point = layout.transform(v);
        v.setX((int) point.getX());
        v.setY((int) point.getY());
    }
}

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

public void updateLayout(GraphContainer graph) {

    Graph g = new Graph(graph);

    int szl = g.getSemanticZoomLevel();

    DirectedSparseGraph<Vertex, Edge> jungGraph = new DirectedSparseGraph<Vertex, Edge>();

    List<Vertex> vertices = g.getVertices(szl);

    for (Vertex v : vertices) {
        jungGraph.addVertex(v);/* w  ww .  j a  v a2 s. c  o m*/
    }

    List<Edge> edges = g.getEdges(szl);

    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource(), e.getTarget());
    }

    DelegateForest<Vertex, Edge> forest = new DelegateForest<Vertex, Edge>(jungGraph);

    RadialTreeLayout<Vertex, Edge> layout = new RadialTreeLayout<Vertex, Edge>(forest);
    layout.setInitializer(new Transformer<Vertex, Point2D>() {
        public Point2D transform(Vertex v) {
            return new Point(v.getX(), v.getY());
        }
    });
    layout.setSize(new Dimension(750, 750));

    for (Vertex v : vertices) {
        Point2D point = layout.transform(v);
        v.setX((int) point.getX());
        v.setY((int) point.getY());
    }
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.MoveTo.java

/**
 * process : m : Begin new subpath.//www.  j a  v a2  s.  co  m
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws java.io.IOException If there is an error processing the operator.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    try {
        GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;
        COSNumber x = (COSNumber) arguments.get(0);
        COSNumber y = (COSNumber) arguments.get(1);
        Point2D pos = drawer.transformedPoint(x.floatValue(), y.floatValue());
        drawer.getLinePath().moveTo((float) pos.getX(), (float) pos.getY());
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

From source file:org.apache.pdfbox.util.operator.pagedrawer.MoveTo.java

/**
 * process : m : Begin new subpath./*www.j  ava  2s.c  om*/
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws IOException If there is an error processing the operator.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    try {
        PageDrawer drawer = (PageDrawer) context;
        COSNumber x = (COSNumber) arguments.get(0);
        COSNumber y = (COSNumber) arguments.get(1);
        Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue());
        drawer.getLinePath().moveTo((float) pos.getX(), (float) pos.getY());
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

From source file:pdfimport.pdfbox.operators.MoveTo.java

/**
 * process : m : Begin new subpath./*from  w w w  .  j  a  v  a 2s.  c o m*/
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws IOException If there is an error processing the operator.
 */
@Override
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    try {
        PageDrawer drawer = (PageDrawer) context;
        COSNumber x = (COSNumber) arguments.get(0);
        COSNumber y = (COSNumber) arguments.get(1);
        Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue());
        drawer.getLinePath().moveTo((float) pos.getX(), (float) pos.getY());
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

From source file:org.pathvisio.pathlayout.layouts.Balloon.java

/**
 * create a new Balloon layout./*  w w  w  .ja va2  s .c  om*/
 * @param swingEngine The PathVisio swing engine
 * @param selection Boolean whether to use currently selected nodes or complete pathway
 */
public Balloon(SwingEngine swingEngine, boolean selection) {
    super(swingEngine, selection);

    createDSMultigraph();
    Forest<String, String> forest = new DelegateForest<String, String>();
    List<PathwayElement> elements = pwy.getDataObjects();

    for (PathwayElement element : elements) {
        if (element.getObjectType().equals(ObjectType.LINE)) {
            if (!forest.containsVertex(element.getStartGraphRef())) {
                forest.addVertex(element.getStartGraphRef());
            }
            if (!forest.containsEdge(element.getEndGraphRef())) {
                forest.addVertex(element.getEndGraphRef());
            }
            forest.addEdge(element.getGraphId(), element.getStartGraphRef(), element.getEndGraphRef());
        }
    }
    BalloonLayout.DEFAULT_DISTX = 200;
    BalloonLayout.DEFAULT_DISTY = 200;
    l = new BalloonLayout<String, String>(forest);
    setDimension((Layout<String, String>) l);

    for (PathwayElement element : elements) {
        if (element.getObjectType().equals(ObjectType.DATANODE)) {
            Point2D p = new Point2D.Double(element.getMCenterX(), element.getMCenterY());
            l.setLocation(element.getGraphId(), p);
        }
    }
    l.initialize();

    for (String v : l.getGraph().getVertices()) {
        Point2D center = l.transform(v);

        double x = center.getX();
        double y = center.getY();
        PathwayElement e = pwy.getElementById(v);
        x = x + e.getMWidth() / 2 * 5;
        y = y + e.getMHeight() / 2 * 5;
        e.setMCenterX(x);
        e.setMCenterY(y);
    }
    //re-draw the lines
    drawLines();
}

From source file:RollingText.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "Java Source and Support.";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//w w  w. j  av a2s  . c  om

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:algorithms.quality.JndRegionSize.java

private double computeArea(List<Point2D> poly, Point2D center) {
    double sum = 0;
    for (int i = 0; i < poly.size(); i++) {
        Point2D p0 = poly.get(i);
        Point2D p1 = poly.get((i + 1) % poly.size());

        sum = sum + p0.getX() * p1.getY() - p0.getY() * p1.getX();
    }/*from   w w w  .j  a  va  2 s  .co  m*/

    double area = Math.abs(sum / 2);
    return area;
}