Example usage for java.awt Graphics drawPolyline

List of usage examples for java.awt Graphics drawPolyline

Introduction

In this page you can find the example usage for java.awt Graphics drawPolyline.

Prototype

public abstract void drawPolyline(int[] xPoints, int[] yPoints, int nPoints);

Source Link

Document

Draws a sequence of connected lines defined by arrays of x and y coordinates.

Usage

From source file:edu.umn.cs.spatialHadoop.core.OGCESRIShape.java

@Override
public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) {
    OGCGeometry geom = this.geom;
    Color shape_color = g.getColor();
    if (geom instanceof OGCGeometryCollection) {
        OGCGeometryCollection geom_coll = (OGCGeometryCollection) geom;
        for (int i = 0; i < geom_coll.numGeometries(); i++) {
            OGCGeometry sub_geom = geom_coll.geometryN(i);
            // Recursive call to draw each geometry
            new OGCESRIShape(sub_geom).draw(g, fileMBR, imageWidth, imageHeight, scale);
        }/* w w w.j a  va2s  .c  o  m*/
    } else if (geom.getEsriGeometry() instanceof MultiPath) {
        MultiPath path = (MultiPath) geom.getEsriGeometry();
        double sub_geom_alpha = path.calculateLength2D() * scale;
        int color_alpha = sub_geom_alpha > 1.0 ? 255 : (int) Math.round(sub_geom_alpha * 255);

        if (color_alpha == 0)
            return;

        int[] xpoints = new int[path.getPointCount()];
        int[] ypoints = new int[path.getPointCount()];

        for (int i = 0; i < path.getPointCount(); i++) {
            double px = path.getPoint(i).getX();
            double py = path.getPoint(i).getY();

            // Transform a point in the polygon to image coordinates
            xpoints[i] = (int) Math.round((px - fileMBR.x1) * imageWidth / fileMBR.getWidth());
            ypoints[i] = (int) Math.round((py - fileMBR.y1) * imageHeight / fileMBR.getHeight());
        }

        // Draw the polygon
        g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
        if (path instanceof Polygon)
            g.drawPolygon(xpoints, ypoints, path.getPointCount());
        else if (path instanceof Polyline)
            g.drawPolyline(xpoints, ypoints, path.getPointCount());
    }
}

From source file:com.jcraft.weirdx.Draw.java

static void reqPolyLine(Client c, XDrawable d, GC gc) throws IOException {
    int n = c.length;
    int foo;//from   w  w  w .  ja v a 2  s. c  o m

    Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode | GC.GCLineWidth);
    if (graphics == null) {
        c.client.readPad(n * 4);
        return;
    }

    int mode = c.data;

    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask());
        if (rec == null) {
            while (n > 0) {
                c.client.readPad(4);
                n--;
            }
            return;
        }
    }

    //short x, y;
    if (c.xarray.length < n) {
        c.xarray = new int[n];
        c.yarray = new int[n];
    }
    int sx = d.width;
    int sy = d.height;
    int lx = 0;
    int ly = 0;
    foo = c.xarray[0] = (short) c.client.readShort();
    if (foo <= sx)
        sx = foo;
    if (foo >= lx)
        lx = foo;
    foo = c.yarray[0] = (short) c.client.readShort();
    if (foo <= sy)
        sy = foo;
    if (foo >= ly)
        ly = foo;
    for (int i = 1; i < n; i++) {
        c.xarray[i] = (short) c.client.readShort();
        c.yarray[i] = (short) c.client.readShort();
        if (mode == 1) {
            c.xarray[i] += c.xarray[i - 1];
            c.yarray[i] += c.yarray[i - 1];
        }
        foo = c.xarray[i];
        if (foo <= sx)
            sx = foo;
        if (foo >= lx)
            lx = foo;
        foo = c.yarray[i];
        if (foo <= sy)
            sy = foo;
        if (foo >= ly)
            ly = foo;
    }

    if (gc.lineWidth > 1 && n > 1) {
        --n;
        for (int i = 0; i < n; i++) {
            int j = i + 1;
            drawThickLine(graphics, c.xarray[i], c.yarray[i], c.xarray[j], c.yarray[j], gc.lineWidth);
        }
    } else
        graphics.drawPolyline(c.xarray, c.yarray, n);

    if (d instanceof XWindow) {
        ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1);
    } else {
        ((XPixmap) d).draw(sx, sy, lx - sx + 1, ly - sy + 1);
    }

    if (gc.function == GC.GXxor || gc.function == GC.GXinvert) {
        graphics.setPaintMode();
    }
    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        d.restoreClip();
    }
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.grid.LinePointCollector.java

