Exemplo n.º 1
0
  /** This is the entry point method. */
  @Override
  public void onModuleLoad() {
    initFetcherAPI();

    cellTable = new CellTable<PlaceRecord>(PlaceRecord.KEY_PROVIDER);
    RootPanel.get("locationContainer").add(cellTable);
    cellTable.setWidth("100%", true);
    initTableColumns();
    //
    locationService.getPlaceAddress(
        new Date(),
        new AsyncCallback<List<PlaceRecord>>() {

          @Override
          public void onFailure(Throwable caught) {
            DialogBox message = new DialogBox();
            message.setTitle("failed to get place");
            message.setText(caught.getMessage());
            message.show();
          }

          @Override
          public void onSuccess(List<PlaceRecord> records) {
            List<PlaceRecord> list = dataProvider.getList();
            for (PlaceRecord palce : records) {
              list.add(palce);
            }
            dataProvider.addDataDisplay(cellTable);
            cellTable.setPageSize(list.size());
          }
        });

    processedRow = -1;
    Timer fetchTimer =
        new Timer() {
          @Override
          public void run() {
            fetchData();
          }
        };
    fetchTimer.scheduleRepeating(REFRESH_INTERVAL);

    Timer saveTimer =
        new Timer() {
          @Override
          public void run() {
            saveData();
          }
        };
    saveTimer.scheduleRepeating(SAVE_INTERVAL);
  }
Exemplo n.º 2
0
  public void run(final RootPanel rp, final String nick) {

    if (Cookies.getCookie(nick) == null) Cookies.setCookie(nick, "" + 0);

    cl.setPageSize(500);

    final Button sendMessage =
        new Button(
            "sendMessage",
            new ClickHandler() {

              public void onClick(ClickEvent event) {

                if (!message.getText().equals("")) {
                  new Post().postJson(SERVERURL, nick.toString(), message.getText());
                  message.setText("");
                }
              }
            });

    rp.get("mainDiv2").setVisible(true);
    message.getElement().setAttribute("placeholder", "Introduce your message");
    message.getElement().setAttribute("id", "message");

    cl.getElement().setAttribute("id", "chatBox");

    sendMessage.getElement().setAttribute("id", "sendMessage");
    sendMessage.setText("Send");

    vp.getElement().setAttribute("id", "verticalPanel");
    hp.getElement().setAttribute("id", "horizontalPanel");

    panel.getElement().setAttribute("id", "scroller");

    hp.add(message);
    hp.add(sendMessage);
    panel.add(cl);
    vp.add(panel);

    vp.add(hp);
    rp.get("mainDiv2").add(vp);

    Timer t =
        new Timer() {
          @Override
          public void run() {
            getMessages();

            if (chatList != null && Integer.parseInt(Cookies.getCookie(nick)) < chatList.size()) {
              cl.setRowCount(chatList.size() + 1, true);
              cl.setRowData(
                  Integer.parseInt(Cookies.getCookie(nick)),
                  chatList.subList(Integer.parseInt(Cookies.getCookie(nick)), chatList.size()));
              panel.setVerticalScrollPosition(panel.getMaximumVerticalScrollPosition() - 1);
              Cookies.setCookie(nick, "" + chatList.size());
            }
          }
        };
    t.scheduleRepeating(1000);
  }
 protected void testUntil(final long duration, final Runnable runnable) {
   delayTestFinish((int) (2 * duration));
   final long startTime = System.currentTimeMillis();
   final int interval = 500;
   timer =
       new Timer() {
         @Override
         public void run() {
           final long buffer = 4 * interval;
           if (System.currentTimeMillis() + buffer < startTime + duration) {
             boolean passed = true;
             try {
               runnable.run();
             } catch (AssertionFailedError e) {
               passed = false;
             } finally {
               if (passed) {
                 cancel();
                 finishTest();
               }
             }
           } else {
             cancel();
             runnable.run();
             finishTest();
           }
         }
       };
   timer.scheduleRepeating(interval);
   timer.run();
 }
