Example usage for com.google.gwt.canvas.dom.client Context2d fill

List of usage examples for com.google.gwt.canvas.dom.client Context2d fill

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d fill.

Prototype

public final native void fill() ;

Source Link

Document

Fills the current path.

Usage

From source file:org.cesiumjs.cs.scene.interaction.MarkerGroup.java

License:Apache License

public static BillboardOptions createBillboard(DrawInteractionOptions options) {
    Canvas canvas = Canvas.createIfSupported();
    Context2d context = canvas.getContext2d();

    context.setFillStyle(options.color.toCssColorString());
    context.setStrokeStyle(options.outlineColor.toCssColorString());
    context.setLineWidth(options.outlineWidth);

    context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2);
    context.beginPath();/* ww w . j  a  v  a2 s  . c o  m*/
    context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
    context.closePath();
    context.stroke();
    context.fill();

    BillboardOptions billboard = new BillboardOptions();
    billboard.horizontalOrigin = HorizontalOrigin.CENTER();
    billboard.verticalOrigin = VerticalOrigin.CENTER();
    billboard.imageCanvas = canvas.getCanvasElement();
    return billboard;
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.ParticleSystemFireworks.java

License:Apache License

private CanvasElement getImage() {
    if (!Cesium.defined(particleCanvas)) {
        particleCanvas = RootPanel.get().getElement().getOwnerDocument().createCanvasElement();
        particleCanvas.setWidth(20);/* ww w. j a  va2 s  .  c  om*/
        particleCanvas.setHeight(20);
        Context2d context2d = particleCanvas.getContext2d();
        context2d.beginPath();
        context2d.arc(8, 8, 8, 0, Math.TWO_PI(), true);
        context2d.closePath();
        context2d.setFillStyle("rgb(255, 255, 255)");
        context2d.fill();
        Cesium.log(particleCanvas);
    }
    return particleCanvas;
}

From source file:org.cruxframework.crux.widgets.client.colorpicker.HuePicker.java

License:Apache License

private void drawGradient() {
    Context2d ctx = canvas.getContext2d();

    // draw gradient
    ctx.setFillStyle("#ffffff");
    ctx.fillRect(0, 0, 26, 180);/* w w  w .  j a v  a2  s  .co  m*/
    for (int y = 0; y <= 179; y++) {
        String hex = ColorUtils.hsl2hex(y * 2, 100, 100);
        ctx.setFillStyle("#" + hex);
        ctx.fillRect(3, y, 20, 1);
    }

    // draw handle
    if (handleY >= 0) {
        ctx.setFillStyle("#000000");

        ctx.beginPath();
        ctx.moveTo(3, handleY);
        ctx.lineTo(0, handleY - 3);
        ctx.lineTo(0, handleY + 3);
        ctx.closePath();
        ctx.fill();

        ctx.moveTo(23, handleY);
        ctx.lineTo(26, handleY - 3);
        ctx.lineTo(26, handleY + 3);
        ctx.closePath();
        ctx.fill();
    }
}

From source file:org.cruxframework.crux.widgets.client.colorpicker.SaturationLightnessPicker.java

License:Apache License

private void drawGradient(boolean drawHandle) {
    Context2d ctx = canvas.getContext2d();

    // draw gradient
    for (int x = 0; x <= 179; x++) {
        CanvasGradient grad = ctx.createLinearGradient(x, 0, x, 179);
        int s = Math.round(x * 100 / 179);
        String hex = ColorUtils.hsl2hex(hue, s, 0);
        grad.addColorStop(0, "#" + hex);
        hex = ColorUtils.hsl2hex(hue, s, 100);
        grad.addColorStop(1, "#" + hex);
        ctx.setFillStyle(grad);/*from   ww  w.j a  v  a  2 s  . c om*/
        ctx.fillRect(x, 0, 1, 180);
    }

    // draw handle
    if (drawHandle) {
        ctx.beginPath();
        ctx.arc(handleX, handleY, 3, 0, Math.PI * 2, false);
        ctx.closePath();
        ctx.setFillStyle("#ffffff");
        ctx.fill();

        ctx.beginPath();
        ctx.arc(handleX, handleY, 2, 0, Math.PI * 2, false);
        ctx.closePath();
        ctx.setFillStyle("#000000");
        ctx.fill();
    }
}

From source file:org.primaresearch.web.gwt.client.ui.page.renderer.PolygonRendererHelper.java

License:Apache License

