@UiHandler("polyBtn")
 public void onPolyBtnClicked(ClickEvent event) {
   if (container != null) {
     container.clear();
     List<CanvasShape> shapes = new ArrayList<CanvasShape>();
     double factor = Math.pow(count, -0.5);
     for (int i = 0; i < count; i++) {
       double x1 = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor);
       double y1 = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor);
       double x2 = x1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor;
       double y2 = y1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor;
       double x3 = x1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor;
       double y3 = y1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor;
       Coordinate[] coords =
           new Coordinate[] {
             new Coordinate(x1, y1),
             new Coordinate(x2, y2),
             new Coordinate(x3, y3),
             new Coordinate(x1, y1)
           };
       Geometry ring = new Geometry(Geometry.LINEAR_RING, 0, 5);
       ring.setCoordinates(coords);
       Geometry poly = new Geometry(Geometry.POLYGON, 0, 5);
       poly.setGeometries(new Geometry[] {ring});
       CanvasPath path = new CanvasPath(poly);
       path.setFillStyle(getRandomRGB(0.5));
       path.setStrokeStyle(getRandomRGB(1));
       shapes.add(path);
     }
     container.addAll(shapes);
     container.repaint();
   }
 }
  private void calculate(final GeometryArrayFunction callback) {
    geometry.setPrecision(-1);
    splitLine.setPrecision(-1);
    GeometrySplitRequest request = new GeometrySplitRequest(geometry, splitLine);
    GwtCommand command = new GwtCommand(GeometrySplitRequest.COMMAND);
    command.setCommandRequest(request);
    GwtCommandDispatcher.getInstance()
        .execute(
            command,
            new AbstractCommandCallback<GeometrySplitResponse>() {

              public void execute(GeometrySplitResponse response) {
                callback.execute(
                    response
                        .getGeometries()
                        .toArray(new Geometry[response.getGeometries().size()]));
              }
            });
  }