Exemplo n.º 4
0
  public StockPresenter(final StockView view) {

    this.view = view;

    stocks = new ListVariable<StockSymbol>();

    // set up event listeners for adding a new stock
    StreamMerge.<Object>mergeStreams(
            view.addButtonClick(), view.newSymbolTextEntry().keyDown().filter(new IsEnterKeyCode()))
        .loop(
            new Effect<Object>() {
              @Override
              public void e(Object o) {
                addStock();
              }
            });

    // set up timer to refresh list automatically
    final Timer refreshTimer =
        new Timer() {
          public void run() {
            refreshWatchList();
          }
        };
    refreshTimer.scheduleRepeating(REFRESH_INTERVAL);

    // move cursor focus to the text box
    view.newSymbolTextEntry().focus().put(true);
  }
Exemplo n.º 5
0
  private void layout(final SearchSummaryItem ssi, final int depth) {

    final int row = table.getRowCount();
    final Image loading = new Image(GwtUtil.LOADING_ICON_URL);
    ssi.checkUpdate();

    table.setWidget(row, iconColIdx, loading);

    if (ssi.isLoaded()) {
      ssi.renderItem(table, row, curGroupByName);
      GwtUtil.setStyles(loading, "visibility", "hidden");
    } else {
      ssi.checkUpdate();
      table.setWidget(row, iconColIdx, loading);
      Timer timer =
          new Timer() {
            public void run() {
              ssi.checkUpdate();
              ssi.renderItem(table, row, curGroupByName);
              if (ssi.isLoaded()) {
                cancel();
                GwtUtil.setStyles(loading, "visibility", "hidden");
              }
            }
          };
      bgList.add(timer);
      timer.scheduleRepeating(1000);
    }

    if (ssi.getChildren() != null && ssi.getChildren().size() > 0) {
      for (SearchSummaryItem child : ssi.getChildren()) {
        layout(child, depth + 1);
      }
    }
  }
Exemplo n.º 6
0
  public void fade() {
    DOM.removeEventPreview(this);
    cancelDelay();
    if (fader == null) {
      fader =
          new Timer() {
            private final long start = new Date().getTime();

            @Override
            public void run() {
              /*
               * To make animation smooth, don't count that event happens
               * on time. Reduce opacity according to the actual time
               * spent instead of fixed decrement.
               */
              long now = new Date().getTime();
              long timeEplaced = now - start;
              float remainingFraction = 1 - timeEplaced / (float) fadeMsec;
              int opacity = (int) (startOpacity * remainingFraction);
              if (opacity <= 0) {
                cancel();
                hide();
              } else {
                setOpacity(getElement(), opacity);
              }
            }
          };
      fader.scheduleRepeating(FADE_ANIMATION_INTERVAL);
    }
  }
Exemplo n.º 7
0
 @Override
 public void onStateChanged(StateChangeEvent event) {
   super.onStateChanged(event);
   timer.cancel();
   if (isEnabled()) {
     timer.scheduleRepeating(getState().interval);
   }
 }
Exemplo n.º 8
0
 private void setupTimerToRefreshListAutomatically() {
   Timer refreshTimer =
       new Timer() {
         public void run() {
           refreshWatchList();
         }
       };
   refreshTimer.scheduleRepeating(REFRESH_INTERVAL);
 }
 private void initTimer() {
   timer =
       new Timer() {
         @Override
         public void run() {
           mainLoop();
         }
       };
   timer.scheduleRepeating(20);
 }
Exemplo n.º 10
0
 private void setupTimer() {
   final Timer timer =
       new Timer() {
         @Override
         public void run() {
           if (animate) {
             doUpdate();
           }
         }
       };
   timer.scheduleRepeating(REFRESH_RATE);
 }
