Example usage for java.awt.geom Point2D getY

List of usage examples for java.awt.geom Point2D getY

Introduction

In this page you can find the example usage for java.awt.geom Point2D getY.

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

From source file:org.squidy.designer.util.ImageUtils.java

public static Shape getShapeOfImage(BufferedImage image) {
    // Get the data
    Raster data = image.getData();
    ////from   ww w.  j  a  v  a 2s.co  m
    //      System.out.println("num of bands = " + data.getNumBands());
    // The colour of the pixel looking at
    // Shoulld have length of 4 (RGBA)
    int[] lookAt = null;
    // The map of all the points
    Point2D[][] pointMap = new Point2D[data.getWidth()][data.getHeight()];
    // The from point
    Point2D from = null;
    // The general path
    GeneralPath path = new GeneralPath();

    // Go round height
    for (int y = 0; y < data.getHeight(); y++) {
        // Go round width
        for (int x = 0; x < data.getWidth(); x++) {
            // Get the colour
            lookAt = data.getPixel(x, y, lookAt);
            // The alpha
            int a = lookAt[3];
            // If > then 0
            if (a > 0) {
                // Output 1
                //System.out.print(1);
                // Save point
                pointMap[x][y] = new Point2D.Double(x, y);

                if (from == null) {
                    from = pointMap[x][y];
                }
            } // 0
            else {
                // Output 0
                //System.out.print(0);
                // Nothing her
                pointMap[x][y] = null;
            }
        }
        // New line
        //System.out.println();
    }

    // Move it to the from
    if (from != null) {
        path.moveTo(from.getX(), from.getY());
        /*
         * Make the shape
         */
        // Go round height
        for (int y = 0; y < data.getHeight(); y++) {
            // Go round width
            for (int x = 0; x < data.getWidth(); x++) {
                // If the point is not null
                if (pointMap[x][y] != null) {
                    // Draw a line to
                    path.append(new Rectangle2D.Double(pointMap[x][y].getX(), pointMap[x][y].getY(), 1, 1),
                            true);
                    //               path.lineTo(pointMap[x][y].getX(), pointMap[x][y].getY());
                }
            }

        }
        path.closePath();
        // TODO: Put in the middle
        return path;
    }
    return null;
}

From source file:vteaexploration.plotgatetools.gates.PolygonGate.java

@Override
public Path2D createPath2D() {

    Point2D p;
    Path2D.Double polygon = new Path2D.Double();

    ListIterator<Point2D.Double> itr = vertices.listIterator();

    p = (Point2D) vertices.get(0);
    polygon.moveTo(p.getX(), p.getY());
    while (itr.hasNext()) {
        p = (Point2D) itr.next();
        polygon.lineTo(p.getX(), p.getY());
    }// w  w  w  . ja  va2  s.c o m
    polygon.closePath();
    return polygon;

}

From source file:org.kuali.student.repository.viewer.GitGraphTransformer.java

private Point2D place(RevCommit commit, RevCommit parentCommit) {

    Point2D parentPlacement = findPlacement(parentCommit);

    if (parentPlacement == null) {

        parentPlacement = place(parentCommit);

    }//from   w  w w . jav  a2 s  .  co m

    Point2D.Double placement = new Point2D.Double(parentPlacement.getX(), parentPlacement.getY() + 10);

    while (this.pointToCommitsMap.containsKey(placement)) {
        // prevent placements on the same point

        placement = new Point2D.Double(placement.getX() + 10, placement.getY() + 10);

    }

    this.placedCommitsMap.put(commit, placement);
    this.pointToCommitsMap.put(placement, commit);

    return placement;

}

From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>.  Labels for vertices may
 * be supplied by <code>vs</code> (defaults to no labels if null), 
 * edge weights may be specified by <code>nev</code>
 * (defaults to weights of 1.0 if null), 
 * and vertex locations may be specified by <code>vld</code> (defaults
 * to no locations if null). //from ww  w.  j ava 2  s  .co m
 */
@SuppressWarnings("unchecked")
public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null)
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    writer.write("*Vertices " + graph.getVertexCount());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null)
                writer.write(" \"" + label + "\"");
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null)
                writer.write(" " + location.getX() + " " + location.getY());
        }
        if (shape != null) {
            writer.write(" " + shape.transform(currentVertex) + " x_fact 1");
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed)
        d_set.addAll(graph.getEdges());
    if (undirected)
        u_set.addAll(graph.getEdges());
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphEditMousePlugin.java

@SuppressWarnings("unchecked")
public void mouseReleased(MouseEvent e) {
    if (checkModifiers(e)) {
        editor.clearPath();/* w ww  . ja  va 2 s  .co m*/

        final VisualizationViewer<GraphNode, GraphLink> vv = (VisualizationViewer<GraphNode, GraphLink>) e
                .getSource();
        final Point2D p = e.getPoint();
        Layout<GraphNode, GraphLink> layout = vv.getModel().getGraphLayout();
        GraphElementAccessor<GraphNode, GraphLink> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            if (vertex != null && startVertex != null) {
                Graph<GraphNode, GraphLink> graph = vv.getGraphLayout().getGraph();

                GraphLink coGraphLink;
                if (edgeFactory instanceof LinkedLinesFactory) {
                    coGraphLink = ((LinkedLinesFactory) edgeFactory).createLinkedLine(startVertex, vertex);
                } else {
                    coGraphLink = edgeFactory.create();
                }

                SmartMapLine line = coGraphLink.getMapLine();
                if (line.getCodirectionalSign() == null)
                    line.setCodirectionalSign(new RoadSign());
                if (line.getOppositelySign() == null)
                    line.setOppositelySign(new RoadSign());

                GraphLink opGraphLink = new GraphLink(coGraphLink.getMapLine(),
                        coGraphLink.getMapLine().getOppositelySign());

                coGraphLink.setNeighbor(opGraphLink);
                opGraphLink.setNeighbor(coGraphLink);

                graph.addEdge(coGraphLink, startVertex, vertex, edgeIsDirected);
                graph.addEdge(opGraphLink, vertex, startVertex, edgeIsDirected);
                vv.repaint();
            }
        }
        startVertex = null;
        down = null;
        edgeIsDirected = EdgeType.UNDIRECTED;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);
    }
}