public void paint(final Graphics g, final GeoTransform projection, final GM_Point currentPoint,
        final int pointRectSize) {
    // IMPORTANT: we remeber GM_Points (not Point's) and retransform them for painting
    // because the projection depends on the current map-extent, so this builder
    // is stable in regard to zoom in/out
    if (!m_points.isEmpty()) {
        if (m_isSelected) {
            final int[][] points = getPointArrays(projection, null);
            final int[][] polygonPoints = toPolygonPoints(points, highlightDeltaX);

            g.drawPolygon(polygonPoints[0], polygonPoints[1], polygonPoints[0].length);
            g.fillPolygon(polygonPoints[0], polygonPoints[1], polygonPoints[0].length);

            drawHandles(g, points[0], points[1], pointRectSize, m_selection);
        } else {//  w  w w .j a va2  s  . co m
            // draw a line
            final int[][] points = getPointArrays(projection, currentPoint);
            final int[] arrayX = points[0];
            final int[] arrayY = points[1];

            /* Paint a linestring. */
            g.drawPolyline(arrayX, arrayY, arrayX.length);

            drawHandles(g, arrayX, arrayY, pointRectSize, m_selection);
        }
    }
}

From source file:org.kalypso.ogc.gml.map.widgets.AbstractCreateGeometeryWidget.java

/**
 * @see org.kalypso.ogc.gml.map.widgets.AbstractWidget#paint(java.awt.Graphics)
 *///from  ww w  . j a v  a 2s  .  c o  m
@Override
public void paint(final Graphics g) {
    if (!canEdit())
        return;
    if (!m_points.isEmpty() && m_currentPoint != null) {
        final int[][] lArrPositionToDrow = getXYArrayPixel();
        final int[] arrayX = lArrPositionToDrow[0];
        final int[] arrayY = lArrPositionToDrow[1];
        final Class<? extends GM_Object> geoClass = getGeometryClass();
        if (geoClass == GeometryUtilities.getPolygonClass()) {
            // paint polygon
            g.drawPolygon(arrayX, arrayY, arrayX.length);
            drawHandles(g, arrayX, arrayY);
        } else if (geoClass == GeometryUtilities.getLineStringClass()) {
            // paint linestring
            g.drawPolyline(arrayX, arrayY, arrayX.length);
            drawHandles(g, arrayX, arrayY);
        } else if (geoClass == GeometryUtilities.getPointClass()) {
            drawHandles(g, arrayX, arrayY);
        }
    }
}

From source file:org.kalypso.ogc.gml.map.widgets.builders.LineGeometryBuilder.java

@Override
public void paint(final Graphics g, final GeoTransform projection, final Point currentPoint) {
    if (projection == null)
        return;/*  w w  w.  jav a 2 s. co  m*/

    // IMPORTANT: we remember GM_Points (not Point's) and re-transform them for painting
    // because the projection depends on the current map-extent, so this builder
    // is stable in regard to zoom in/out
    if (!m_points.isEmpty()) {
        final int[][] points = getPointArrays(projection, currentPoint);

        final int[] arrayX = points[0];
        final int[] arrayY = points[1];

        /* Paint a linestring. */
        g.drawPolyline(arrayX, arrayY, arrayX.length);
        drawHandles(g, arrayX, arrayY);
    }

    m_renderer.paint(g);
}