private static void drawPolygon(Context2d context, Polygon polygon, boolean outline, boolean fill) {
    if (polygon == null || polygon.getSize() < 3 || (!outline && !fill))
        return;//from   ww  w. j  a v  a2s .co m

    context.beginPath();
    context.moveTo(polygon.getPoint(0).x, polygon.getPoint(0).y);
    for (int i = 1; i < polygon.getSize(); i++)
        context.lineTo(polygon.getPoint(i).x, polygon.getPoint(i).y);
    context.lineTo(polygon.getPoint(0).x, polygon.getPoint(0).y);
    if (fill)
        context.fill();
    if (outline)
        context.stroke();
}

From source file:org.primaresearch.web.gwt.client.ui.page.tool.drawing.EditOutlineTool.java

License:Apache License

@Override
public void render(PageRenderer renderer) {
    if (!isEnabled())
        return;//  ww w  .  ja  v a2 s.  c  o m

    Context2d context = renderer.getContext();

    //Draw the selected outline in red
    RenderStyle style = new RenderStyle("rgb(255,0,0)", "transparent", 1.0);
    PolygonRendererHelper.drawPolygon(context, polygon, style, renderer.getZoomFactor(), true, false);

    //Delete mode
    if (deletePointsMode) {
        if (currentPolygonPoint != null) {
            context.setFillStyle(DELETE_POINT_FILL_COLOR);
            context.setStrokeStyle(DELETE_POINT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            //Cross
            context.beginPath();
            int size = (int) (3.0 / view.getZoomFactor());
            context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size);

            context.fill();
            context.stroke();
        }
    }
    //Add or move mode
    else {
        //Move point
        if (currentPolygonPoint != null) {
            context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR);
            context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            int size = (int) (3.0 / view.getZoomFactor());

            //Rect in centre
            context.beginPath();
            context.rect(currentPolygonPoint.x - size, currentPolygonPoint.y - size, 2 * size + 1,
                    2 * size + 1);
            context.fill();
            context.stroke();

            //Arrows
            // Left
            context.beginPath();
            context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size);
            context.fill();
            context.stroke();
            // Right
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size);
            context.fill();
            context.stroke();
            // Top
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size);
            context.fill();
            context.stroke();
            // Bottom
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size);
            context.fill();
            context.stroke();
        }

        //Add point
        if (newPolygonPointCandidate != null) {
            context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR);
            context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            //Plus sign
            context.beginPath();
            int size = (int) (3.0 / view.getZoomFactor());
            context.moveTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - 3 * size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + 3 * size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + 3 * size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size);

            context.fill();
            context.stroke();
        }
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw the grid.//from w w  w .  j  a v a  2 s  . co  m
 * @param ctx A GWT Context2d object.
 */
protected void drawGrid(Context2d ctx) {
    AbstractGrid currentCell = upperLeft;
    AbstractGrid startOfRow = upperLeft;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            if (this.isIncognita(currentCell)) {
                ctx.setFillStyle(TERRA_INCOGNITA_COLOR);
                ctx.beginPath();
                ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
                ctx.closePath();
                ctx.fill();
            } else {
                if ((xholonConsole != null) && (currentCell == xholonConsole.getContext())) {
                    ctx.setFillStyle(COLOR_CONTEXT);
                } else {
                    ctx.setFillStyle(getColor(currentCell));
                }
                ctx.beginPath();
                ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
                ctx.closePath();
                ctx.fill();
                if (useShapes) {
                    drawAgents(ctx, currentCell, j * cellSize, i * cellSize);
                }
            }
            currentCell = (AbstractGrid) currentCell.port[IGrid.P_EAST]; // get next cell
        }
        startOfRow = (AbstractGrid) startOfRow.port[IGrid.P_SOUTH]; // get start of next row
        currentCell = (AbstractGrid) startOfRow;
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw a 1D CA grid.//  www  .  j a  v a 2s  . c  om
 * @param ctx A GWT Context2d object.
 */
