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() ;

Source Link

Document

Returns a random int between -2147483648 and 2147483647 (inclusive) with roughly equal probability of returning any particular int in this range.

Usage

From source file:cc.alcina.framework.gwt.client.provider.ClientRandomProvider.java

License:Apache License

@Override
public int nextInt() {
    return Random.nextInt();
}

From source file:ch.sebastienzurfluh.swissmuseum.core.client.view.pagewidget.ResourceWidget.java

License:Open Source License

@Override
public void notifyObserver(Observable source) {
    for (ResourceData resource : model.getAllNeededResources()) {
        // The following check is sufficient to determine unicity as there cannot be
        // two different resources with the same id, be it an IMAGE and a VIDEO.
        // This is explicitly reflected in the CakeConnector/MySQL by the use of a single
        // table Resources with an unique key column 'id'.
        if (resource.getReference().equals(this.getReference())) {
            switch (resource.getResourceType()) {
            case IMAGE:
                Image image = new Image(resource.getURL());
                image.setStyleName(primaryStyle + imageExtension);
                image.setAltText(resource.getTitle());

                final ResourceGallery imageGallery = new ResourceGallery(image.getUrl(), resource.getTitle(),
                        resource.getDetails());
                image.addClickHandler(new ClickHandler() {
                    @Override/*from   w ww  .j  a  v  a  2s.  com*/
                    public void onClick(ClickEvent event) {
                        imageGallery.center();
                    }
                });
                resourceContainer.setWidget(image);
                break;
            case VIDEO:
                int id = Random.nextInt();
                HTML video = new HTML("<a href='" + resource.getURL() + "' target='_blank'>" + "<video id='"
                        + id + "' autobuffer class='" + primaryStyle + videoExtension + "'>" + "<source src='"
                        + resource.getURL() + "' " + "type='video/ogg; codecs=\"theora, vorbis\"'/>"
                        + "</video></a>");
                resourceContainer.setWidget(video);

                //               Video video = Video.createIfSupported();
                //               if (video == null) {
                //                  resourceContainer.setWidget(new Label("Your browser is not able to play"
                //                        + " this video"));
                //               } else {
                //                  video.setSrc(resource.getURL());
                //                  video.setStyleName(primaryStyle+videoExtension);
                //                  resourceContainer.setWidget(video);
                //               }
                break;
            default:
                // Destroy the object. It is never referenced outside of this object, but is
                // attached to it's parent.
                this.removeFromParent();
            }

            title.setText(resource.getTitle());
            details.setText(resource.getDetails());

            eventBus.fireEvent(new PageModifiedEvent());

            model.allNeededResourcesObservable.unsubscribeObserver(this);
            return;
        }
    }
}

From source file:com.chinarewards.gwt.license.client.login.view.LoginWidget.java

@Override
public void changeImage() {
    int rand = Random.nextInt();
    String url = "kaptcha.jpg?dt=" + rand;
    verifyImage.setUrl(url);
}

From source file:com.client.hp.hpl.jena.shared.uuid.LibUUID.java

License:Apache License

static int makeRandom() {
    //        SecureRandom sRandom = new SecureRandom() ; // SecureRandom.getInstance("SHA1PRNG");

    // ---- Seeding.
    // If no setSeed() call is made before a nextBytes call, the
    // generator "self seeds".  If a setSeed() is called before
    // any nextBytes call, no self seeding is done.  We use the
    // self seeding and our own bytes.

    // Access the internal seed generator.
    //        byte[] seed1 = sRandom.generateSeed(16) ;
    //        byte[] seed2 = LibUUID.makeSeed() ;
    //        // seeds are cumulative
    //        sRandom.setSeed(seed1) ;                     
    //        sRandom.setSeed(seed2) ;                     
    return Random.nextInt();

}

From source file:com.dimdim.conference.ui.sharing.client.ResourceSharingPanel.java

License:Open Source License

private String getParamAddedUrl() {
    String url = waitingPageFrame.container.getCollaborationesources().getWaitingPageURL();
    String paramToAdd = "";
    if (url.indexOf('?') != -1) {
        paramToAdd = "&";
    } else {/*  ww w .  j av  a 2s  . co  m*/
        paramToAdd = "?";
    }
    if (this.me.isHost()) {
        url = url + paramToAdd + "role=host";
    } else {
        url = url + paramToAdd + "role=attendee";
    }
    url = url + "&cflag=" + Random.nextInt();
    return url;
}

From source file:com.dimdim.conference.ui.sharing.client.ResourceSharingPanel.java

License:Open Source License

private void syncCobUrl(UIResourceObject res) {
    String url = "http://" + ConferenceGlobals.userInfoDictionary.getStringValue("dms_cob_server_address")
            + "/content/" + res.getUrl();
    //String url = ConferenceGlobals.baseWebappURL+"cob/"+ConferenceGlobals.conferenceKey+"/"+res.getResourceId();
    //Window.alert("inside sync cobrowse... "+this.activeResource);
    if (UIGlobals.isActivePresenter(me)) {
        url += "/p_cache.html";
    } else {/*from w  w w .  j  ava  2  s . co  m*/
        url += "/a_cache.html";
    }
    //Window.alert("setting the url to "+url);
    this.coBrowseFrame.setUrl(url + "?cflag=" + Random.nextInt());
    this.resizePanel();
    //writeResName(false, null, res.getResourceName());
    writeCobResName(res.getResourceName());
    setLockMask();
}

From source file:com.fullmetalgalaxy.client.game.GameEngine.java

License:Open Source License

/**
 * rpc call to run the current action./* w  ww.j  av  a 2s  .c  om*/
 * Clear the current action.
 */