Exemplo n.º 11
0
 public void setGoal(final int goal) {
   this.goal = goal;
   // setup timer
   final Timer timer =
       new Timer() {
         @Override
         public void run() {
           refresh(this);
         }
       };
   timer.scheduleRepeating(refreshRate);
 }
 @Override
 public void center() {
   super.center();
   Timer t =
       new Timer() {
         public void run() {
           if (scheduleEditorWizardPanel.isAttached() && scheduleEditorWizardPanel.isVisible()) {
             cancel();
           }
         }
       };
   t.scheduleRepeating(250);
 }
Exemplo n.º 13
0
 /**
  * Runs the application at the desired FPS. The application will try to call update and draw as
  * many times as the given frames per second, but it may be called less often if there is a
  * performance hit in either method.
  *
  * @param fps the number of frames per second to run the application at.
  */
 public void run(int fps) {
   initialize();
   timer =
       new Timer() {
         @Override
         public void run() {
           if (isPaused()) {
             return;
           }
           update();
         }
       };
   timer.scheduleRepeating(1000 / fps);
 }
Exemplo n.º 14
0
  @Test
  public void checkScheduleRepeating() throws Exception {
    i = 0;
    Timer timer =
        new Timer() {

          @Override
          public void run() {
            i++;
          }
        };

    timer.scheduleRepeating(500);

    Assert.assertTrue("timer should be run more than once", i > 1);
  }
Exemplo n.º 15
0
  private void adjustUpdateSpeed(int newSpeed) {
    updateSpeed = newSpeed;
    updateCmd.execute();

    if (updater != null) updater.cancel();
    if (updateSpeed == 0) {
      return;
    }
    updater =
        new Timer() {
          public void run() {
            updateCmd.execute();
          }
        };
    updater.scheduleRepeating(updateSpeed);
  }
 @Override
 public Registration scheduleRepeating(int period, final Runnable r) {
   final Timer timer =
       new Timer() {
         @Override
         public void run() {
           try {
             r.run();
           } catch (Throwable t) {
             LOG.log(Level.SEVERE, "Runnable submitted to JsEventDispatchThread failed", t);
           }
         }
       };
   timer.scheduleRepeating(period);
   return timerReg(timer);
 }
Exemplo n.º 17
0
  protected void handleClick() {

    if (isEnabled() && subMenu == null) {

      final Timer t =
          new Timer() {
            private int tcount = 0;

            @Override
            public void run() {

              if (tcount > 0) {
                cancel();

                if (checkable) {
                  setChecked(!checked);
                }

                if (menu != null && subMenu == null) {
                  ((Menu) menu).setLastSelectedItem(MenuItem.this);
                  menu.close();
                }

                getElement().removeClassName(appearance.css().menuItemActiveClass());
                getElement().removeClassName("appkit-state-selected");
                DOM.releaseCapture(getElement());

                SelectionEvent.fire(MenuItem.this, getText());

                return;
              }

              if (getElement().hasClassName(appearance.css().menuItemActiveClass())) {
                getElement().removeClassName(appearance.css().menuItemActiveClass());
                getElement().removeClassName("appkit-state-selected");
              } else {
                getElement().addClassName(appearance.css().menuItemActiveClass());
                getElement().addClassName("appkit-state-selected");
                DOM.setCapture(getElement());
                tcount++;
              }
            }
          };

      t.scheduleRepeating(50);
    }
  }
  @Override
  public void createScreen(final PageController pageController, Long modelId) {
    this.pageController = pageController;
    pageController.setBackground(Background.MENU);
    pageController.getSoundPlayer().playMenuScreenMusic();
    pageController.setScreenTitle("Select a Game to Observe");

    pageController.addScreen(screen.content);

    requestUpdateObservableGameList();

    refreshObservableGameListTimer.cancel();
    // TODO would scheduling each time we update work better?
    // updates take different amounts of time for different
    // computers/networks
    refreshObservableGameListTimer.scheduleRepeating(GAME_LIST_REFRESH_INTERVAL_MS);
  }
