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:org.celstec.arlearn2.portal.client.htmlDisplay.MatrixCollectionCRSDisplay.java

License:Open Source License

private void drawPicture(Canvas cubeBin, String url, String accountId) {
    if (url == null || "".equals(url.trim())) {
        url = "blue.png";
    }//from  w w w  .j a  va2 s. c o  m
    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();
    }
}

From source file:org.celstec.arlearn2.portal.client.htmlDisplay.ObjectCollectionCRSDisplay.java

License:Open Source License

private void drawPicture(Canvas cubeBin, String url, String accountId) {
    if (url == null || "".equals(url.trim())) {
        url = "blue.png";
    }/* w  ww  .  jav  a 2s. c o m*/
    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();
    }
}

From source file:org.celstec.arlearn2.portal.client.htmlDisplay.SingleChoiceDisplay.java

License:Open Source License

private void drawAccount(Canvas cubeBin, String url) {
    if (url == null || "".equals(url.trim())) {
        url = "blue.png";
    }// w w w. ja v a2s.c o  m
    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();
    }
}

From source file:org.cimav.client.db.domain.DeptoDatabase.java

public void load() {

    dataProvider.getList().clear();/*from w w w  .  j a va  2s.  co m*/

    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(Resource.HEADER_CONTENT_TYPE, "application/json; charset=utf-8");

    Resource rb = new Resource(URL_REST, headers);
    rb.get().send(Ajax.jsonCall(new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getLocalizedMessage());
            System.out.println("---Vacio--- ");
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {

            List<Departamento> deptosProvider = dataProvider.getList();

            JSONArray array = null;
            if (response instanceof JSONObject) {
                JSONObject obj = (JSONObject) response;
                array = obj.get("departamento").isArray(); //TODO que el elemento-root se llame 'Departamento'
            } else if (response instanceof JSONArray) {
                array = response.isArray();
            } else {
                throw new NullPointerException("EL arreglo de Departamentos es Nulo en: " + URL_REST);
            }

            for (int i = 0; i < array.size(); i++) {
                JSONObject item = array.get(i).isObject();

                Integer id = (int) item.get("id").isNumber().doubleValue();

                String codigo = item.get("codigo") != null ? item.get("codigo").isString().stringValue()
                        : "NO_COD_" + Random.nextInt(100000);
                String nombre = item.get("nombre") != null ? item.get("nombre").isString().stringValue()
                        : "NO_NOM_" + Random.nextInt(100000);
                Integer status = item.get("status") != null ? (int) item.get("status").isNumber().doubleValue()
                        : -1;

                Departamento depto = new Departamento(id, codigo, nombre, status);

                // Remove the contact first so we don't add a duplicate.
                deptosProvider.remove(depto);
                deptosProvider.add(depto);
            }

            InfoView.show(array.size() + " registros recargados");
        }
    }));

    /*
     rb.get().send(new JsonCallback() {
     @Override
     public void onFailure(Method method, Throwable exception) {
     Window.alert(exception.getLocalizedMessage());
     System.out.println("---Vacio--- ");
     }
            
     @Override
     public void onSuccess(Method method, JSONValue response) {
                                
     List<Departamento> deptosProvider = dataProvider.getList();
            
     JSONArray array = null;
     if (response instanceof JSONObject) {
     JSONObject obj = (JSONObject) response;
     array = obj.get("departamento").isArray(); //TODO que el elemento-root se llame 'Departamento'
     } else if (response instanceof JSONArray) {
     array = response.isArray();
     } else {
     throw new NullPointerException("EL arreglo de Departamentos es Nulo en: " + URL_REST);
     }
                
     for (int i = 0; i < array.size(); i++) {
     JSONObject item = array.get(i).isObject();
                    
     Integer id = (int) item.get("id").isNumber().doubleValue();
                    
     String codigo = item.get("codigo") != null ? item.get("codigo").isString().stringValue() : "NO_COD_" +  Random.nextInt(100000);
     String nombre = item.get("nombre") != null ? item.get("nombre").isString().stringValue() : "NO_NOM_"  + Random.nextInt(100000);
     Integer status = item.get("status") != null ? (int) item.get("status").isNumber().doubleValue() : -1;
            
     Departamento depto = new Departamento(id, codigo, nombre, status);
                    
     // Remove the contact first so we don't add a duplicate.
     deptosProvider.remove(depto);
     deptosProvider.add(depto);
     }
                
     }
     });
     */
}

