/** * Sets the components widget representation and initializes its properties. * * <p>To be called from implementing constructor. * * @param widget components visual representation in designer */ void initComponent(Widget widget) { // Widget needs to be initialized before the component itself so that the component properties // can be reflected by the widget initWidget(widget); // Capture mouse and click events in onBrowserEvent(Event) sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK); // Add the special name property and set the tooltip String name = componentName(); setTitle(name); addProperty(PROPERTY_NAME_NAME, name, null, new TextPropertyEditor()); // TODO(user): Ensure this value is unique within the project using a list of // already used UUIDs // Set the component's UUID // The default value here can be anything except 0, because YoungAndroidProjectServce // creates forms with an initial Uuid of 0, and Properties.java doesn't encode // default values when it generates JSON for a component. addProperty(PROPERTY_NAME_UUID, "-1", null, new TextPropertyEditor()); changeProperty(PROPERTY_NAME_UUID, "" + Random.nextInt()); editor.getComponentPalettePanel().configureComponent(this); }
private HTMLPanel createJob(String jobType) { final HTMLPanel p = JobPanels.createJobPanel(jobType); TextBox jobName = new TextBox(); jobName.setName("jobName"); jobName.setText(jobType + "_" + projectName + "_" + Random.nextInt()); jobName.setVisible(false); p.add(jobName); final Button deleteButton = new Button("delete"); deleteButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { deletePanel(p); } }); p.addAndReplaceElement(deleteButton, "delete"); if(jobType.equals("cron")) { addCronToggleButton(p, deleteButton); } activePanels.add(p); return p; }
private void drawAccount(Canvas cubeBin, String url) { if (url == null || "".equals(url.trim())) { url = "blue.png"; } if (cubeBin != null) { int width = cubeBin.getWidth(); final Img img = new Img(); img.setLeft(Random.nextInt(width - 50)); img.setTop(Random.nextInt(240)); img.setWidth(48); img.setHeight(48); img.setParentElement(cubeBin); img.setSrc(url); img.setCanDragReposition(true); // img.addClickHandler(new ClickHandler() { // public void onClick(ClickEvent event) { // img.destroy(); // } // }); img.redraw(); } }
private void drawPicture(Canvas cubeBin, String url, String accountId) { if (url == null || "".equals(url.trim())) { url = "blue.png"; } if (cubeBin != null) { int width = cubeBin.getWidth(); // DrawableObjectWithAccount object = new DrawableObjectWithAccount(url, Random.nextInt(width - 100), Random.nextInt(240), cubeBin); if (accountMap.get(accountId) != null && accountMap.get(accountId).getPicture()!=null){ url = accountMap.get(accountId).getPicture(); } DrawableObject object = new DrawableObject(url,Random.nextInt(width - 100), Random.nextInt(240), cubeBin); // object.setAccount(accountMap.get(accountId)); object.redraw(); } }
public static double getRandomManipulatedDoubleBetween(double upper, double lower) { double factor = Random.nextDouble(); double max,min; if (upper > lower) { max = upper; min = lower; } else { max = lower; min = upper; } double range = (max - min) /3; double randomBit = factor * range; return min + randomBit; }
public static double getRandomDoubleBetween(double upper, double lower) { double factor = Random.nextDouble(); double max,min; if (upper > lower) { max = upper; min = lower; } else { max = lower; min = upper; } double range = max - min; double randomBit = factor * range; return min + randomBit; }
@UiHandler("rectBtn") public void onRectangleBtnClicked(ClickEvent event) { if (rectangleContainer != null) { rectangleContainer.clear(); 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); } rectangleContainer.addAll(shapes); rectangleContainer.repaint(); } }
/** * Create a new random {@link ContactInfo}. * * @return the new {@link ContactInfo}. */ @SuppressWarnings("deprecation") private ContactInfo createContactInfo() { ContactInfo contact = new ContactInfo(nextValue(categories)); contact.setLastName(nextValue(LAST_NAMES)); if (Random.nextBoolean()) { // Male. contact.setFirstName(nextValue(MALE_FIRST_NAMES)); } else { // Female. contact.setFirstName(nextValue(FEMALE_FIRST_NAMES)); } // Create a birthday between 20-80 years ago. int year = (new Date()).getYear() - 21 - Random.nextInt(61); contact.setBirthday(new Date(year, Random.nextInt(12), 1 + Random.nextInt(31))); // Create an address. int addrNum = 1 + Random.nextInt(999); String addrStreet = nextValue(STREET_NAMES); String addrSuffix = nextValue(STREET_SUFFIX); contact.setAddress(addrNum + " " + addrStreet + " " + addrSuffix); return contact; }
private static JsArray<AreaSeries> createSeries() { JsArray<AreaSeries> series = JavaScriptObject.createArray().cast(); AreaSeries s = SeriesBuilder .create() .withFillColor("rgba(220,220,220,0.5)") .withStoreColor("rgba(220,220,220,1)") .withPointColor("rgba(220,220,220,1)") .withPointStrokeColor("#fff") .withData( new double[] { Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400) }) .get(); series.push(s); series.push(SeriesBuilder .create() .withFillColor("rgba(151,187,205,0.5)") .withStoreColor("rgba(151,187,205,1)") .withPointColor("rgba(151,187,205,1)") .withPointStrokeColor("#fff") .withData( new double[] { Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400), Random.nextInt(400) }) .get()); return series; }
protected void addSymbol() { symbols.type(Type.values()[Random.nextInt(Type.values().length)]); symbols.size(Random.nextInt(2500) + 25); svg.append("path") .classed(css.symboldemo(), true) .attr("transform", Transform .parse("") .translate(Random.nextInt(width), Random.nextInt(height)).toString()) .attr("d", symbols.generate(1.0)) .style("fill", Colors.rgb(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255)).toHexaString()); }
protected void testEasingFunction(final EasingFunction e1, final EasingFunction e2) { // test the extreme values assertEquals(0.0, e1.ease(0)); assertEquals(1.0, e1.ease(1)); assertEquals(0.0, e2.ease(0)); assertEquals(1.0, e2.ease(1)); Selection selection = D3.select(sandbox).append("div"); // pass it to Transition.ease1 // D3.select(sandbox).append("div") // .attr("foo", "stuff") selection.transition().duration(1000).ease(e1) .attr("foobar", Integer.toString(Random.nextInt())) .transition() .ease(e2) .attr("foobar", Integer.toString(Random.nextInt())); }
/** * 调用评论信息 * * @access public * @return string */ public static void insertComments(int type, String id, HttpServletRequest request, ShopConfigWrapper scw) { //TODO /* 验证码相关设置 */ // ShopConfigWrapper.getDefaultConfig().get("captcha") if(false) { request.setAttribute("enabledCaptcha", true); request.setAttribute("rand", Random.nextInt()); } else { request.setAttribute("enabledCaptcha", false); } request.setAttribute("username", request.getSession().getAttribute(IWebConstants.KEY_USER_NAME)); request.setAttribute("email", request.getSession().getAttribute(IWebConstants.KEY_USER_EMAIL)); request.setAttribute("commentType", type); request.setAttribute("id", id); Map<String, Object> cmt = LibMain.assignComment(id, type, 1, SpringUtil.getCommentManager(), scw); request.setAttribute("comments", cmt.get("comments")); request.setAttribute("pager", cmt.get("pager")); return; }
/** * Generate random stock prices. */ private void refreshWatchList() { final double MAX_PRICE = 100.0; // $100.00 final double MAX_PRICE_CHANGE = 0.02; // +/- 2% StockPrice[] prices = new StockPrice[stocks.size()]; for (int i = 0; i < stocks.size(); i++) { double price = Random.nextDouble() * MAX_PRICE; double change = price * MAX_PRICE_CHANGE * (Random.nextDouble() * 2.0 - 1.0); prices[i] = new StockPrice(stocks.get(i), price, change); } updateTable(prices); }
private void init() { setStyleName("n52_sensorweb_client_imagebutton"); // int length = this.size + 2 * this.margin; // this.setWidth(length); // this.setHeight(length); String loaderId = "loader_" + (LoaderManager.getInstance().getCount() + Random.nextInt(10000)); this.loader = new LoaderImage(loaderId, "../img/mini_loader_bright.gif", this); this.setID(this.id); this.setSrc(this.icon); this.setShowHover(true); this.setShowRollOver(this.showRollOver); this.setShowDownIcon(this.showDown); this.setShowFocusedAsOver(false); this.setCursor(Cursor.POINTER); if (View.getView().isShowExtendedTooltip()) { this.setTooltip(this.extendedTooltip); } else { this.setTooltip(this.shortToolTip); } }
/** * Place a new widget to paint panel * * @param widget */ public void addWidget(final BaseWidget widget) { int h = this.scrollPanel.getOffsetHeight(); int w = this.scrollPanel.getOffsetWidth(); int offsetx = this.scrollPanel.getHorizontalScrollPosition(); int offsety = this.scrollPanel.getVerticalScrollPosition(); int x = offsetx + 4 * w / 9 + Random.nextInt(100); int y = offsety + 2 * h / 7 + Random.nextInt(100); addWidget(widget, x, y); }
public FillStyle() { this.normalColor = StyleFactory.stringToColour( String.valueOf(Random.nextInt())); this.hoverColor = DEFAULT_HOVER_COLOR; this.selectedColor = DEFAULT_SELECTED_COLOR; this.fillOpacity = DEFAULT_OPACITY; }
/** * Crea un mapa de estilos por defecto, aplicando color normal * uno obtenido de manera aleatoria. * * @return */ public static StyleMap createDefaultStyleMap() { String default_normal_color = String.valueOf(Random.nextInt()); return createStyleMap( StyleFactory.stringToColour(default_normal_color), FillStyle.DEFAULT_SELECTED_COLOR, FillStyle.DEFAULT_HOVER_COLOR, null, null); }
/** * Constructs GadgetWidget for testing. */ private GadgetWidget() { clientInstanceId = nextClientInstanceId++; clientInstanceLogLabel = "[" + clientInstanceId + "]"; prefElements = CollectionUtils.createStringMap(); stateElements = CollectionUtils.createStringMap(); rpcToken = "" + ((Long.valueOf(Random.nextInt()) << 32) | (Long.valueOf(Random.nextInt()) & 0xFFFFFFFFL)); }
@Override public void run() { //Choose the first background image randomly backgroundImageIndex = Random.nextInt( mainBackgroundImageURLs.size() ) ; //Choose the logo image randomly logoTimeImageIndex = Random.nextInt( logoTimeImageURLs.size() ) ; //Set the background image and its size updateMainImagesAndSizes(); //Reschedule to run in 30 minutes this.schedule( 1800000 ); }
public static CredentialsInfo build(String username, RealmSecurityInfo realmInfo, String rawPassword) throws NoSuchAlgorithmException { // compute the digest auth... String fullDigestAuth = username + ":" + realmInfo.getRealmString() + ":" + rawPassword; MessageDigest md = MessageDigest.getInstance("MD5"); String digestAuthHash = genHash(md, fullDigestAuth, 32); String basicAuthSalt = null; String basicAuthHash = null; // compute the basic auth hash... basicAuthSalt = Integer.toString(Random.nextInt(), Character.MAX_RADIX); // we only have 8 characters to hold it... if (basicAuthSalt != null) { int len = basicAuthSalt.length(); int start, end; if (len > 8) { start = 1; end = start + 8; } else { start = 0; end = len; } basicAuthSalt = basicAuthSalt.substring(start, end); } // RealmSecurityInfo would need to be augmented if additional // encrypted format parameters are allowed. // Must match SpringSecurity BasicPasswordEncoder for constructing salted // string. String fullBasicAuth = rawPassword + "{" + basicAuthSalt + "}"; basicAuthHash = SHA1.calcSHA1(fullBasicAuth); // hopefully this matches these actions: // MessageDigest sha1d = MessageDigest.getInstance("SHA-1"); // basicAuthHash = genHash(sha1d, fullBasicAuth, 40); return new CredentialsInfo(username, digestAuthHash, basicAuthHash, basicAuthSalt); }
private JsArray<Integer> getRandomIndexes(int quantity, JsArray<Integer> excludes) { int number; if(excludes.length() == quantity) return excludes; do { number = Random.nextInt(size()); } while (excludes.contains(number)); return getRandomIndexes(quantity, excludes.add(number)); }
private void __login(String sessionId, String login) { LoginModel loginModel = LoginModel.getInstance(); loginModel.setLoggedIn(true); loginModel.setLogin(login); loginModel.setSessionId(sessionId); if (loginView != null) SchedulerController.this.loginView.destroy(); this.loginView = null; this.schedulerView = new SchedulerPage(this); this.executionController.getJobsController().fetchJobs(true); this.startTimer(); String lstr = ""; if (login != null) { lstr += " as " + login; } Settings.get().setSetting(SESSION_SETTING, sessionId); if (login != null) { Settings.get().setSetting(LOGIN_SETTING, login); } else { Settings.get().clearSetting(LOGIN_SETTING); } // this cookie is reset to a random int on every login: // if another session in another tab has a different localSessionNUm // than the one in the domain cookie, then we exit this.localSessionNum = "" + System.currentTimeMillis() + "_" + Random.nextInt(); Cookies.setCookie(LOCAL_SESSION_COOKIE, this.localSessionNum); LogModel.getInstance().logMessage("Connected to " + SchedulerConfig.get().getRestUrl() + lstr + " (sessionId=" + loginModel.getSessionId() + ", login=" + loginModel.getLogin() + ")"); }
private void __login(String sessionId, String login) { LoginModel loginModel = LoginModel.getInstance(); loginModel.setLoggedIn(true); loginModel.setLogin(login); loginModel.setSessionId(sessionId); if (this.loginPage != null) { this.loginPage.destroy(); this.loginPage = null; } this.rmPage = new RMPage(this); this.fetchRMMonitoring(); this.fetchNodesLimit(); this.startTimer(); Settings.get().setSetting(SESSION_SETTING, sessionId); if (login != null) { Settings.get().setSetting(LOGIN_SETTING, login); } else { Settings.get().clearSetting(LOGIN_SETTING); } String lstr = ""; if (login != null) { lstr += " as " + login; } // this cookie is reset to a random int on every login: // if another session in another tab has a different localSessionNUm // than the one in the domain cookie, then we exit this.localSessionNum = "" + System.currentTimeMillis() + "_" + Random.nextInt(); Cookies.setCookie(LOCAL_SESSION_COOKIE, this.localSessionNum); LogModel.getInstance().logMessage("Connected to " + Config.get().getRestUrl() + lstr + " (sessionId=" + loginModel.getSessionId() + ")"); }
/** * Randomly shuffle the list in-place. */ public static void shuffle(List<?> list) { int size = list.size(); for (int i=size; i>1; i--) { Collections.swap(list, i-1, Random.nextInt(i)); } }
@Override public void getCategories(AsyncCallback<List<String>> async) { // Fake a delay for the demo new Timer() { @Override public void run() { async.onSuccess(categories); } }.schedule(Math.min(200, Random.nextInt(500))); }
private void drawPicture(Canvas cubeBin, String url, String accountId) { if (url == null || "".equals(url.trim())) { url = "blue.png"; } if (cubeBin != null) { int width = cubeBin.getWidth(); DrawableObjectWithAccount object = new DrawableObjectWithAccount(url,Random.nextInt(width - 100), Random.nextInt(240), cubeBin); object.setAccount(accountMap.get(accountId)); object.redraw(); } }
@Override protected void onUpdate(double progress) { if (delayCount == 0) { panel.clear(); panel.add(new HTML(text)); for (int i = 0; i < rolls.size(); ++i) { panel.add(new Image(diceImageList.get(Random.nextInt(18)))); } } delayCount++; if (delayCount == delay) { delayCount = 0; } }
private void addEmergencyEntropy() { // Iterate for up to a second. We measure the time between successive generations // of a random number of iterations over the the generator and feed this // as seed. In addition, we feed information about the current window. // Peforming a random number of iterations also discards a random number of // bytes from the generator, thus increasing the work for an attacker to recreate the // stream. This is a pretty low quality source of entropy, and high security // applications should use the reserveEntropy mechanism to avoid fallback to this // mechanism if the random output needs to be unguessable. For applications where // the random output goes in the clear (IV, Salt) this should be sufficient. if (isEmergency) return; isEmergency = true; byte[] bytesToDiscard = new byte[(Math.abs(Random.nextInt()) % 256) * blockSize]; long start = System.currentTimeMillis(); addEntropy(EMERGENCY_SEED_ID, 0.0, ByteArrayUtils.toBytes(start)); addEntropy(EMERGENCY_SEED_ID, 0.0, windowInfoAsBytes()); long curr = start; int count = 0; do { engineNextBytes(bytesToDiscard); curr = System.currentTimeMillis(); addEntropy(EMERGENCY_SEED_ID, 0.0, ByteArrayUtils.toBytes(curr)); byte[] b = new byte[4]; engineNextBytes(b); bytesToDiscard = new byte[(Math.abs(ByteArrayUtils.toInteger(b)) % 256) * blockSize]; count++; } while(curr - start < 1000); addEntropy(EMERGENCY_SEED_ID, 0.0, ByteArrayUtils.toBytes(count)); isEmergency = false; }
private void generateRandomEvents() { int screenX = 0; int screenY = 0; int x = 320; int y = 240; for (int i=0; i < 60; i++) { int xDelta = Random.nextInt(11) - 5; int yDelta = Random.nextInt(11) - 5; screenX += xDelta; x += xDelta; screenY += yDelta; y += yDelta; switch(Random.nextInt(4)) { case 0: Event.fireNativePreviewEvent(Document.get().createMouseOverEvent(0, screenX, screenY, x, y, false, false, false, false, 0, RootPanel.getBodyElement())); break; case 1: Event.fireNativePreviewEvent(Document.get().createMouseOutEvent(0, screenX, screenY, x, y, false, false, false, false, 0, RootPanel.getBodyElement())); break; case 2: Event.fireNativePreviewEvent(Document.get().createMouseDownEvent(0, screenX, screenY, x, y, false, false, false, false, 0)); break; case 3: Event.fireNativePreviewEvent(Document.get().createMouseUpEvent(0, screenX, screenY, x, y, false, false, false, false, 0)); break; } } }
public void testCanLoadDefaultInstanceAndSeedIt() { Security.addProvider(CryptoGwtProvider.INSTANCE); SecureRandom secureRandom = new SecureRandom(); for (int i=0; i < 64; i++) { secureRandom.setSeed(Random.nextInt()); } }
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 + ")"); }
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())); } }
private void shuffleList(List<InfluenceAnswerViewInterface<Object>> list) { int n = list.size(); for (int i = 0; i < n; i++) { int change = i + Random.nextInt(n - i); InfluenceAnswerViewInterface<Object> helper = list.get(i); list.set(i, list.get(change)); list.set(change, helper); } }
@Override public void onFinish(IUploader uploader) { if (uploader.getStatus() == Status.SUCCESS) { UploadedInfo serverInfo = uploader.getServerInfo(); logger.log(Level.INFO, "fileUrl=" + serverInfo.getFileUrl()); logger.log(Level.INFO, "fileName=" + serverInfo.getFileName()); hasMenus.updateTeacher(serverInfo.getFileName() + "?v" + Random.nextInt()); } }
public void onMapInitialized(MapInitializationEvent event) { CanvasContainer container = mapPresenter.getContainerManager().addWorldCanvasContainer(); final TracingLayer layer = new TracingLayer(mapPresenter.getViewPort(), container); mapPresenter.getLayersModel().addLayer(layer); mapPresenter.getLayersModelRenderer().setAnimated(layer, true); Timer timer = new Timer() { private boolean zoomOut; @Override public void run() { View endView = mapPresenter.getViewPort().asView(getNextBounds(), ZoomOption.LEVEL_CLOSEST); mapPresenter.getViewPort().registerAnimation( NavigationAnimationFactory.createZoomIn(mapPresenter, endView)); } private Bbox getNextBounds() { if (zoomOut) { layer.setEnabled(false); zoomOut = false; return new Bbox(-5000000, -5000000, 10000000, 10000000); } else { layer.setEnabled(true); double x = (Random.nextDouble() - 0.5) * 5000000; double y = (Random.nextDouble() - 0.5) * 5000000; double width = 5000; double height = 5000; zoomOut = true; return new Bbox(x, y, width, height); } } }; timer.scheduleRepeating(2000); }
@UiHandler("polyBtn") public void onPolyBtnClicked(ClickEvent event) { if (polygonContainer != null) { polygonContainer.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); } polygonContainer.addAll(shapes); polygonContainer.repaint(); } }
@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); } }