List of usage examples for com.google.gwt.user.client Random nextInt
public static native int nextInt(int upperBound) ;
int
between 0 (inclusive) and upperBound
(exclusive) with roughly equal probability of returning any particular int
in this range. From source file:net.s17fabu.vip.gwt.showcase.client.content.lists.CwTree.java
License:Apache License
/** * Create a dynamic tree that will add a random number of children to each * node as it is clicked./*from ww w . j a va 2 s . c o m*/ * * @return the new tree */ private Tree createDynamicTree() { // Create a new tree Tree dynamicTree = new Tree(); // Add some default tree items for (int i = 0; i < 5; i++) { TreeItem item = dynamicTree.addItem(constants.cwTreeItem() + " " + i); // Temporarily add an item so we can expand this node item.addItem(""); } // Add a handler that automatically generates some children dynamicTree.addOpenHandler(new OpenHandler<TreeItem>() { public void onOpen(OpenEvent<TreeItem> event) { TreeItem item = event.getTarget(); if (item.getChildCount() == 1) { // Close the item immediately item.setState(false, false); // Add a random number of children to the item String itemText = item.getText(); int numChildren = Random.nextInt(5) + 2; for (int i = 0; i < numChildren; i++) { TreeItem child = item.addItem(itemText + "." + i); child.addItem(""); } // Remove the temporary item when we finish loading item.getChild(0).remove(); // Reopen the item item.setState(true, false); } } }); // Return the tree return dynamicTree; }
From source file:next.celebs.dao.NamesDao.java
License:Apache License
public String getRandomName() { int i = Math.abs(Random.nextInt(names.size() - 1)); String n = names.get(i);/* www .j a v a2s . c o m*/ if (!n.startsWith("<div")) { return n; } else { return getRandomName(); } }
From source file:next.celebs.ui.MiscUtils.java
License:Apache License
public static int getTimeout() { int timeout = Math.abs(Random.nextInt(1000)); if (timeout < 1) { return 1; }//from w w w . j a va2 s. com return timeout; }
From source file:next.tablet.client.black.LeftMenu.java
License:Apache License
private void clearLeftMenuRandom() { for (final ImageButton btn : buttons) { int timeout = Random.nextInt(1000); Timer t = new Timer() { public void run() { btn.setEnabled(false);/*ww w . j a v a 2 s. co m*/ NMorphStyle eff = CUtil.moveHorizEffect(0, -btn.getOffsetWidth(), btn.getElement(), null, 100, 0); eff.play(); } }; t.schedule(timeout); } }
From source file:next.tablet.client.black.LeftMenu.java
License:Apache License
public void resetButtons(final ImageButton selectedBtn) { for (final ImageButton btn : buttons) { if (!btn.equals(selectedBtn) && !btn.isEnabled()) { int timeout = Random.nextInt(1000); Timer t = new Timer() { public void run() { NMorphStyle eff = CUtil.moveHorizEffect(-btn.getOffsetWidth(), 0, btn.getElement(), new Command() { @Override public void execute() { btn.setEnabled(true); }//from w w w. j av a 2s .c om }, 50, 100); eff.play(); } }; t.schedule(timeout); } } }
From source file:nl.mpi.tg.eg.experiment.client.view.ColourPickerCanvasView.java
License:Open Source License
public void setRandomColour() { final int randomHue = Random.nextInt(360); setHue("hsl(" + randomHue + ",100%,50%)"); final int red = Random.nextInt(255); final int green = Random.nextInt(255); final int blue = Random.nextInt(255); selectedColourData = new ColourData((int) red, (int) green, (int) blue); selectedColourPanel.getElement().setAttribute("style", "background:rgb(" + (int) red + "," + (int) green + "," + (int) blue + ")"); }
From source file:nl.ru.languageininteraction.synaesthesia.client.model.UserResults.java
License:Open Source License
public void addDummyResults(StimuliGroup stimuliGroup) { final StimulusResponseGroup stimulusResponseGroup = new StimulusResponseGroup(); results.put(stimuliGroup, stimulusResponseGroup); for (Stimulus stimulus : stimuliGroup.getStimuli()) { stimulusResponseGroup.addResponse(stimulus, new StimulusResponse( new ColourData(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255)), new Date(), Random.nextDouble())); stimulusResponseGroup.addResponse(stimulus, new StimulusResponse( new ColourData(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255)), new Date(), Random.nextDouble())); stimulusResponseGroup.addResponse(stimulus, new StimulusResponse( new ColourData(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255)), new Date(), Random.nextDouble())); }/*from w ww . j a v a 2s . co m*/ }
From source file:org.aksw.TripleCheckMate.shared.sparql.Endpoint.java
License:Apache License
public String getQueryforRandomResource() { int offset = Random.nextInt(760129); String from = ""; for (String g : graphs) from += " FROM <" + g + "> "; return " SELECT ?s " + from + " WHERE { ?s foaf:isPrimaryTopicOf ?o } LIMIT 1 OFFSET " + offset; }
From source file:org.aksw.TripleCheckMate.shared.sparql.Endpoint.java
License:Apache License
public String getQueryforRandomClassResource(String classURI, long maxRand) { int offset = Random.nextInt((int) maxRand); String from = ""; for (String g : graphs) from += " FROM <" + g + "> "; return " SELECT ?s " + from + " WHERE { ?s rdf:type <" + classURI + "> } LIMIT 1 OFFSET " + offset; }
From source file:org.apache.oozie.tools.workflowgenerator.client.OozieWorkflowGenerator.java
License:Apache License
/** * Initialize node tree-view menu on left side * * @return/* ww w . j a v a 2 s . c o m*/ */ public Tree initNodeTree() { Tree t = new Tree(); // Action Node Tree TreeItem actionTree = new TreeItem("Action Node"); TreeItem mrTree = new TreeItem("MapReduce"); mrTree.addItem("Streaming"); mrTree.addItem("Pipes"); actionTree.addItem(mrTree); actionTree.addItem("Pig"); actionTree.addItem("Java"); actionTree.addItem("FS"); actionTree.addItem("Subworkflow"); actionTree.addItem("SSH"); actionTree.addItem("Shell"); actionTree.addItem("Email"); // Control Node Tree TreeItem controlTree = new TreeItem("Control Node"); controlTree.addItem("Start"); controlTree.addItem("End"); controlTree.addItem("Kill"); controlTree.addItem("Fork/Join"); controlTree.addItem("Decision"); t.addItem(actionTree); t.addItem(controlTree); // Event Handler t.addSelectionHandler(new SelectionHandler<TreeItem>() { @Override public void onSelection(SelectionEvent<TreeItem> event) { TreeItem item = event.getSelectedItem(); String name = item.getText(); if (name.equals("MapReduce")) { MapReduceActionWidget w = new MapReduceActionWidget(OozieWorkflowGenerator.this); w.setName("MR_".concat( nodeCount.get(NodeType.MAPREDUCE) != null ? nodeCount.get(NodeType.MAPREDUCE).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Streaming")) { StreamingActionWidget w = new StreamingActionWidget(OozieWorkflowGenerator.this); w.setName("Streaming_".concat( nodeCount.get(NodeType.STREAMING) != null ? nodeCount.get(NodeType.STREAMING).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Pipes")) { PipesActionWidget w = new PipesActionWidget(OozieWorkflowGenerator.this); w.setName("Pipes_" .concat(nodeCount.get(NodeType.PIPES) != null ? nodeCount.get(NodeType.PIPES).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Pig")) { PigActionWidget w = new PigActionWidget(OozieWorkflowGenerator.this); w.setName("Pig_".concat( nodeCount.get(NodeType.PIG) != null ? nodeCount.get(NodeType.PIG).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Java")) { JavaActionWidget w = new JavaActionWidget(OozieWorkflowGenerator.this); w.setName("Java_".concat( nodeCount.get(NodeType.JAVA) != null ? nodeCount.get(NodeType.JAVA).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("FS")) { FSActionWidget w = new FSActionWidget(OozieWorkflowGenerator.this); w.setName("FS_".concat( nodeCount.get(NodeType.FS) != null ? nodeCount.get(NodeType.FS).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("SSH")) { SSHActionWidget w = new SSHActionWidget(OozieWorkflowGenerator.this); w.setName("SSH_".concat( nodeCount.get(NodeType.SSH) != null ? nodeCount.get(NodeType.SSH).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Email")) { EmailActionWidget w = new EmailActionWidget(OozieWorkflowGenerator.this); w.setName("Email_" .concat(nodeCount.get(NodeType.EMAIL) != null ? nodeCount.get(NodeType.EMAIL).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Shell")) { ShellActionWidget w = new ShellActionWidget(OozieWorkflowGenerator.this); w.setName("Shell_" .concat(nodeCount.get(NodeType.SHELL) != null ? nodeCount.get(NodeType.SHELL).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Subworkflow")) { SubWFActionWidget w = new SubWFActionWidget(OozieWorkflowGenerator.this); w.setName("SubWF_" .concat(nodeCount.get(NodeType.SUBWF) != null ? nodeCount.get(NodeType.SUBWF).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Start")) { if (start == null) { StartNodeWidget w = new StartNodeWidget(OozieWorkflowGenerator.this); start = w; addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } } else if (name.equals("End")) { if (end == null) { EndNodeWidget w = new EndNodeWidget(OozieWorkflowGenerator.this); w.setName("End"); end = w; addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } } else if (name.equals("Kill")) { if (kill == null) { KillNodeWidget w = new KillNodeWidget(OozieWorkflowGenerator.this); w.setName("Kill"); kill = w; addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } } else if (name.equals("Fork/Join")) { ForkNodeWidget fork = new ForkNodeWidget(OozieWorkflowGenerator.this); fork.setName("Fork_".concat( nodeCount.get(NodeType.FORK) != null ? nodeCount.get(NodeType.FORK).toString() : "0")); addWidget(fork, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); JoinNodeWidget join = new JoinNodeWidget(OozieWorkflowGenerator.this); join.setName("Join_".concat( nodeCount.get(NodeType.JOIN) != null ? nodeCount.get(NodeType.JOIN).toString() : "0")); addWidget(join, 90 + Random.nextInt(30), 30 + Random.nextInt(30)); } else if (name.equals("Decision")) { DecisionNodeWidget w = new DecisionNodeWidget(OozieWorkflowGenerator.this); w.setName("Decision_".concat( nodeCount.get(NodeType.DECISION) != null ? nodeCount.get(NodeType.DECISION).toString() : "0")); addWidget(w, 30 + Random.nextInt(30), 30 + Random.nextInt(30)); } } }); return t; }