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.pdfbox2.pdf.operator.path.construction.CurveTo.java

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    try {// w ww  .  j ava2 s  .co m
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x1 = (COSNumber) operands.get(0);
        COSNumber y1 = (COSNumber) operands.get(1);
        COSNumber x2 = (COSNumber) operands.get(2);
        COSNumber y2 = (COSNumber) operands.get(3);
        COSNumber x3 = (COSNumber) operands.get(4);
        COSNumber y3 = (COSNumber) operands.get(5);

        Point2D p1 = transform(x1.doubleValue(), y1.doubleValue());
        Point2D p2 = transform(x2.doubleValue(), y2.doubleValue());
        Point2D p3 = transform(x3.doubleValue(), y3.doubleValue());

        pdfPage.getCurrentPath().curveTo((float) p1.getX(), (float) p1.getY(), (float) p2.getX(),
                (float) p2.getY(), (float) p3.getX(), (float) p3.getY());

        if (log.isTraceEnabled()) {
            log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x2:"
                    + p2.getX() + ",y2:" + p2.getY() + ", x3:" + p3.getX() + ",y3:" + p3.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'c'.", e);
    }
}

From source file:views.network.MyRadialTreeLayout.java

public void setLocation(V v, Point2D location) {
    Point2D c = getCenter();//from w  ww .  j  ava2s  . c  o  m
    Point2D pv = new Point2D.Double(location.getX() - c.getX(), location.getY() - c.getY());
    PolarPoint newLocation = PolarPoint.cartesianToPolar(pv);
    polarLocations.get(v).setLocation(newLocation);
}

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

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

        COSNumber x2 = (COSNumber) operands.get(0);
        COSNumber y2 = (COSNumber) operands.get(1);
        COSNumber x3 = (COSNumber) operands.get(2);
        COSNumber y3 = (COSNumber) operands.get(3);

        Point2D currentPoint = pdfPage.getCurrentPath().getCurrentPoint();
        Point2D p2 = transform(x2.doubleValue(), y2.doubleValue());
        Point2D p3 = transform(x3.doubleValue(), y3.doubleValue());

        pdfPage.getCurrentPath().curveTo((float) currentPoint.getX(), (float) currentPoint.getY(),
                (float) p2.getX(), (float) p2.getY(), (float) p3.getX(), (float) p3.getY());

        if (log.isTraceEnabled()) {
            log.trace("Appending cubic Bezier curve with x2:" + p2.getX() + ",y2:" + p2.getY() + ", x3:"
                    + p3.getX() + ",y3:" + p3.getY() + ", using current point x:" + currentPoint.getX() + ",y:"
                    + currentPoint.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'v'.", e);
    }
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java

/**
 * Creates a triangle to indicate the presence of far-out values when the
 * plot orientation is vertical./*www  . j av  a  2 s.c  o m*/
 *
 * @param foRadius the far-out radius.
 * @param point the location.
 */
private Shape createTriangleVertical(Point2D point, double foRadius) {
    double side = foRadius * 2;
    double x = point.getX();
    double y = point.getY();

    int[] xpoints = { (int) (x), (int) (x + side), (int) (x + (side / 2.0)) };
    int[] ypoints = { (int) (y), (int) (y), (int) (y + side) };

    return new Polygon(xpoints, ypoints, 3);
}

From source file:hudson.util.NoOverlapCategoryAxis.java

@Override
protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
        RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {

    if (state == null) {
        throw new IllegalArgumentException("Null 'state' argument.");
    }/*w w  w.  j a va2 s.c  o  m*/

    if (isTickLabelsVisible()) {
        java.util.List ticks = refreshTicks(g2, state, plotArea, edge);
        state.setTicks(ticks);

        // remember the last drawn label so that we can avoid drawing overlapping labels.
        Rectangle2D r = null;

        int categoryIndex = 0;
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {

            CategoryTick tick = (CategoryTick) iterator.next();
            g2.setFont(getTickLabelFont(tick.getCategory()));
            g2.setPaint(getTickLabelPaint(tick.getCategory()));

            CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
            double x0 = 0.0;
            double x1 = 0.0;
            double y0 = 0.0;
            double y1 = 0.0;
            if (edge == RectangleEdge.TOP) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                y0 = y1 - state.getMax();
            } else if (edge == RectangleEdge.BOTTOM) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                y1 = y0 + state.getMax();
            } else if (edge == RectangleEdge.LEFT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                x0 = x1 - state.getMax();
            } else if (edge == RectangleEdge.RIGHT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                x1 = x0 - state.getMax();
            }
            Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
            if (r == null || !r.intersects(area)) {
                Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor());
                TextBlock block = tick.getLabel();
                block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                if (plotState != null && plotState.getOwner() != null) {
                    EntityCollection entities = plotState.getOwner().getEntityCollection();
                    if (entities != null) {
                        String tooltip = getCategoryLabelToolTip(tick.getCategory());
                        entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
                    }
                }
                r = bounds.getBounds2D();
            }

            categoryIndex++;
        }

        if (edge.equals(RectangleEdge.TOP)) {
            double h = state.getMax();
            state.cursorUp(h);
        } else if (edge.equals(RectangleEdge.BOTTOM)) {
            double h = state.getMax();
            state.cursorDown(h);
        } else if (edge == RectangleEdge.LEFT) {
            double w = state.getMax();
            state.cursorLeft(w);
        } else if (edge == RectangleEdge.RIGHT) {
            double w = state.getMax();
            state.cursorRight(w);
        }
    }
    return state;
}

From source file:org.sejda.impl.sambox.component.PageImageWriter.java

