Example usage for com.google.gwt.user.client Random nextDouble

List of usage examples for com.google.gwt.user.client Random nextDouble

Introduction

In this page you can find the example usage for com.google.gwt.user.client Random nextDouble.

Prototype

public static native double nextDouble() ;

Source Link

Document

Returns a random double between 0 (inclusive) and 1 (exclusive).

Usage

From source file:org.geomajas.gwt2.example.client.sample.rendering.CanvasRenderingPanel.java

License:Open Source License

@UiHandler("rectBtn")
public void onRectangleBtnClicked(ClickEvent event) {
    if (container != null) {
        container.clear();//  w  w w.jav  a2  s . co m
        List<CanvasShape> shapes = new ArrayList<CanvasShape>();
        double factor = Math.pow(count, -0.5);
        for (int i = 0; i < count; i++) {
            double x = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor);
            double y = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor);
            double width = Random.nextDouble() * SHAPE_SIZE * factor;
            double height = Random.nextDouble() * SHAPE_SIZE * factor;
            CanvasRect rect = new CanvasRect(new Bbox(x - width / 2, y - height / 2, width, height));
            rect.setFillStyle(getRandomRGB(0.5));
            rect.setStrokeStyle(getRandomRGB(1));
            shapes.add(rect);
        }
        container.addAll(shapes);
        container.repaint();
    }
}

From source file:org.geomajas.gwt2.example.client.sample.rendering.HtmlMarkerPanel.java

License:Open Source License

@UiHandler("markersBtn")
public void onMarkersBtnClicked(ClickEvent event) {
    for (int i = 0; i < 20; i++) {
        double userX = Random.nextDouble() * 40000000 - 20000000;
        double userY = Random.nextDouble() * 40000000 - 20000000;
        Marker1 marker1 = new Marker1(resources.marker1(), userX, userY, 16, 32);
        container.add(marker1);//  w ww  . j  a  va2  s  . c om
    }
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * Gets the content stream for the specified Document object, 
 * or gets a rendition stream for a specified rendition of a document or folder object.
 * //from  w  w  w.j  a v a 2s.co m
 * On success response received, {@link ContentStreamReceivedEvent}  event is fired.
 * 
 * @param url url
 * @param streamId streamId
 */
public void getContentStream(String url, String streamId) {
    CmisContentStreamType contentStream = new CmisContentStreamType();
    ContentStreamReceivedEvent event = new ContentStreamReceivedEvent(contentStream);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Content stream is not recieved.");
    ContentStreamUnmarshaller unmarshaller = new ContentStreamUnmarshaller(contentStream);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.GET, url + "?nocache=" + String.valueOf(Random.nextDouble()))
            .send(callback);
}

From source file:org.objectfabric.GWTPlatform.java

License:Apache License

@Override
double randomDouble() {
    return Random.nextDouble();
}

From source file:org.rhq.coregui.client.admin.storage.StorageNodeLoadComponent.java

License:Open Source License

public StorageNodeLoadComponent(final int storageNodeId,
        Map<String, List<MeasurementDataNumericHighLowComposite>> sparkLineData) {
    super(5);/* ww w. ja va2 s  .com*/
    setPadding(5);
    this.sparkLineData = sparkLineData;
    final boolean showSparkLine = sparkLineData != null && !sparkLineData.isEmpty();
    loadGrid = new ListGrid() {
        @Override
        protected String getCellCSSText(ListGridRecord record, int rowNum, int colNum) {
            if ("avg".equals(getFieldName(colNum))
                    && (StorageNodeLoadCompositeDatasource.KEY_HEAP_PERCENTAGE.equals(record.getAttribute("id"))
                            || StorageNodeLoadCompositeDatasource.KEY_DATA_DISK_SPACE_PERCENTAGE
                                    .equals(record.getAttribute("id"))
                            || StorageNodeLoadCompositeDatasource.KEY_TOTAL_DISK_SPACE_PERCENTAGE
                                    .equals(record.getAttribute("id")))) {
                if (record.getAttributeAsFloat("avgFloat") > .85) {
                    return DONT_MISS_ME_CLASS;
                } else if (record.getAttributeAsFloat("avgFloat") > .7) {
                    return WARN_CLASS;
                } else {
                    return OK_CLASS;
                }
            } else if ("max".equals(getFieldName(colNum))
                    && StorageNodeLoadCompositeDatasource.KEY_FREE_DISK_TO_DATA_SIZE_RATIO
                            .equals(record.getAttribute("id"))) {
                if (record.getAttributeAsFloat("avgFloat") < .7) {
                    return DONT_MISS_ME_CLASS;
                } else if (record.getAttributeAsFloat("avgFloat") < 1.5) {
                    return WARN_CLASS;
                } else {
                    return OK_CLASS;
                }
            } else {
                return super.getCellCSSText(record, rowNum, colNum);
            }
        }
    };
    loadGrid.setID(
            EnhancedUtility.getSafeId(this.getClass().getName() + storageNodeId + "_" + Random.nextDouble()));
    loadGrid.setWidth100();
    loadGrid.setHeight(200);
    loadGrid.setAutoFitData(Autofit.VERTICAL);
    StorageNodeLoadCompositeDatasource datasource = StorageNodeLoadCompositeDatasource
            .getInstance(storageNodeId);
    List<ListGridField> fields = datasource.getListGridFields();
    if (showSparkLine) {
        fields.add(0, new ListGridField("sparkline", MSG.view_adminTopology_storageNodes_detail_chart(), 75));
    }
    loadGrid.setFields(fields.toArray(new ListGridField[fields.size()]));
    loadGrid.setHoverWidth(300);
    loadGrid.setDataSource(datasource);
    loadGrid.setAutoFetchData(true);
    //        loadGrid.fetchData();
    if (showSparkLine) {
        loadGrid.addDataArrivedHandler(new DataArrivedHandler() {
            @Override
            public void onDataArrived(DataArrivedEvent event) {
                showSparkLineGraphs();
                loadGrid.redraw();
            }
        });
    }
    addMember(loadGrid);

}

From source file:org.tiwonk.util.client.api.GwtRandomGenerator.java

License:Apache License

@Override
public double nextDouble() {
    return Random.nextDouble();
}

From source file:org.vectomatic.svg.chess.JSONBook.java

License:Open Source License

/**
 * Gets a random move from the book taking care of weights 
 * @param fen//from   w  w  w  .j  av  a2s  .  c  om
 * @return
 */
public int getMove(Board board) {
    generateMoves(board);
    long randomWeight = (new Double(Random.nextDouble() * totalWeight)).longValue();
    for (int i = 0; i < moves.size(); i++) {
        randomWeight -= weights.get(i);
        if (randomWeight <= 0)
            return moves.get(i);
    }
    return 0;
}