From source file:org.cobogw.pongy.client.BarComputer.java

License:Apache License

public void move(Ball ball) {
    final int bty = ball.getTopY();
    final int bby = ball.getBottomY();
    final int ct = getTopY();
    final int cb = getBottomY();
    if (ball.getX() < reactonx || ball.getDirX() < 0) {
        return;//from  w ww .jav  a 2s .  c o  m
    }
    final boolean rand = Random.nextInt(randupper) > reactrand ? true : false;
    final float r2 = maxspeed * (Random.nextInt(randupper) / (float) randupper);

    if (ct + margin > bty && rand) {
        super.move(-1 * r2);
    } else if (cb + margin < bby && rand) {
        super.move(1 * r2);
    }
}

From source file:org.cobogw.pongy.client.Pongy.java

License:Apache License

public void initializeFeature(WaveFeature feature) {
    wave = feature;//from w w  w .  j  ava  2s  . c  o m
    state = wave.getState();

    view.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            if (wave == null || wave.isPlayback()) {
                return;
            }
            final char keyCode = Character.toUpperCase((char) event.getNativeKeyCode());

            //        if ('N' == keyCode && playerLeft == thisPlayer) {
            //          setStateDelta(STATE_KEYS.PLAYER_LEFT_POINTS, "0");
            //          setStateDelta(STATE_KEYS.PLAYER_RIGHT_POINTS, "0");
            //          //submitStateDelta(STATE_KEYS.GAME_STATE, GAME_STATE.NEW_MATCH);
            //        } else
            if ('S' == keyCode && GAME_STATE.NEW_MATCH.equals(getGameState(STATE_KEYS.GAME_STATE))) {
                if (playerLeft == thisPlayer) {
                    setStateDelta(STATE_KEYS.PLAYER_LEFT_READY, "1");
                    submitStateDelta(STATE_KEYS.GAME_STATE, GAME_STATE.NEW_MATCH);
                } else {
                    submitStateDelta(STATE_KEYS.PLAYER_RIGHT_READY, "1");
                }
                //        } else if ('P' == keyCode) {
                //        togglePauze();
            } else {
                if (thisPlayer != null) {
                    thisPlayer.setKeyState(true, keyCode);
                }
            }
        }
    });
    view.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            if (wave != null && !wave.isPlayback() && thisPlayer != null) {
                thisPlayer.setKeyState(false, (char) event.getNativeKeyCode());
            }
        }
    });
    wave.addParticipantUpdateEventHandler(new ParticipantUpdateEventHandler() {
        public void onUpdate(ParticipantUpdateEvent event) {
            initParticipants();
        }
    });
    wave.addStateUpdateEventHandler(new StateUpdateEventHandler() {
        public void onUpdate(StateUpdateEvent event) {
            if (state == null) {
                state = wave.getState();
            }
            final String gs = getGameState(STATE_KEYS.GAME_STATE, GAME_STATE.NEW);

            switch (GAME_STATE.valueOf(gs)) {
            case NEW:
                break;
            case INIT:
                view.showSingleLine(textInviteSomeone);
                break;
            case NEW_MATCH:
                final boolean thisPlayerReady = (thisPlayer == playerLeft
                        && getGameState(STATE_KEYS.PLAYER_LEFT_READY) != null)
                        || (thisPlayer == playerRight && getGameState(STATE_KEYS.PLAYER_RIGHT_READY) != null);
                final boolean otherPlayerReady = (otherPlayer == playerLeft
                        && getGameState(STATE_KEYS.PLAYER_LEFT_READY) != null)
                        || (otherPlayer == playerRight && getGameState(STATE_KEYS.PLAYER_RIGHT_READY) != null);

                if (thisPlayerReady && otherPlayerReady) {
                    setStateDelta(STATE_KEYS.PLAYER_LEFT_READY, (String) null);
                    setStateDelta(STATE_KEYS.PLAYER_RIGHT_READY, (String) null);
                    setStateDelta(STATE_KEYS.BALL_WAIT_LEFT_PLAYER, "");
                    setStateDelta(STATE_KEYS.BALL_WAIT_RIGHT_PLAYER, "");
                    setStateDelta(STATE_KEYS.BALL_START, String.valueOf(Random.nextInt(1000) > 500));
                    submitStateOnlyLeftDelta(STATE_KEYS.GAME_STATE, GAME_STATE.ON);
                } else if (thisPlayerReady) {
                    view.showSingleLine(texWaitingForOtherPlayer);
                } else if (otherPlayerReady) {
                    view.showSingleLine(texWaitingForThisPlayer);
                } else if ("0".equals(getGameState(STATE_KEYS.PLAYER_LEFT_POINTS, "0"))
                        && "0".equals(getGameState(STATE_KEYS.PLAYER_RIGHT_POINTS, "0"))) {
                    view.showInstructions(instructionsText);
                } else {
                    view.showSingleLine(textWaitingForBothPlayers);
                }
                break;
            case ON:
                if (!matchStarted) {
                    newMatch();
                }
                final String bwl = getGameState(STATE_KEYS.BALL_WAIT_LEFT_PLAYER, "");
                final String bwr = getGameState(STATE_KEYS.BALL_WAIT_RIGHT_PLAYER, "");

                if ("".equals(bwl) && "".equals(bwr)
                        && (!bwl.equals(lastWLPStatus) || !bwl.equals(lastWRPStatus))) {
                    ball.resumeBall();
                }
                lastWLPStatus = bwl;
                lastWRPStatus = bwr;
                break;
            //        case PAUZE:
            //           TODO implement pause
            //           Game paused by on of the players, wait for both to acknowledge
            //           continue
            //          break;
            case END:
                matchStarted = false;
                showPoints();
                ball.setVisible(false);
                lastwinner = PLAYER.PLAYER_LEFT.equals(getGameState(STATE_KEYS.LAST_WINNER))
                        ? PLAYER.PLAYER_LEFT
                        : PLAYER.PLAYER_RIGHT;
                // Game ended, update score and send game on after timeout.
                final boolean youWin = (PLAYER.PLAYER_LEFT.equals(lastwinner) && playerLeft == thisPlayer)
                        || (PLAYER.PLAYER_RIGHT.equals(lastwinner) && playerRight == thisPlayer);
                if (youWin) {
                    handleMatchOver();
                }
                view.showWinner("YOU " + (youWin ? "WIN!!" : "LOSE!!"));
                if (!wave.isPlayback() && youWin) {
                    new Timer() {
                        @Override
                        public void run() {
                            submitStateDelta(STATE_KEYS.GAME_STATE, GAME_STATE.NEW_MATCH);
                        }
                    }.schedule(winnertimeout);
                }
                break;
            }
        }
    });
}