protected void draw1dCaGrid(Context2d ctx) {
    AbstractGrid currentCell = upperLeft;
    AbstractGrid startOfRow = upperLeft;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            //ctx.setFillStyle(getColor(currentCell));
            if ((xholonConsole != null) && (currentCell == xholonConsole.getContext())) {
                ctx.setFillStyle(COLOR_CONTEXT);
            } else {
                ctx.setFillStyle(getColor(currentCell));
            }
            ctx.beginPath();
            ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
            ctx.closePath();
            ctx.fill();
            if (useShapes) {
                drawAgents(ctx, currentCell, j * cellSize, i * cellSize);
            }
            currentCell = (AbstractGrid) currentCell.port[IGrid.P_CARIGHTNEIGHBOR]; // get next cell
        }
        startOfRow = (AbstractGrid) startOfRow.port[IGrid.P_CAFUTURESELF]; // get start of next row
        currentCell = (AbstractGrid) startOfRow;
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw agents within the current grid cell.
 * Only one agent is drawn, for now.//from  w w w  . jav  a2  s. c  o m
 * GWT code to draw a triangle:
<code>
Canvas canvas = Canvas.createIfSupported();
Context2d context1 = canvas.getContext2d();
context1.beginPath();
context1.moveTo(25,0);
context1.lineTo(0,20);
context1.lineTo(25,40);
context1.lineTo(25,0);
context1.fill();
context1.closePath();
</code>
 * @param ctx A GWT Context2d object.
 * @param currentCell The grid cell that the agents will draw themselves in.
 * @param x X coordinate of the grid cell.
 * @param y Y coordinate of the grid cell.
 */