Exemplo n.º 19
0
 /**
  * Schedules a repeating timer to continually update the text with the pretty-date, every minute
  * until the text is more than an hour old, at which point it stops. The assumption is that nobody
  * will wait for 60+ minutes for "one hour ago" to turn into "2 hours ago"
  */
 public static void keepMakingPretty(final Date date, final String prefix, final Element element) {
   makePretty(date, prefix, element);
   if (!TIMERS.containsKey(element)) {
     Timer timer =
         new Timer() {
           @Override
           public void run() {
             makePretty(date, prefix, element);
             if (element.getInnerText().contains("hour")) {
               stopMakingPretty(element);
             }
           }
         };
     timer.scheduleRepeating(60000);
     TIMERS.put(element, timer);
   }
 }
Exemplo n.º 20
0
  @Override
  public Registration scheduleRepeating(final int period, final Runnable r) {
    Timer timer =
        new Timer() {
          private long myLastInvocation = 0L;

          @Override
          public void run() {
            long current = getCurrentTimeMillis();
            if (current - myLastInvocation < period) return;
            myLastInvocation = current;
            doExecute(r);
          }
        };
    timer.scheduleRepeating(period);
    return timerReg(timer);
  }
Exemplo n.º 21
0
 public void onChange(ChangeEvent event) {
   basenames.clear();
   for (String s : getFileNames()) {
     basenames.add(Utils.basename(s));
   }
   statusWidget.setFileNames(basenames);
   if (anyFileIsRepeated(false)) {
     statusWidget.setStatus(Status.REPEATED);
     return;
   }
   if (autoSubmit && !validateAll(basenames)) {
     return;
   }
   if (autoSubmit && fileSelected()) {
     automaticUploadTimer.scheduleRepeating(DEFAULT_AUTOUPLOAD_DELAY);
   }
   onChangeInput();
 }
Exemplo n.º 22
0
  public void shake(Command command) {
    if (!drawn) throw new IllegalStateException();
    if (command != null) commandQueue.add(command);
    if (hidden) unhide();
    if (shaking) stopShake();

    if (shakeTimer == null)
      shakeTimer =
          new Timer() {
            public void run() {
              doShake();
            }
          };

    shakeTime = 0;

    shakeTimer.scheduleRepeating(20);
    shaking = true;
  }
Exemplo n.º 23
0
  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);

    header = new Text();
    header.setText(getContent(""));
    add(header);

    connect();

    timer =
        new Timer() {
          @Override
          public void run() {
            connect();
          }
        };
    timer.scheduleRepeating(300000);
  }
Exemplo n.º 24
0
 /**
  * Format the contents of the tooltip.
  *
  * <p>Note that this function must wait for the states to load (if they are needed) before
  * continuing. This is done with a timer.
  */
 protected void formatToolTip() {
   if (snapshotParameterSet != null
       && snapshotParameterSet.getValues().containsKey(SnapshotParameterNames.INSTITUTION_STATE)
       && !UiConstants.areInstitutionStatesLoaded()) {
     UiConstants.loadInstitutionStates();
     Timer timer =
         new Timer() {
           @Override
           public void run() {
             if (UiConstants.areInstitutionStatesLoaded()) {
               this.cancel();
               formatToolTipNoWait();
             }
           }
         };
     timer.scheduleRepeating(200);
   } else {
     formatToolTipNoWait();
   }
 }