From source file:org.ebayopensource.turmeric.monitoring.client.model.DummyMetricsQueryServiceImpl.java

License:Open Source License

/**
 * Gets the metric data./*from  w  ww .  j  a  v  a2s.co  m*/
 * 
 * @param criteria
 *            the criteria
 * @param resourceCriteria
 *            the resource criteria
 * @param callback
 *            the callback
 * @see org.ebayopensource.turmeric.monitoring.client.model.MetricsQueryService#getMetricData(org.ebayopensource.turmeric.monitoring.client.model.MetricCriteria,
 *      org.ebayopensource.turmeric.monitoring.client.model.MetricResourceCriteria,
 *      com.google.gwt.user.client.rpc.AsyncCallback)
 */
public void getMetricData(MetricCriteria criteria, MetricResourceCriteria resourceCriteria,
        AsyncCallback<MetricData> callback) {

    MetricData result = new MetricData();
    // result.setRestUrl(URL.encode(MetricsDataRequest.getRestURL(criteria, resourceCriteria)));
    result.setMetricCriteria(criteria);
    result.setMetricResourceCriteria(resourceCriteria);
    boolean nonExistantService = false;
    if (resourceCriteria.resourceEntityRequests != null && resourceCriteria.resourceEntityRequests.size() > 0) {
        nonExistantService = resourceCriteria.resourceEntityRequests.get(0).resourceEntityNames
                .contains("ANonExistantMyService");
    }
    List<MetricGroupData> metrics = new ArrayList<MetricGroupData>();
    result.setReturnData(metrics);
    if (!nonExistantService) {// if the service name is != that 'ANonexistantService'
        if ("CallCount".equals(criteria.metricName)) {

            int max = (resourceCriteria.resourceEntityRequests != null
                    && resourceCriteria.resourceEntityRequests.size() > 1 ? 1 : 10);
            for (int i = 0; i < max; i++) {
                MetricGroupDataImpl rd = new MetricGroupDataImpl();
                CriteriaInfoImpl ci = new CriteriaInfoImpl();
                rd.setCriteriaInfo(ci);
                metrics.add(rd);
                if (resourceCriteria.resourceEntityResponseType.equals(Entity.Operation)) {
                    // Was a specific operation requested?
                    if (resourceCriteria.resourceEntityRequests != null) {
                        for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                            if (r.resourceEntityType.equals(Entity.Operation))
                                ci.setOperationName(r.resourceEntityNames.get(0));
                        }
                    }
                    // Make up some
                    if (ci.getOperationName() == null)
                        ci.setOperationName("Op" + i);
                } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Service)) {
                    if (resourceCriteria.resourceEntityRequests != null) {
                        for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                            if (r.resourceEntityType.equals(Entity.Service))
                                ci.setServiceName(r.resourceEntityNames.get(0));
                        }
                    }
                    if (ci.getServiceName() == null)
                        ci.setServiceName("Service" + i);
                } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Consumer)) {
                    ci.setConsumerName("Consumer" + i);
                }

                int s1 = Random.nextInt(1000);
                rd.setCount1(new Double(s1).toString());
                int s2 = Random.nextInt(1000);
                rd.setCount2(new Double(s2).toString());
                int s3 = Random.nextInt(100);
                rd.setDiff(new Double(s3).toString());

            }
        } else if ("ResponseTime".equals(criteria.metricName)) {

            int max = (resourceCriteria.resourceEntityRequests != null
                    && resourceCriteria.resourceEntityRequests.size() > 1 ? 1 : 10);

            for (int i = 0; i < max; i++) {
                MetricGroupDataImpl rd = new MetricGroupDataImpl();
                CriteriaInfoImpl ci = new CriteriaInfoImpl();
                rd.setCriteriaInfo(ci);
                metrics.add(rd);
                if (resourceCriteria.resourceEntityResponseType.equals(Entity.Service)) {
                    // Was a specific service requested?
                    if (resourceCriteria.resourceEntityRequests != null) {
                        for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                            if (r.resourceEntityType.equals(Entity.Service))
                                ci.setServiceName(r.resourceEntityNames.get(0));
                        }
                    }
                    // otherwise make up some
                    if (ci.getServiceName() == null)
                        ci.setServiceName("Service " + i);
                } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Operation)) {
                    // Was a specific operation requested?
                    if (resourceCriteria.resourceEntityRequests != null) {
                        for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                            if (r.resourceEntityType.equals(Entity.Operation))
                                ci.setOperationName(r.resourceEntityNames.get(0));
                        }
                    }
                    // otherwise make up some
                    if (ci.getOperationName() == null)
                        ci.setOperationName("Op" + i);

                } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Consumer)) {
                    // Was a specific consumer requested?
                    if (resourceCriteria.resourceEntityRequests != null) {
                        for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                            if (r.resourceEntityType.equals(Entity.Consumer))
                                ci.setConsumerName(r.resourceEntityNames.get(0));
                        }
                    }
                    // otherwise make up some
                    if (ci.getConsumerName() == null)
                        ci.setConsumerName("Consumer" + i);
                }

                double s1 = Random.nextInt(5000000) / 1.0;
                rd.setCount1(new Double(s1).toString());
                double s2 = Random.nextInt(5000000) / 1.0;
                rd.setCount2(new Double(s2).toString());
                int s3 = Random.nextInt(100);
                rd.setDiff(new Double(s3).toString());

            }

        } else if ("ErrorCount".equals(criteria.metricName)) {

            if (resourceCriteria.resourceEntityResponseType.equals(Entity.Consumer)) {
                // int max = (resourceCriteria.resourceEntityRequests != null &&
                // resourceCriteria.resourceEntityRequests.size() > 1? 2 : 10);
                int max = 2;
                for (int i = 0; i < max; i++) {
                    MetricGroupDataImpl rd = new MetricGroupDataImpl();
                    CriteriaInfoImpl ci = new CriteriaInfoImpl();
                    rd.setCriteriaInfo(ci);
                    metrics.add(rd);
                    ci.setMetricName("Err" + i);
                    ci.setConsumerName("Consumer" + i);

                    int s1 = Random.nextInt(1000);
                    rd.setCount1(new Double(s1).toString());
                    int s2 = Random.nextInt(1000);
                    rd.setCount2(new Double(s2).toString());
                    int s3 = Random.nextInt(100);
                    rd.setDiff(new Double(s3).toString());
                }
            } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Service)) {
                // int max = (resourceCriteria.resourceEntityRequests != null &&
                // resourceCriteria.resourceEntityRequests.size() > 1? 2 : 10);
                String service = null;
                if (resourceCriteria.resourceEntityRequests != null) {
                    for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                        if (r.resourceEntityType.equals(Entity.Service))
                            service = r.resourceEntityNames.get(0);
                    }
                }
                GWT.log("service=" + service);

                int max = 2;
                for (int i = 0; i < max; i++) {
                    MetricGroupDataImpl rd = new MetricGroupDataImpl();
                    CriteriaInfoImpl ci = new CriteriaInfoImpl();
                    rd.setCriteriaInfo(ci);
                    metrics.add(rd);
                    ci.setMetricName("Err" + i);
                    if (service == null)
                        ci.setServiceName("Service" + i);
                    else
                        ci.setServiceName(service);

                    int s1 = Random.nextInt(1000);
                    rd.setCount1(new Double(s1).toString());
                    int s2 = Random.nextInt(1000);
                    rd.setCount2(new Double(s2).toString());
                    int s3 = Random.nextInt(100);
                    rd.setDiff(new Double(s3).toString());
                }
            } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Operation)) {
                // int max = (resourceCriteria.resourceEntityRequests != null &&
                // resourceCriteria.resourceEntityRequests.size() > 1? 2 : 10);
                String operation = null;

                if (resourceCriteria.resourceEntityRequests != null) {
                    for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                        if (r.resourceEntityType.equals(Entity.Operation))
                            operation = r.resourceEntityNames.get(0);
                    }
                }
                GWT.log("Op=" + operation);
                int max = 2;
                for (int i = 0; i < max; i++) {
                    MetricGroupDataImpl rd = new MetricGroupDataImpl();
                    CriteriaInfoImpl ci = new CriteriaInfoImpl();
                    rd.setCriteriaInfo(ci);
                    metrics.add(rd);
                    ci.setMetricName("Err" + i);
                    if (operation == null)
                        ci.setOperationName("Op" + i);
                    else
                        ci.setOperationName(operation);

                    int s1 = Random.nextInt(1000);
                    rd.setCount1(new Double(s1).toString());
                    int s2 = Random.nextInt(1000);
                    rd.setCount2(new Double(s2).toString());
                    int s3 = Random.nextInt(100);
                    rd.setDiff(new Double(s3).toString());
                }
            } else if (resourceCriteria.resourceEntityResponseType.equals(Entity.Error)) {
                // int max = ( resourceCriteria.resourceEntityRequests!= null &&
                // resourceCriteria.resourceEntityRequests.size() > 1? 2 : 10);

                String service = null;
                String operation = null;
                if (resourceCriteria.resourceEntityRequests != null) {
                    for (ResourceEntityRequest r : resourceCriteria.resourceEntityRequests) {
                        if (r.resourceEntityType.equals(Entity.Operation))
                            operation = r.resourceEntityNames.get(0);
                        if (r.resourceEntityType.equals(Entity.Service))
                            service = r.resourceEntityNames.get(0);
                    }
                }
                int max = 2;
                for (int i = 0; i < max; i++) {
                    MetricGroupDataImpl rd = new MetricGroupDataImpl();
                    CriteriaInfoImpl ci = new CriteriaInfoImpl();
                    rd.setCriteriaInfo(ci);
                    metrics.add(rd);
                    ci.setMetricName("Err" + i);
                    if (service == null)
                        ci.setServiceName("Service" + i);
                    else
                        ci.setServiceName(service);
                    if (operation == null)
                        ci.setOperationName("Op" + i);
                    else
                        ci.setOperationName(operation);
                    int s1 = Random.nextInt(1000);
                    rd.setCount1(new Double(s1).toString());
                    int s2 = Random.nextInt(1000);
                    rd.setCount2(new Double(s2).toString());
                    int s3 = Random.nextInt(100);
                    rd.setDiff(new Double(s3).toString());
                }
            }
        }
    }

    callback.onSuccess(result);
}

