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

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

Introduction

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

Prototype

public static native int nextInt(int upperBound) ;

Source Link

Document

Returns a random int between 0 (inclusive) and upperBound (exclusive) with roughly equal probability of returning any particular int in this range.

Usage

From source file:com.gwttest.client.Demo.java

License:Open Source License

private ChartData getScatterLineChartData() {
    ChartData cd = new ChartData("X Y Distribution",
            "font-size: 14px; font-family: Verdana; text-align: center;");
    cd.setBackgroundColour("#ffffff");
    ScatterChart scat = new ScatterChart(ScatterStyle.LINE);

    // FIXME does not work in flash
    scat.setTooltip("#x#,#y#");

    for (int n = 0; n < 25; n++) {
        int x = n * 2 - 25;
        int y = Random.nextInt(30) - 15;
        scat.addPoint(x, y);//from w w  w  .  jav  a  2  s. c  o  m
    }
    XAxis xa = new XAxis();
    xa.setRange(-25, 25, 5);
    cd.setXAxis(xa);
    YAxis ya = new YAxis();
    ya.setRange(-25, 25, 5);
    cd.setYAxis(ya);
    cd.addElements(scat);
    return cd;
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private ChartData getScatterPointChartData() {
    ChartData cd = new ChartData("X Y Distribution",
            "font-size: 14px; font-family: Verdana; text-align: center;");
    cd.setBackgroundColour("#ffffff");
    ScatterChart scat = new ScatterChart();
    // Star star = new Star();
    // star.setSize(10);
    // star.setColour("#FF9900");
    // star.setTooltip("#x#,#y#");
    // scat.setDotStyle(star);
    for (int n = 0; n < 20; n++) {
        int x = Random.nextInt(50) - 25;
        int y = Random.nextInt(50) - 25;
        Star star = new Star();
        star.setSize(Random.nextInt(8) + 2);
        star.setColour(colours[Random.nextInt(8)]);
        star.setTooltip("#x#,#y#");
        star.setXY(x, y);//from  w  w  w  .ja  v  a  2  s .com
        scat.addPoints(star);
        // scat.addPoint(x, y);
    }
    XAxis xa = new XAxis();
    xa.setRange(-25, 25, 5);
    cd.setXAxis(xa);
    YAxis ya = new YAxis();
    ya.setRange(-25, 25, 5);
    cd.setYAxis(ya);
    cd.addElements(scat);
    return cd;
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private ChartData getSketchChartData() {
    ChartData cd2 = new ChartData("How many pies were eaten?",
            "font-size: 14px; font-family: Verdana; text-align: center;");
    cd2.setBackgroundColour("#ffffff");
    XAxis xa = new XAxis();
    xa.setLabels("John", "Frank", "Mary", "Andy", "Mike", "James");
    // xa.setMax(6);
    cd2.setXAxis(xa);/* www.ja  v a  2  s. c o  m*/
    SketchBarChart sketch = new SketchBarChart("#00aa00", "#009900", 6);
    sketch.setTooltip("#val# pies");
    sketch.addValues(Random.nextInt(6) + 1, Random.nextInt(5) + 1, Random.nextInt(3) + 1);
    SketchBarChart.SketchBar skb = new SketchBarChart.SketchBar(Random.nextInt(5) + 5);
    skb.setColour("#6666ff");
    skb.setTooltip("Winner!<br>#val# pies");
    sketch.addBars(skb);
    sketch.addValues(Random.nextInt(5) + 1, Random.nextInt(5) + 1);
    cd2.addElements(sketch);
    return cd2;
}

From source file:com.jwh.gwt.fasttable.sample.client.SampleModel.java

License:Open Source License

/**
 * @param samples//from w w  w .ja  va 2  s .c o m
 *            Options available
 * @return A random selection of one of the options
 */
private String randomSample(String[] samples) {
    return samples[Random.nextInt(samples.length - 1)];
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.grid.CellGridExample.java

License:sencha.com license

@Override
public Widget asWidget() {
    // reduce the padding on text element as we have widgets in the cells
    SafeStyles textStyles = SafeStylesUtils.fromTrustedString("padding: 1px 3px;");

    ColumnConfig<Plant, String> nameColumn = new ColumnConfig<Plant, String>(properties.name(), 100, "Name");
    // IMPORTANT we want the text element (cell parent) to only be as wide as
    // the cell and not fill the cell
    nameColumn.setColumnTextClassName(CommonStyles.get().inlineBlock());
    nameColumn.setColumnTextStyle(textStyles);

    TextButtonCell button = new TextButtonCell();
    button.addSelectHandler(new SelectHandler() {

        @Override// w  ww .  j a  v a2s .  c om
        public void onSelect(SelectEvent event) {
            Context c = event.getContext();
            int row = c.getIndex();
            Plant p = store.get(row);
            Info.display("Event", "The " + p.getName() + " was clicked.");
        }
    });
    nameColumn.setCell(button);

    DateCell dateCell = new DateCell();
    dateCell.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {

        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            Info.display("Date Selected", "You selected "
                    + DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(event.getValue()));
        }
    });
    dateCell.setPropertyEditor(
            new DateTimePropertyEditor(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

    ColumnConfig<Plant, Date> availableColumn = new ColumnConfig<Plant, Date>(properties.available(), 170,
            "Date");
    availableColumn.setColumnTextStyle(SafeStylesUtils.fromTrustedString("padding: 2px 3px;"));
    availableColumn.setCell(dateCell);

    ListStore<String> lights = new ListStore<String>(new ModelKeyProvider<String>() {
        @Override
        public String getKey(String item) {
            return item;
        }
    });

    lights.add("Mostly Shady");
    lights.add("Mostly Sunny");
    lights.add("Shade");
    lights.add("Sunny");
    lights.add("Sun or Shade");

    ColumnConfig<Plant, String> lightColumn = new ColumnConfig<Plant, String>(properties.light(), 130, "Light");
    lightColumn.setColumnTextStyle(SafeStylesUtils.fromTrustedString("padding: 2px 3px;"));

    ComboBoxCell<String> lightCombo = new ComboBoxCell<String>(lights, new LabelProvider<String>() {
        @Override
        public String getLabel(String item) {
            return item;
        }
    });
    lightCombo.addSelectionHandler(new SelectionHandler<String>() {

        @Override
        public void onSelection(SelectionEvent<String> event) {
            CellSelectionEvent<String> sel = (CellSelectionEvent<String>) event;
            Plant p = store.get(sel.getContext().getIndex());
            Info.display("Lightness Selected", p.getName() + " selected " + event.getSelectedItem());
        }
    });
    lightCombo.setTriggerAction(TriggerAction.ALL);
    lightCombo.setForceSelection(true);

    lightColumn.setCell(lightCombo);
    lightCombo.setWidth(110);

    ColumnConfig<Plant, String> colorColumn = new ColumnConfig<Plant, String>(properties.color(), 140, "Color");
    colorColumn.setColumnTextStyle(SafeStylesUtils.fromTrustedString("padding: 2px 3px;"));

    // This next line only works with any appearance that extends from Base
    ColorPaletteBaseAppearance appearance = GWT.create(ColorPaletteAppearance.class);
    appearance.setColumnCount(6);

    ColorPaletteCell colorPalette = new ColorPaletteCell(appearance, COLORS, COLORS) {
        @Override
        public boolean handlesSelection() {
            return true;
        }
    };
    colorPalette.addSelectionHandler(new SelectionHandler<String>() {

        @Override
        public void onSelection(SelectionEvent<String> event) {
            Info.display("Color Selected", "You selected " + event.getSelectedItem());
        }
    });
    colorColumn.setCell(colorPalette);

    ColumnConfig<Plant, Integer> difficultyColumn = new ColumnConfig<Plant, Integer>(properties.difficulty(),
            150, "Durability");
    SliderCell slider = new SliderCell() {
        @Override
        public boolean handlesSelection() {
            return true;
        }
    };
    slider.setWidth(140);
    difficultyColumn.setCell(slider);

    final ColumnConfig<Plant, Double> progressColumn = new ColumnConfig<Plant, Double>(properties.progress(),
            150, "Progress");
    final ProgressBarCell progress = new ProgressBarCell() {
        @Override
        public boolean handlesSelection() {
            return true;
        }
    };
    progress.setProgressText("{0}% Complete");
    progress.setWidth(140);
    progressColumn.setCell(progress);

    List<ColumnConfig<Plant, ?>> l = new ArrayList<ColumnConfig<Plant, ?>>();
    l.add(nameColumn);
    l.add(availableColumn);
    l.add(lightColumn);
    l.add(colorColumn);
    l.add(difficultyColumn);
    l.add(progressColumn);
    ColumnModel<Plant> cm = new ColumnModel<Plant>(l);

    store = new ListStore<Plant>(properties.key());

    List<Plant> plants = new ArrayList<Plant>(TestData.getPlants());
    for (Plant p : plants) {
        p.setColor(COLORS[Random.nextInt(4)]);
    }

    store.addAll(plants);

    final Grid<Plant> grid = new Grid<Plant>(store, cm);
    grid.setBorders(true);
    grid.getView().setAutoExpandColumn(nameColumn);
    grid.getView().setTrackMouseOver(false);

    grid.getColumnModel()
            .addColumnWidthChangeHandler(new CellColumnResizer<Plant, Double>(grid, progressColumn, progress));

    FramedPanel cp = new FramedPanel();
    cp.setHeadingText("Cell Grid Example");
    cp.setWidget(grid);
    cp.setPixelSize(920, 410);
    cp.addStyleName("margin-10");

    cp.setButtonAlign(BoxLayoutPack.CENTER);
    cp.addButton(new TextButton("Reset", new SelectHandler() {

        @Override
        public void onSelect(SelectEvent event) {
            store.rejectChanges();
        }
    }));

    cp.addButton(new TextButton("Save", new SelectHandler() {

        @Override
        public void onSelect(SelectEvent event) {
            store.commitChanges();
        }
    }));
    return cp;
}

From source file:com.mycompany.client.MyApplication2.java

License:Apache License

/**
 * Deferred initialization method, called from {@link #onModuleLoad()}.
 *///from w ww . j  av a 2 s.  c  o  m
private void onModuleLoad2() {
    // Create a boundary panel to constrain all drag operations
    AbsolutePanel boundaryPanel = new AbsolutePanel();
    boundaryPanel.setPixelSize(400, 300);
    boundaryPanel.addStyleName("getting-started-blue");

    // Create a drop target on which we can drop labels
    AbsolutePanel targetPanel = new AbsolutePanel();
    targetPanel.setPixelSize(300, 200);
    targetPanel.addStyleName("getting-started-blue");

    // Add both panels to the root panel
    RootPanel.get().add(boundaryPanel);
    boundaryPanel.add(targetPanel, 40, 40);

    // Create a DragController for each logical area where a set of draggable
    // widgets and drop targets will be allowed to interact with one another.
    PickupDragController dragController = new PickupDragController(boundaryPanel, true);

    // Positioner is always constrained to the boundary panel
    // Use 'true' to also constrain the draggable or drag proxy to the boundary panel
    dragController.setBehaviorConstrainedToBoundaryPanel(false);

    // Allow multiple widgets to be selected at once using CTRL-click
    dragController.setBehaviorMultipleSelection(true);

    // create a DropController for each drop target on which draggable widgets
    // can be dropped
    DropController dropController = new AbsolutePositionDropController(targetPanel);

    // Don't forget to register each DropController with a DragController
    dragController.registerDropController(dropController);

    // create a few randomly placed draggable labels
    for (int i = 1; i <= 5; i++) {
        // create a label and give it style
        Label label = new Label("Label #" + i, false);
        label.addStyleName("getting-started-label");

        // add it to the DOM so that offset width/height becomes available
        targetPanel.add(label, 0, 0);

        // determine random label location within target panel
        int left = Random.nextInt(DOMUtil.getClientWidth(targetPanel.getElement()) - label.getOffsetWidth());
        int top = Random.nextInt(DOMUtil.getClientHeight(targetPanel.getElement()) - label.getOffsetHeight());

        // move the label
        targetPanel.setWidgetPosition(label, left, top);

        // make the label draggable
        dragController.makeDraggable(label);
    }
}

From source file:com.philbeaudoin.quebec.client.utils.GwtRandomShuffler.java

License:Apache License

/**
 * A Fisher-Yates shuffle inspired from the Java source code, restricted to small ArrayList.
 * @param list The list to shuffle//from  w w  w  .  j  a v a 2 s  . c om
 * @param seed The seed to use.
 */
@Override
public <T> void shuffle(ArrayList<T> list, long seed) {
    int size = list.size();
    for (int i = size; i > 1; i--) {
        swap(list, i - 1, Random.nextInt(i));
    }
}

From source file:com.pronoiahealth.olhie.client.utils.Utils.java

License:Open Source License

/**
 * Gets a random integer
 * 
 * @return
 */
public static String getRandom() {
    return "" + Random.nextInt(100000);
}

From source file:com.qtitools.player.client.util.RandomizedSet.java

License:Open Source License

/**
 * return element from the set. element will be removed
 *///  w ww . j av  a 2 s  .c o m
public T pull() {
    if (elements.size() == 0)
        return null;

    int index = Random.nextInt(elements.size());
    T item = elements.get(index);
    elements.remove(index);

    return item;
}

From source file:com.risevision.viewer.client.controller.ViewerGadgetController.java

License:Open Source License

@SuppressWarnings("unused")
private String addVersionNumber(String url) {
    int queryLocation = url.indexOf(".xml");
    if (queryLocation != -1) {
        String versionString = "%3Fv%3D" + Random.nextInt(10000);
        queryLocation += ".xml".length();

        if (queryLocation < url.length()) {
            url = url.substring(0, queryLocation) + versionString + url.substring(queryLocation, url.length());
        } else {//w  w w . j a v a2  s  .  c  o  m
            url = url + versionString;
        }
    } else {
        // TODO: handle cases where the Gadget is obtained through an API not a static .XML file.
    }
    return url;
}