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:com.databasepreservation.visualization.client.common.lists.AsyncTableCell.java
public AsyncTableCell(Filter filter, boolean justActive, Facets facets, String summary, boolean selectable, boolean exportable, int initialPageSize, int pageSizeIncrement, O object) { super();/*from www . j a v a 2 s.c om*/ this.initialPageSize = initialPageSize; this.pageSizeIncrement = pageSizeIncrement; this.object = object; if (summary == null) { summary = "summary" + Random.nextInt(1000); } this.filter = filter; this.justActive = justActive; this.facets = facets; this.selectable = selectable; display = new AccessibleCellTable<T>(getInitialPageSize(), (MyCellTableResources) GWT.create(MyCellTableResources.class), getKeyProvider(), summary); display.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); display.setLoadingIndicator(new HTML(SafeHtmlUtils.fromSafeConstant( "<div class='spinner'><div class='double-bounce1'></div><div class='double-bounce2'></div></div>"))); configure(display); this.dataProvider = new MyAsyncDataProvider<T>(display, new IndexResultDataProvider<T>() { @Override public void getData(Sublist sublist, ColumnSortList columnSortList, AsyncCallback<IndexResult<T>> callback) { AsyncTableCell.this.getData(sublist, columnSortList, callback); } }) { @Override protected void fireChangeEvent(IndexResult<T> result) { ValueChangeEvent.fire(AsyncTableCell.this, result); } }; dataProvider.addDataDisplay(display); if (exportable) { // mimic PageSizePager exportButtons = new FlexTable(); exportButtons.setCellPadding(0); exportButtons.setCellSpacing(0); exportVisibleButton = new Anchor("Export visible"); exportVisibleButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { AsyncTableCell.this.exportVisibleClickHandler(); } }); exportAllButton = new Anchor("Export all"); exportAllButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { AsyncTableCell.this.exportAllClickHandler(); } }); exportButtons.setWidget(0, 0, exportVisibleButton); exportButtons.setText(0, 1, " | "); exportButtons.setWidget(0, 2, exportAllButton); } resultsPager = new AccessibleSimplePager(AccessibleSimplePager.TextLocation.LEFT, (SimplePager.Resources) GWT.create(SimplePager.Resources.class), false, initialPageSize, false, false, (SimplePager.ImageButtonsConstants) GWT.create(SimplePager.ImageButtonsConstants.class)); resultsPager.setDisplay(display); pageSizePager = new PageSizePager(getPageSizePagerIncrement()); pageSizePager.setDisplay(display); createSelectAllPanel(); displayScroll = new ScrollPanel(display); displayScrollWrapper = new SimplePanel(displayScroll); add(selectAllPanel); add(displayScrollWrapper); add(resultsPager); if (exportButtons != null) { add(exportButtons); } add(pageSizePager); selectionModel = new SingleSelectionModel<>(getKeyProvider()); Handler<T> selectionEventManager = getSelectionEventManager(); if (selectionEventManager != null) { display.setSelectionModel(selectionModel, selectionEventManager); } else { display.setSelectionModel(selectionModel); } columnSortHandler = new AsyncHandler(display); display.addColumnSortHandler(columnSortHandler); display.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() { @Override public void onLoadingStateChanged(LoadingStateChangeEvent event) { if (LoadingStateChangeEvent.LoadingState.LOADED.equals(event.getLoadingState())) { handleScrollChanges(); } } }); addStyleName("my-asyncdatagrid"); resultsPager.addStyleName("my-asyncdatagrid-pager-results"); pageSizePager.addStyleName("my-asyncdatagrid-pager-pagesize"); displayScrollWrapper.addStyleName("my-asyncdatagrid-display-scroll-wrapper"); display.addStyleName("my-asyncdatagrid-display"); if (exportButtons != null) { exportButtons.addStyleName("my-asyncdatagrid-pager-pagesize"); // exportVisibleButton.addStyleName("btn btn-export btn-export-visible"); // exportAllButton.addStyleName("btn btn-export btn-export-all"); } displayScroll.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { handleScrollChanges(); } }); addValueChangeHandler(new ValueChangeHandler<IndexResult<T>>() { @Override public void onValueChange(ValueChangeEvent<IndexResult<T>> event) { selected = new HashSet<T>(); hideSelectAllPanel(); } }); Label emptyInfo = new Label(messages.noItemsToDisplay()); display.setEmptyTableWidget(emptyInfo); }
From source file:com.databasepreservation.visualization.shared.client.widgets.wcag.WCAGUtilities.java
public void makeAccessible(Element element) { if (element.getAttribute("align") != null) { String className = ""; if (element.getAttribute("align").equals("right")) { className = "alignRight"; } else if (element.getAttribute("align").equals("left")) { className = "alignLeft"; } else if (element.getAttribute("align").equals("center")) { className = "alignCenter"; } else {/*from www .jav a 2s . c o m*/ className = "alignJustify"; } element.removeAttribute("align"); element.addClassName(className); } if (INPUT_TAGNAMES.contains(element.getTagName())) { addAttributeIfNonExistent(element, "title", "t_" + Random.nextInt(1000), true); } if (element.getChildCount() > 0) { for (int i = 0; i < element.getChildCount(); i++) { if (element.getChild(i).getNodeType() == Node.ELEMENT_NODE) { makeAccessible((Element) element.getChild(i)); } } } }
From source file:com.extjs.gxt.samples.resources.client.ResourcesData.java
License:Open Source License
public static List<Country> getCountries() { List<Country> countries = new ArrayList<Country>(); countries.add(new Country("ad", "Andora", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("ae", "Arab Emirates", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("ag", "Antigua And Barbuda", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("ai", "Anguilla", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("al", "Albania", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("am", "Armenia", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("an", "Neth. Antilles", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("ao", "Angola", 100 + (Random.nextInt(110) * 100))); countries.add(new Country("ar", "Argentina", 100 + (Random.nextInt(110) * 100))); return countries; }
From source file:com.extjs.gxt.samples.resources.client.ResourcesData.java
License:Open Source License
public static List<TeamSales> getTeamSales() { List<TeamSales> teamsales = new ArrayList<TeamSales>(); for (String m : months) { int upper = 50; int a = Random.nextInt(upper); int b = Random.nextInt(upper); int c = Random.nextInt(upper); teamsales.add(new TeamSales(m, a, b, c)); }/*from ww w .j a v a 2 s . co m*/ return teamsales; }
From source file:com.freedomotic.clients.client.widgets.ContactDatabase.java
License:Apache License
/** * Create a new random {@link ContactInfo}. * * @return the new {@link ContactInfo}./*from w w w. j a v a 2s .c o m*/ */ @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; }
From source file:com.freedomotic.clients.client.widgets.ContactDatabase.java
License:Apache License
/** * Get the next random value from an array. * * @param array the array/*www . j a va2 s. c om*/ * @return a random value in the array */ private <T> T nextValue(T[] array) { return array[Random.nextInt(array.length)]; }
From source file:com.fullmetalgalaxy.client.creation.GameGenerator.java
License:Open Source License
/** * populate game with minerais token//from w ww.ja v a2s. co m */ public static void populateOres() { clearOre(); int width = getGame().getLandWidth(); int height = getGame().getLandHeight(); int ix = Random.nextInt(3); int starty = Random.nextInt(3); while (ix < width) { int iy = starty; while (iy < height) { LandType type = getGame().getLand(ix, iy); if ((ix >= 0) && (iy >= 0) && (s_oreAllowedOnLands.contains(type)) && (getGame().getToken(new AnBoardPosition(ix, iy)) == null)) { EbToken token = new EbToken(TokenType.Ore); if (s_useAllOre == true) { // an arbitrary ore distribution that keep the same overall ore value switch (Random.nextInt(9)) { case 0: case 1: token.setType(TokenType.Ore0); break; case 6: case 7: token.setType(TokenType.Ore3); break; case 8: token.setType(TokenType.Ore5); break; default: break; } } if (s_useOreGenerator == true && Math.floor(ix * 3 / width) == 1 && Math.floor(iy * 3 / height) == 1 && Random.nextInt(3) == 0) { // ore generator shall only appear in map center... token.setType(TokenType.Ore2Generator); if (s_useAllOre == true && Random.nextInt(3) == 0) { token.setType(TokenType.Ore3Generator); } } token.getPosition().setX(ix); token.getPosition().setY(iy); token.getPosition().setSector(Sector.getRandom()); token.setLocation(Location.Board); getGame().addToken(token); } iy += 3; } AnBoardPosition startPosition = new AnBoardPosition(ix, starty); // use a flat coordinate system to avoid infinite loop ! HexCoordinateSystem coodinateSystem = new HexCoordinateSystem(); startPosition = coodinateSystem.getNeighbor(startPosition, Sector.NorthEast); startPosition = coodinateSystem.getNeighbor(startPosition, Sector.NorthEast); startPosition = coodinateSystem.getNeighbor(startPosition, Sector.NorthEast); ix = startPosition.getX(); starty = startPosition.getY(); } }
From source file:com.fullmetalgalaxy.client.game.board.DlgJoinChooseColor.java
License:Open Source License
/** * //from w w w . j a v a 2 s. c om */ public DlgJoinChooseColor() { // auto hide / modal super(false, true); // Set the dialog box's caption. setText(MAppBoard.s_messages.unitsTitle()); // add company list widget // ======================= List<Company> freeCompany = new ArrayList<Company>(); for (Company company : Company.values()) { if (company != Company.Freelancer) { freeCompany.add(company); } } if (!GameEngine.model().getGame().isTeamAllowed()) { // remove already chosen company for (EbTeam team : GameEngine.model().getGame().getTeams()) { if (team.getCompany() != null && team.getCompany() != Company.Freelancer) { freeCompany.remove(team.getCompany()); } } freeCompany.add(0, Company.Freelancer); } else { m_panel.add(new HTML("<b>" + MAppBoard.s_messages.warningTeamAllowed() + "</b>")); if (GameEngine.model().getGame().getMaxTeamAllowed() <= GameEngine.model().getGame().getTeams() .size()) { // player shouldn't choose other team freeCompany.clear(); for (EbTeam team : GameEngine.model().getGame().getTeams()) { freeCompany.add(team.getCompany()); } } } for (Company company : freeCompany) { m_companySelection.addItem(company.getFullName(), company.toString()); } m_companySelection.setSelectedIndex(Random.nextInt(m_companySelection.getItemCount())); Company company = Company.valueOf(m_companySelection.getValue(m_companySelection.getSelectedIndex())); m_companyPreview.setUrl("/images/avatar/" + company + ".jpg"); m_companySelection.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent p_event) { Company company = Company .valueOf(m_companySelection.getValue(m_companySelection.getSelectedIndex())); m_companyPreview.setUrl("/images/avatar/" + company + ".jpg"); } }); Panel hpanel = new HorizontalPanel(); hpanel.add(m_companySelection); hpanel.add(m_companyPreview); m_panel.add(new HTML("<b>" + MAppBoard.s_messages.chooseCompany() + "</b>")); m_panel.add(hpanel); // add color list widget // ===================== Set<EnuColor> freeColors = null; if (GameEngine.model().getGame().getSetRegistration().size() >= GameEngine.model().getGame() .getMaxNumberOfPlayer()) { // this is a player replacement: don't allow company selection m_companySelection.setVisible(false); freeColors = GameEngine.model().getGame().getFreeRegistrationColors(); } else { freeColors = GameEngine.model().getGame().getFreePlayersColors(); } for (EnuColor color : freeColors) { if (color.getValue() != EnuColor.None) { m_colorSelection.addItem(Messages.getColorString(0, color.getValue()), "" + color.getValue()); } } m_colorSelection.setSelectedIndex(Random.nextInt(m_colorSelection.getItemCount())); // initialize company icon int colorValue = Integer.parseInt(m_colorSelection.getValue(m_colorSelection.getSelectedIndex())); EbRegistration registration = GameEngine.model().getGame().getRegistrationByColor(colorValue); if (registration != null && registration.getTeam(GameEngine.model().getGame()) != null) { m_companyPreview.setUrl( "/images/avatar/" + registration.getTeam(GameEngine.model().getGame()).getCompany() + ".jpg"); } // initialize color icon m_colorPreview.setUrl("/images/board/" + (new EnuColor(colorValue)).toString() + "/preview.jpg"); m_colorSelection.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent p_event) { int colorValue = Integer.parseInt(m_colorSelection.getValue(m_colorSelection.getSelectedIndex())); EnuColor color = new EnuColor(colorValue); m_colorPreview.setUrl("/images/board/" + color.toString() + "/preview.jpg"); m_btnOk.setEnabled(true); // for replacement: search corresponding team EbRegistration registration = GameEngine.model().getGame().getRegistrationByColor(colorValue); if (registration != null && registration.getTeam(GameEngine.model().getGame()) != null) { m_companyPreview.setUrl("/images/avatar/" + registration.getTeam(GameEngine.model().getGame()).getCompany() + ".jpg"); } } }); hpanel = new HorizontalPanel(); hpanel.add(m_colorSelection); hpanel.add(m_colorPreview); m_panel.add(new HTML("<b>" + MAppBoard.s_messages.chooseColor() + "</b>")); m_panel.add(hpanel); // add buttons // =========== hpanel = new HorizontalPanel(); // add cancel button m_btnCancel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent p_event) { hide(); } }); hpanel.add(m_btnCancel); // add OK button m_btnOk.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent p_event) { int colorValue = Integer.parseInt(m_colorSelection.getValue(m_colorSelection.getSelectedIndex())); EnuColor color = new EnuColor(colorValue); EbGameJoin action = new EbGameJoin(); Company company = Company.Freelancer; try { company = Company.valueOf(m_companySelection.getValue(m_companySelection.getSelectedIndex())); } catch (Exception e) { } action.setCompany(company); action.setGame(GameEngine.model().getGame()); action.setAccountId(AppMain.instance().getMyAccount().getId()); action.setAccount(AppMain.instance().getMyAccount()); action.setColor(color.getValue()); GameEngine.model().runSingleAction(action); hide(); } }); hpanel.add(m_btnOk); m_panel.add(hpanel); setWidget(m_panel); }
From source file:com.github.gwtbootstrap.showcase.client.CellTables.java
License:Apache License
@UiHandler("add5Entity") public void onClickAdd5Entity(ClickEvent e) { Date date = new Date(); for (int i = 0; i < 5; i++) { Person p = new Person(); p.setAge(exampleTable.getRowCount()); p.setFavorite(Favorite.values()[Random.nextInt(Favorite.values().length)]); p.setUserName("userName" + exampleTable.getRowCount()); p.setBirthDay(date);/*w w w . j a v a 2 s.c o m*/ addPerson(p); date.setTime(date.getTime() + 24 * 60 * 60 * (exampleTable.getRowCount() + 1) * 1000); } }
From source file:com.google.collide.clientlibs.invalidation.DropRecoveringInvalidationController.java
License:Open Source License
void recover() { if (isRecovering) { return;/*from w w w .ja va 2s.co m*/ } isRecovering = true; int currentClientVersion = invalidationReorderer.getNextExpectedVersion() - 1; // Disable timeout, as it would trigger a recover invalidationReorderer.setTimeoutEnabled(false); // Perform XHR, feed results into reorderer, get callbacks recoverer.recoverPayloads(objectId, currentClientVersion, new Recoverer.Callback() { @Override public void onPayloadsRecovered(JsonArray<RecoveredPayload> payloads, int currentVersion) { for (int i = 0; i < payloads.size(); i++) { RecoveredPayload payload = payloads.get(i); invalidationReorderer.acceptItem(payload.getPayload(), payload.getPayloadVersion()); } invalidationReorderer.skipToVersion(currentVersion + 1); isRecovering = false; invalidationReorderer.setTimeoutEnabled(true); } @Override public void onError() { // Consider ourselves to be in the "retrying" state during this delay timerFactory.createTimer(new Runnable() { @Override public void run() { isRecovering = false; // This will end up retrying invalidationReorderer.setTimeoutEnabled(true); } }).schedule(ERROR_RETRY_DELAY_MS + Random.nextInt(ERROR_RETRY_DELAY_MS / 10)); } }); }