From source file:org.ebayopensource.turmeric.monitoring.client.model.DummyMetricsQueryServiceImpl.java

License:Open Source License

/**
 * Gets the error data.//from   ww  w  . j  ava2 s .  c  o  m
 * 
 * @param ec
 *            the ec
 * @param mc
 *            the mc
 * @param callback
 *            the callback
 * @see org.ebayopensource.turmeric.monitoring.client.model.MetricsQueryService#getErrorData(org.ebayopensource.turmeric.monitoring.client.model.ErrorCriteria,
 *      org.ebayopensource.turmeric.monitoring.client.model.MetricCriteria,
 *      com.google.gwt.user.client.rpc.AsyncCallback)
 */
public void getErrorData(ErrorCriteria ec, MetricCriteria mc, AsyncCallback<ErrorMetricData> callback) {
    ErrorMetricData result = new ErrorMetricData();
    // result.setRestUrl(URL.encode(ErrorMetricsDataRequest.getRestURL(ec, mc)));
    result.setErrorCriteria(ec);
    result.setMetricCriteria(mc);

    List<ErrorViewData> results = new ArrayList<ErrorViewData>();
    result.returnData = results;
    // specific error requested
    if (ec.e != null) {
        // return info about the consumers
        for (int i = 0; i < 10; i++) {
            ErrorViewDataImpl evd = new ErrorViewDataImpl();
            evd.setConsumer("Consumer" + i);
            evd.setErrorCallRatio1(Random.nextDouble() * 10.0);
            evd.setErrorCallRatio2(Random.nextDouble() * 10.0);
            evd.setErrorCount1(Random.nextInt(1000));
            evd.setErrorCount2(Random.nextInt(1000));
            results.add(evd);
        }
    } else {
        GWT.log("no error requested");
        // assume for now that errors are required rather than consumers
        for (Map.Entry<String, ErrorDetail> entry : errorDetailsByName.entrySet()) {
            if (ec.category != null) {
                if (ec.category.toString().equalsIgnoreCase(entry.getValue().getCategory())) {
                    ErrorViewDataImpl evd = new ErrorViewDataImpl();
                    evd.setErrorId(entry.getValue().getId());
                    evd.setErrorName(entry.getValue().getName());
                    evd.setErrorCallRatio1(Random.nextDouble() * 10.0);
                    evd.setErrorCallRatio2(Random.nextDouble() * 10.0);
                    evd.setErrorCount1(Random.nextInt(1000));
                    evd.setErrorCount2(Random.nextInt(1000));
                    results.add(evd);
                }
            } else if (ec.severity != null) {
                if (ec.severity.toString().equalsIgnoreCase(entry.getValue().getSeverity())) {
                    ErrorViewDataImpl evd = new ErrorViewDataImpl();
                    evd.setErrorId(entry.getValue().getId());
                    evd.setErrorName(entry.getValue().getName());
                    evd.setErrorCallRatio1(Random.nextDouble() * 10.0);
                    evd.setErrorCallRatio2(Random.nextDouble() * 10.0);
                    evd.setErrorCount1(Random.nextInt(1000));
                    evd.setErrorCount2(Random.nextInt(1000));
                    results.add(evd);
                }
            } else {
                ErrorViewDataImpl evd = new ErrorViewDataImpl();
                evd.setErrorName(entry.getValue().getName());
                evd.setErrorId(entry.getValue().getId());
                evd.setErrorCallRatio1(Random.nextDouble() * 10.0);
                evd.setErrorCallRatio2(Random.nextDouble() * 10.0);
                evd.setErrorCount1(Random.nextInt(1000));
                evd.setErrorCount2(Random.nextInt(1000));
                results.add(evd);
            }

        }
    }

    callback.onSuccess(result);
}