Exemplo n.º 25
0
  private static Timer startRefreshCycle(
      final AutoRefresh autoRefresh,
      final Canvas autoRefreshCanvas,
      Timer refreshTimer,
      int intervalMillis,
      int minIntervalMillis) {
    // cancel any existing timer
    if (null != refreshTimer) {
      refreshTimer.cancel();
      refreshTimer = null;
    }

    if (minIntervalMillis <= 0 || intervalMillis >= minIntervalMillis) {

      refreshTimer =
          new Timer() {
            public void run() {

              // if the autoRefresh component is already refreshing or is not currently on screen
              // then
              // don't bother doing the work. this protects against unnecessary or unwanted db
              // queries
              // being performed in the background. Also, avoid refresh if the session has expired
              // and we're
              // waiting for the user to login and refresh his session.
              if (!autoRefresh.isRefreshing()
                  && autoRefreshCanvas.isDrawn()
                  && autoRefreshCanvas.isVisible()
                  && !autoRefreshCanvas.isDisabled()
                  && !LoginView.isLoginShowing()) {

                autoRefresh.refresh();
              }
            }
          };

      refreshTimer.scheduleRepeating(intervalMillis);
    }

    return refreshTimer;
  }
 private void playTimeFilter() {
   animationTimer =
       new Timer() {
         @Override
         public void run() {
           //                    int startValue = getFielValueDecrement(startFilterNumberField);
           int startValue = slider.getValue();
           if (startValue != startStore.getModels().size() - 1
               && (endFilterNumberField.getValue() != null
                   && (startStore.getModels().size() - startValue - 1)
                       != (endFilterNumberField.getValue().intValue() - 1))) {
             slider.setValue(++startValue);
             // This call produce the update in map
             applyFilterSelectionListener.componentSelected(null);
           } else {
             stopPlayer();
           }
         }
       };
   animationTimer.scheduleRepeating(5000);
 }
Exemplo n.º 27
0
  public GdmTurn(GameScreen gs) {
    super(gs);
    // Setup the DisclosurePanel
    turnPanel.setOpen(true);
    // Create the timer...
    Timer t =
        new Timer() {
          boolean alreadyPlayedTimerSound = false;

          @Override
          public void run() {
            getGameScreen().getGame().getTurn().updateTime();
            int timeLeft = (int) getGameScreen().getGame().getTurn().getRemainingTime();
            String clock;
            if (timeLeft > 0
                && !getGameScreen().getGame().getTurn().getPhase().equals(TurnPhase.END)) {
              clock =
                  NumberFormat.getFormat("00").format(timeLeft / 60)
                      + ":"
                      + NumberFormat.getFormat("00").format(timeLeft % 60);
              if (timeLeft < 18) {
                clock = "--> " + clock + " <--";
                if (getGameScreen().getGame().getTurn().getPlayer().equals(GUI.getUser())
                    && !alreadyPlayedTimerSound) {
                  getGameScreen().getGameSoundManager().play(GameSound.TimeAlert);
                  alreadyPlayedTimerSound = true;
                }
              } else {
                alreadyPlayedTimerSound = false;
              }
            } else {
              clock = "--:--";
              alreadyPlayedTimerSound = false;
            }
            timerDisplay.setText(clock);
          }
        };
    t.scheduleRepeating(1000);
  }
Exemplo n.º 28
0
 @Override
 public void execute(final QueryCallBack<VoidResponse> callback) {
   for (AjaxQuery<?> query : queries) {
     query.execute();
   }
   Timer queriesMonitor =
       new Timer() {
         @Override
         public void run() {
           boolean queriesExecuted = true;
           for (AjaxQuery<?> query : queries) {
             if (!query.isCompleted()) {
               queriesExecuted = false;
               break;
             }
           }
           if (queriesExecuted) {
             callback.onResponse(new VoidResponse(), null);
             cancel();
           }
         }
       };
   queriesMonitor.scheduleRepeating(sleepTimeBetweenCbChecks);
 }
 public void start() {
   pollingTimer.scheduleRepeating(pollingPeriodInMS);
 }
Exemplo n.º 30
0
 public void startMonitoring() {
   if (panel.isAttached()) {
     timer.run();
     timer.scheduleRepeating(interval);
   }
 }