public void write(PDPage page, PDImageXObject image, Point2D position, float width, float height)
        throws TaskIOException {
    try {/*  ww w .  j  a va  2 s .co  m*/
        try (PDPageContentStream contentStream = new PDPageContentStream(document, page,
                PDPageContentStream.AppendMode.APPEND, true, true)) {

            contentStream.drawImage(image, (float) position.getX(), (float) position.getY(), width, height);
            contentStream.close();
        }
    } catch (IOException e) {
        throw new TaskIOException("An error occurred writing image to the page.", e);
    }
}

From source file:org.uva.itast.blended.omr.scanners.MarkScanner.java

/**
 * Return boundingBox of//w  w  w.j  a  v a2  s. c o  m
 * 
 * @param coords
 * @return
 */
private Rectangle getRectArea(double[] coords) {
    Point2D coordUpperLeft = pageImage.toPixels(coords[0], coords[1]);
    Point2D coordBottomRight = pageImage.toPixels(coords[0] + coords[2], coords[1] + coords[2]);

    int x = (int) Math.min(coordUpperLeft.getX(), coordBottomRight.getX());
    int y = (int) Math.min(coordUpperLeft.getY(), coordBottomRight.getY());
    int xm = (int) Math.max(coordUpperLeft.getX(), coordBottomRight.getX());
    int ym = (int) Math.max(coordUpperLeft.getY(), coordBottomRight.getY());
    int width = xm - x; // anchura en pxeles
    int height = ym - y; // altura en pxeles

    return new Rectangle(x, y, width, height);
}

From source file:fr.crnan.videso3d.trajectography.Track2DView.java

public Track2DView(VidesoTrack track) {
    if (track instanceof LPLNTrack) {
        XYSeries dataset = new XYSeries(track.getName());
        List<ValueMarker> markers = new LinkedList<ValueMarker>();
        double distance = 0;
        LPLNTrackPoint last = null;/*from  ww  w  . j  a v  a2s.c  o m*/
        for (LPLNTrackPoint p : ((LPLNTrack) track).getTrackPoints()) {
            if (last != null) {
                distance += Position.ellipsoidalDistance(last.getPosition(), p.getPosition(),
                        Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
            }
            dataset.add(distance, p.getElevation() / 30.48);
            ValueMarker marker = new ValueMarker(distance);
            marker.setLabel(p.getName());
            marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
            markers.add(marker);
            last = p;
        }
        JFreeChart chart = ChartFactory.createXYLineChart("Coupe 2D", "NM", "FL",
                new XYSeriesCollection(dataset), PlotOrientation.VERTICAL, false, false, false);
        for (ValueMarker m : markers) {
            chart.getXYPlot().addDomainMarker(m);
        }
        //ajout des secteurs AIP avec des XYPolygonAnnotation
        Collection<Object> secteurs;
        AIPController controller = (AIPController) DatasManager.getController(DatasManager.Type.AIP);
        secteurs = controller.getObjects(AIP.CTL);
        for (int i = 0; i <= 600; i += 10) {
            last = null;
            Secteur3D lastSecteur = null;
            double lastBoundary = 0.0;
            for (LPLNTrackPoint point : ((LPLNTrack) track).getTrackPoints()) {
                Position p = new Position(point.getPosition(), i * 30.48);
                //calcul du secteur contenant le point en cours
                Iterator<Object> iterator = secteurs.iterator();
                boolean contain = false;
                Secteur3D secteur = null;
                while (iterator.hasNext() && !contain) {
                    Secteur3D temp = (Secteur3D) iterator.next();
                    if (temp.contains(p)) {
                        contain = true;
                        secteur = temp;
                    }
                }

                //si premier point, on enregistre simplement le secteur trouv
                if (last == null) {
                    lastSecteur = secteur;
                } else {
                    if (lastSecteur != secteur) {
                        //si le secteur a chang, on dessine le secteur prcdent
                        //sauf si ce dernier n'existait pas
                        if (lastSecteur != null) {
                            //dans ce cas, on calcule le point d'intersection entre le secteur et le segment form par les deux points
                            //lastSecteur != null => last !=null
                            Set<Point2D> intersects = lastSecteur
                                    .getIntersections(new Line2D.Double(last.getLatitude(), last.getLongitude(),
                                            p.getLatitude().degrees, p.getLongitude().degrees), true);
                            if (!intersects.isEmpty()) {
                                Point2D intersect = intersects.iterator().next();
                                distance = Position.ellipsoidalDistance(
                                        new LatLonCautra(intersect.getX(), intersect.getY()),
                                        last.getPosition(), Earth.WGS84_EQUATORIAL_RADIUS,
                                        Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
                                //et ajout de l'annotation
                                XYPolygonAnnotation annotation = new XYPolygonAnnotation(
                                        new double[] { lastBoundary, i, lastBoundary + distance, i,
                                                lastBoundary + distance, i + 10, lastBoundary, i + 10 });
                                chart.getXYPlot().addAnnotation(annotation);
                                lastBoundary += distance;
                            }
                        }
                        lastSecteur = secteur;
                    }
                }
                last = point;
            }
        }
        //espace en haut pour les marqueurs
        chart.getXYPlot().getRangeAxis().setUpperMargin(0.05);
        ChartPanel chartPanel = new ChartPanel(chart);
        this.setContentPane(chartPanel);
        this.pack();
    }
}

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

/**
 * Draws the background for the plot./*from  w ww . j a va2  s.  co 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:edu.uci.ics.jung.io.PajekNetWriter.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  a  v  a2 s .  c o  m*/
 */
public void save(Graph<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("*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() + " 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();
}