From source file:org.eurekastreams.web.client.ui.pages.profile.settings.stream.StreamPluginConfigurationPanel.java

License:Apache License

/**
 * Private Constructor, used to switch values between Add and Edit modes.
 *
 * @param pluginDefinition//from w w w. j ava2 s  . c o  m
 *            The current plugin
 * @param model
 *            The base model.
 * @param inConfValues
 *            The configuration values for the feed
 * @param inMode
 *            The mode of the panel
 * @param feedSubId
 *            id of the feed sub.
 * @param metaData
 *            the plugin title.
 */
private StreamPluginConfigurationPanel(final GeneralGadgetDefinition pluginDefinition, final BaseModel model,
        final HashMap<String, Serializable> inConfValues, final Method inMode, final Long feedSubId,
        final GadgetMetaDataDTO metaData) {
    mode = inMode;
    confValues = inConfValues;

    formBuilder = new FormBuilder("", model, mode);
    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().streamPluginConfPanel());
    formBuilder.setVisible(false);

    final Integer random = Random.nextInt(10000);

    FlowPanel gadgetDiv = new FlowPanel();
    gadgetDiv.setVisible(false);
    gadgetDiv.getElement().setAttribute("id", "gadget-zone-render-zone-" + random.toString());
    this.add(gadgetDiv);

    spinny = new FlowPanel();
    spinny.addStyleName(StaticResourceBundle.INSTANCE.coreCss().gadgetsGadgetLoading());

    this.add(spinny);

    final BasicCheckBoxFormElement lastCheckBox = new BasicCheckBoxFormElement("Terms of Use", "EUREKA:TOS",
            "I understand that the plugin I am about to configure will import activity "
                    + "into this stream and that the content I am sharing is consistent with the Eureka "
                    + "Streams terms of service.",
            false, mode.equals(Method.UPDATE));

    Session.getInstance().getEventBus().addObserver(GotSystemSettingsResponseEvent.class,
            new Observer<GotSystemSettingsResponseEvent>() {

                public void update(final GotSystemSettingsResponseEvent event) {
                    lastCheckBox.addAdditionalInstructions(new HTML(event.getResponse().getPluginWarning()));
                }
            });
    SystemSettingsModel.getInstance().fetch(null, true);

    lastCheckBox.addStyleName(StaticResourceBundle.INSTANCE.coreCss().streamPluginCheckbox());

    formBuilder.setOnCancelHistoryToken(History.getToken());
    formBuilder.addWidget(new PluginMetaDataDescriptionPanel(metaData));
    formBuilder.addLastFormElement(lastCheckBox);

    formBuilder.addFormElement(new ValueOnlyFormElement("EUREKA:GROUP",
            Session.getInstance().getUrlViews().get(Session.getInstance().getUrlViews().size() - 1)));
    formBuilder.addFormElement(new JSNICommandFormElement("EUREKA:FEEDURL", "getFeedCommand"));
    formBuilder.addFormElement(new ValueOnlyFormElement("EUREKA:PLUGINID", pluginDefinition.getId()));
    formBuilder.addFormElement(new ValueOnlyFormElement("EUREKA:PLUGINTITLE", metaData.getTitle()));

    if (mode.equals(Method.UPDATE)) {
        formBuilder.addFormElement(new ValueOnlyFormElement("EUREKA:FEEDSUBID", feedSubId));
    }

    this.add(formBuilder);

    formBuilder.addOnCancelCommand(new Command() {
        public void execute() {
            Session.getInstance().getEventBus().notifyObservers(new StreamPluginsUpdateCanceledEvent());
        }
    });

    setUpAPI();

    gadgetRenderer.registerSingleGadgetInContainer(pluginDefinition.getUrl(), Long.valueOf(random),
            pluginDefinition.getId(), null);

    DeferredCommand.addCommand(new Command() {
        public void execute() {
            // gadgetRenderer.renderGadget(random.toString());
            gadgetRenderer.renderGagdets();
        }
    });
}

From source file:org.geomajas.gwt2.example.client.sample.rendering.CanvasRenderingPanel.java

License:Open Source License

private String getRandomRGB(double d) {
    int r = Random.nextInt(256);
    int g = Random.nextInt(256);
    int b = Random.nextInt(256);
    return "rgba(" + r + "," + g + "," + b + "," + d + ")";
}