protected void drawAgents(Context2d ctx, AbstractGrid currentCell, int x, int y) {
    IXholon agent = currentCell.getFirstChild(); // this should remain as getFirstChild()
    if (agent != null) {
        if (useIcons) {
            // Test of drawImage()
            String icon = ((IDecoration) agent.getXhc()).getIcon();
            if (icon != null) {
                drawImage(ctx, icon, x, y, cellSize, cellSize);
                return;
            }
        }
        ctx.setFillStyle(getColor(agent));
        int shape = getShape(agent);
        switch (shape) {
        case GPSHAPE_CIRCLE: // OK
        {
            ctx.beginPath();
            int xcentre = x + (int) (cellSize * 0.5);
            int ycentre = y + (int) (cellSize * 0.5);
            int radius = (int) (cellSize * 0.45);
            ctx.arc(xcentre, ycentre, radius, 0, Math.PI * 2);
            ctx.closePath();
            ctx.fill();
        }
            break;
        case GPSHAPE_TRIANGLE: // OK
        {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);

            //Polygon triangle = new Polygon(xCoor, yCoor, 3);
            //triangle.translate(x, y);
            //g.fillPolygon(triangle);

            /*ctx.save();
            ctx.translate(x, y);
            ctx.beginPath();
            ctx.moveTo(0.0*cellSize, 1.0*cellSize);
            ctx.lineTo(1.0*cellSize, 1.0*cellSize);
            ctx.lineTo(0.5*cellSize, 0.0*cellSize);
            ctx.lineTo(0.0*cellSize, 1.0*cellSize);
            ctx.fill();
            ctx.closePath();
            ctx.restore();*/
        }
            break;
        case GPSHAPE_RECTANGLE: // OK
        {
            int xCoor[] = { (int) (0.1 * cellSize), (int) (0.9 * cellSize), (int) (0.9 * cellSize),
                    (int) (0.1 * cellSize) };
            int yCoor[] = { (int) (0.9 * cellSize), (int) (0.9 * cellSize), (int) (0.1 * cellSize),
                    (int) (0.1 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);

            //Polygon rectangle = new Polygon(xCoor, yCoor, 4);
            //rectangle.translate(x, y);
            //g.fillPolygon(rectangle);

            /*ctx.save();
            ctx.translate(x, y);
            ctx.beginPath();
            ctx.moveTo(0.1*cellSize, 0.9*cellSize);
            ctx.lineTo(0.9*cellSize, 0.9*cellSize);
            ctx.lineTo(0.9*cellSize, 0.1*cellSize);
            ctx.lineTo(0.1*cellSize, 0.1*cellSize);
            ctx.lineTo(0.1*cellSize, 0.9*cellSize);
            ctx.fill();
            ctx.closePath();
            ctx.restore();*/
        }
            break;
        case GPSHAPE_PENTAGON: {
            int xCoor[] = { (int) (0.2 * cellSize), (int) (0.8 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.5 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 5);

            //Polygon pentagon = new Polygon(xCoor, yCoor, 5);
            //pentagon.translate(x, y);
            //g.fillPolygon(pentagon);
        }
            break;
        case GPSHAPE_HEXAGON: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.75 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 6);

            //ctx.beginPath();
            //drawPolygon(ctx, x, y, 0.5, 6, 0, false);
            //ctx.fill();

            //Polygon hexagon = new Polygon(xCoor, yCoor, 6);
            //hexagon.translate(x, y);
            //g.fillPolygon(hexagon);
        }
            break;
        case GPSHAPE_OCTOGON: {
            int xCoor[] = { (int) (0.3 * cellSize), (int) (0.7 * cellSize), (int) (1.0 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.7 * cellSize), (int) (0.3 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.7 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.0 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.7 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 8);

            //Polygon octogon = new Polygon(xCoor, yCoor, 8);
            //octogon.translate(x, y);
            //g.fillPolygon(octogon);
        }
            break;
        case GPSHAPE_STAR: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.8 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.7 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.0 * cellSize), (int) (0.2 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.8 * cellSize), (int) (1.0 * cellSize), (int) (0.7 * cellSize),
                    (int) (0.4 * cellSize), (int) (0.4 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.4 * cellSize), (int) (0.4 * cellSize), (int) (0.7 * cellSize),
                    (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 10);

            //Polygon star = new Polygon(xCoor, yCoor, 10);
            //star.translate(x, y);
            //g.fillPolygon(star);
        }
            break;
        case GPSHAPE_TURTLE: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.7 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize),
                    (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);

            //Polygon turtle = new Polygon(xCoor, yCoor, 4);
            //turtle.translate(x, y);
            //g.fillPolygon(turtle);
        }
            break;
        case GPSHAPE_SMALLCIRCLE: {
            ctx.beginPath();
            int xcentre = x + (int) (cellSize * 0.5);
            int ycentre = y + (int) (cellSize * 0.5);
            int radius = (int) (cellSize * 0.25);
            ctx.arc(xcentre, ycentre, radius, 0, Math.PI * 2);
            ctx.closePath();
            ctx.fill();
        }
            break;
        case GPSHAPE_SMALLRECTANGLE: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (0.75 * cellSize),
                    (int) (0.25 * cellSize) };
            int yCoor[] = { (int) (0.75 * cellSize), (int) (0.75 * cellSize), (int) (0.25 * cellSize),
                    (int) (0.25 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);
        }
            break;
        case GPSHAPE_REVERSETRIANGLE: {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_CROSS: {
            int xCoor[] = { (int) (0.33 * cellSize), (int) (0.67 * cellSize), (int) (0.67 * cellSize),
                    (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.67 * cellSize),
                    (int) (0.67 * cellSize), (int) (0.33 * cellSize), (int) (0.33 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.33 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.33 * cellSize),
                    (int) (0.33 * cellSize), (int) (0.67 * cellSize), (int) (0.67 * cellSize),
                    (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.67 * cellSize),
                    (int) (0.67 * cellSize), (int) (0.33 * cellSize), (int) (0.33 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 12);
        }
            break;
        case GPSHAPE_DIAMOND: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.5 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);
        }
            break;
        case GPSHAPE_WYE: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.5 * cellSize), (int) (0.75 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.75 * cellSize), (int) (0.75 * cellSize),
                    (int) (0.25 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize), };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (1.0 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.75 * cellSize), (int) (0.25 * cellSize), };
            drawPolygon(ctx, x, y, xCoor, yCoor, 9);
        }
            break;
        case GPSHAPE_LRTRIANGLE: {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (1.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_RLTRIANGLE: {
            int xCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_JAVASCRIPTCODE:
            this.makeJsShape(ctx, ((IDecoration) agent.getXhc()).getSymbol().substring(JSCODE_INDICATOR_LEN), x,
                    y, cellSize);
            break;
        case GPSHAPE_NOSHAPE:
            break;
        default: // the agent's shape directly specifies the number of sides
        {
            ctx.beginPath();
            drawPolygon(ctx, x, y, cellSize * 0.5, shape, 0, false);
            ctx.fill();
        }

        }
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw a polygon./*from   w  w w.jav  a2 s.com*/
 */
protected void drawPolygon(Context2d ctx, int x, int y, int xCoor[], int yCoor[], int sides) {
    ctx.save();
    ctx.translate(x, y);
    ctx.beginPath();
    ctx.moveTo(xCoor[0], yCoor[0]);
    for (int i = 1; i < sides; i++) {
        ctx.lineTo(xCoor[i], yCoor[i]);
    }
    ctx.lineTo(xCoor[0], yCoor[0]);
    ctx.fill();
    ctx.closePath();
    ctx.restore();
}