From source file:org.owasp.benchmark.score.report.Scatter.java

private void makeDataLabels(OverallResults or, XYPlot xyplot) {
    HashMap<Point2D, String> map = makePointList(or);
    for (Entry<Point2D, String> e : map.entrySet()) {
        if (e.getValue() != null) {
            Point2D p = e.getKey();
            String label = sort(e.getValue());
            XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
            annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            annotation.setPaint(Color.blue);
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }/*from w ww .j  av a  2  s  .  c  o m*/
    }
}

From source file:edu.uci.ics.jung.io.CustomPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>. Labels for vertices may be
 * supplied by <code>vs</code> (defaults to no labels if null), edge weights
 * may be specified by <code>nev</code> (defaults to weights of 1.0 if
 * null), and vertex locations may be specified by <code>vld</code>
 * (defaults to no locations if null)./*from   ww  w.  j av  a 2  s . c  o m*/
 */
public void save(MyGraph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null) {
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    }
    writer.write("*Colors " + graph.getLayoutParameters().getBackgroundColorRgb() + ","
            + graph.getLayoutParameters().getEdgeColorRgb());
    writer.newLine();
    writer.write(
            "*Vertices " + graph.getVertexCount() + "," + graph.getLayoutParameters().areNodeIconsAllowed());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null) {
                writer.write(" \"" + label + "\"");
            }
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null) {
                writer.write(" " + location.getX() + " " + location.getY() + " 0.0");
            }
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed) {
        d_set.addAll(graph.getEdges());
    }
    if (undirected) {
        u_set.addAll(graph.getEdges());
    }
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:inflor.core.gates.ui.PolygonGateAnnotation.java

@Override
public XYGateAnnotation updateVertex(Point2D v, double dx, double dy, double xHandleSize, double yHandleSize) {
    double[] x = getDomainPoints();
    double[] y = getRangePoints();
    double xMin = v.getX() - xHandleSize;
    double xMax = v.getX() + xHandleSize;
    double yMin = v.getY() - yHandleSize;
    double yMax = v.getY() + yHandleSize;
    for (int i = 0; i < x.length; i++) {
        if (xMin <= x[i] && x[i] <= xMax && yMin <= y[i] && y[i] <= yMax) {
            x[i] = x[i] + dx;/*  www  .ja  v a2 s .  c  om*/
            y[i] = y[i] + dy;
        }
    }

    double[] newPoints = new double[polygonPoints.length];
    for (int i = 0; i < newPoints.length; i += 2) {
        newPoints[i] = x[i / 2];
        newPoints[i + 1] = y[i / 2];
    }

    return new PolygonGateAnnotation(subsetName, domainAxisName, rangeAxisName, newPoints,
            LookAndFeel.SELECTED_STROKE, LookAndFeel.SELECTED_GATE_COLOR);
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the background for the plot./* w  w  w . j av  a 2s.c o m*/
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
public void drawBackground(Graphics2D g2, Rectangle2D area) {
    Paint p = getBackgroundPaint();
    if (p instanceof GradientPaint) {
        // do the transformation directly
        GradientPaint gp = (GradientPaint) p;
        double r = (this.f1 - this.f0) * area.getWidth();
        Point2D p0 = new Point2D.Double(area.getMinX() + this.f0 * area.getWidth(), area.getMaxY());
        Point2D p1 = new Point2D.Double(p0.getX() + r * Math.cos(this.angle),
                p0.getY() - r * Math.sin(this.angle));
        p = new GradientPaint(p0, gp.getColor1(), p1, gp.getColor2());
    }
    g2.setPaint(p);
    g2.fill(area);
}

From source file:main.MapKit.java

@Override
public void paintWaypoint(Graphics2D g, JXMapViewer viewer, MyWaypoint w) {
    g = (Graphics2D) g.create();/*from   ww  w . j  av a 2s .c om*/

    Point2D point = viewer.getTileFactory().geoToPixel(w.getPosition(), viewer.getZoom());
    int x = (int) point.getX();
    int y = (int) point.getY();

    if (w.amount == -1) { //means it's an original data point
        int fontSize = 28 - viewer.getZoom() * 2; //font size is larger when zoom in
        if (fontSize < 6)
            fontSize = 6;
        g.setFont(new Font("Arial", Font.PLAIN, fontSize));
        g.setColor(w.color);
        g.drawString("x", x - fontSize / 2, y + fontSize / 2);
        g.dispose();
        return;
    }

    if (origImage == null) {
        return;
    }

    BufferedImage myImg = map.get(w.color);

    if (myImg == null) {
        myImg = convert(origImage, w.color);
        map.put(w.color, myImg);
    }

    g.drawImage(myImg, x - myImg.getWidth() / 2, y - myImg.getHeight(), null);

    String label = String.valueOf(w.amount);

    //      g.setFont(font);
    FontMetrics metrics = g.getFontMetrics();
    int tw = metrics.stringWidth(label);
    int th = 1 + metrics.getAscent();

    //      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawString(label, x - tw / 2, y + th);

    g.dispose();
}