public void runSingleAction(AnEvent p_action) {
    if (m_lastModelUpdateClientID != 0) {
        // no i18n as HMI is lock, so it shouldn't occur
        Window.alert("An action is already send to server... wait for server response.");
        return;
    }
    AppMain.instance().startLoading();
    m_lastModelUpdateClientID = Random.nextInt();
    ModelFmpUpdate modelUpdate = new ModelFmpUpdate(getGame());
    modelUpdate.setClientID(m_lastModelUpdateClientID);

    try {
        if (!GameEngine.model().isLogged() && (getGame().getGameType() == GameType.MultiPlayer
                || getGame().getGameType() == GameType.Initiation)) {
            // no i18n as HMI won't allow that. so unusual
            throw new RpcFmpException("You must be logged to do this action");
        }
        // do not check player is logged to let him join action
        // action.check();
        if (getGame().getGameType() == GameType.MultiPlayer || getGame().getGameType() == GameType.Initiation) {
            AppMain.instance().scheduleCheckChannelTimer();
            modelUpdate.setFromPageId(AppMain.instance().getPageId());
            modelUpdate.setFromPseudo(AppMain.instance().getMyAccount().getPseudo());
            modelUpdate.setGameEvents(new ArrayList<AnEvent>());
            modelUpdate.getGameEvents().add(p_action);
            AppMain.getRpcService().runModelUpdate(modelUpdate, m_callbackEvents);
        } else {
            LocalGame.runEvent(p_action, m_callbackEvents, this);
        }
    } catch (RpcFmpException ex) {
        Window.alert(ex.getLocalizedMessage());
        m_lastModelUpdateClientID = 0;
        AppMain.instance().stopLoading();
        getActionBuilder().cancel();
        AppRoot.getEventBus().fireEvent(new ModelUpdateEvent(GameEngine.model()));
    } catch (Throwable p_caught) {
        Window.alert("Unknown error on client: " + p_caught);
        m_lastModelUpdateClientID = 0;
        AppMain.instance().stopLoading();
        getActionBuilder().cancel();
    }
}

From source file:com.fullmetalgalaxy.client.game.GameEngine.java

License:Open Source License

/**
 * rpc call to run the current action./*w  ww  . j  a v  a2  s  .c  o m*/
 * Clear the current action.
 */
public void runCurrentAction() {
    if (m_lastModelUpdateClientID != 0) {
        Window.alert("Une action a dj t envoy au serveur... sans rponse pour l'instant");
        return;
    }
    AppMain.instance().startLoading();
    m_lastModelUpdateClientID = Random.nextInt();
    ModelFmpUpdate modelUpdate = new ModelFmpUpdate(getGame());
    modelUpdate.setClientID(m_lastModelUpdateClientID);

    try {
        if (!GameEngine.model().isJoined()) {
            // no i18n ?
            throw new RpcFmpException("you didn't join this game.");
        }
        // action.check();
        getActionBuilder().unexec();
        if (getGame().getGameType() == GameType.MultiPlayer || getGame().getGameType() == GameType.Initiation) {
            AppMain.instance().scheduleCheckChannelTimer();
            // then send request
            modelUpdate.setFromPageId(AppMain.instance().getPageId());
            modelUpdate.setFromPseudo(AppMain.instance().getMyAccount().getPseudo());
            modelUpdate.setGameEvents(new ArrayList<AnEvent>());
            modelUpdate.getGameEvents().addAll(getActionBuilder().getActionList());
            AppMain.getRpcService().runModelUpdate(modelUpdate, m_callbackEvents);
        } else {
            LocalGame.runAction(getActionBuilder().getActionList(), m_callbackEvents, this);
        }
    } catch (RpcFmpException ex) {
        Window.alert(ex.getLocalizedMessage());
        m_lastModelUpdateClientID = 0;
        AppMain.instance().stopLoading();
        getActionBuilder().cancel();
    } catch (Throwable p_caught) {
        Window.alert("Unknown error on client: " + p_caught);
        m_lastModelUpdateClientID = 0;
        AppMain.instance().stopLoading();
        getActionBuilder().cancel();
        AppRoot.getEventBus().fireEvent(new ModelUpdateEvent(GameEngine.model()));
    }
}

From source file:com.google.appinventor.client.editor.simple.components.MockComponent.java

License:Open Source License

/**
 * Sets the components widget representation and initializes its properties.
 *
 * <p>To be called from implementing constructor.
 *
 * @param widget  components visual representation in designer
 *///from w  ww.  j  a v  a2 s . c  o m
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);
}

From source file:com.isotrol.impe3.pms.gui.client.widget.design.Design.java

License:Open Source License

/**
 * Dynamically adds the passed CSS to the document, and stores in {@link #additionalCss} the resulting
 * <code>&lt;link rel="stylesheet"&gt;</code><br/>
 * @param css/*  w w w .j a v a2  s  .  c  om*/
 */
private void addCss(StylesheetDTO css) {

    String id = Integer.valueOf(Random.nextInt()).toString();

    Element eLink = DOM.createElement(TAG_LINK);
    eLink.setAttribute(ATTRIBUTE_ID, id);
    eLink.setAttribute(ATTRIBUTE_REL, "stylesheet");
    eLink.setAttribute(ATTRIBUTE_TYPE, "text/css");
    eLink.setAttribute(ATTRIBUTE_HREF, css.getUrl());
    if (css.getMedia() != null) {
        eLink.setAttribute(ATTRIBUTE_MEDIA, css.getMedia());
    }

    Element eHead = XDOM.getDocument().getElementsByTagName(TAG_HEAD).getItem(0);
    eHead.appendChild(eLink);

    additionalCss.put(id, eLink);
}