com.google.gwt.core.client.Duration Java Examples

The following examples show how to use com.google.gwt.core.client.Duration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GadgetWidget.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Registers the Gadget object as RPC event listener with the Gadget RPC
 * Controller after waiting for the Gadget RPC library to load.
 */
private void scheduleControllerRegistration(
    final String url, final long width, final long height) {
  new ScheduleTimer() {
    private double loadWarningTime =
        Duration.currentTimeMillis() + GADGET_RPC_LOAD_WARNING_TIMEOUT_MS;
    @Override
    public void run() {
      if (!isActive()) {
        cancel();
        log("Not active.");
        return;
      } else if (gadgetLibraryLoaded()) {
        cancel();
        controllerRegistration(url, width, height);
      } else {
        if (Duration.currentTimeMillis() > loadWarningTime) {
          log("Gadget RPC script failed to load on time.");
          loadWarningTime += GADGET_RPC_LOAD_WARNING_TIMEOUT_MS;
        }
      }
    }
  }.scheduleRepeating(GADGET_RPC_LOAD_TIMER_MS);
}
 
Example #2
Source File: MapViewer.java    From ThinkMap with Apache License 2.0 6 votes vote down vote up
/**
 * Entry point to the program
 */
public void onModuleLoad() {
    JavascriptLib.init();
    // Feature detection
    if (!featureHandler.detect()) return;
    // Atlas to look up position of textures
    xhr = Browser.getWindow().newXMLHttpRequest();
    xhr.open("GET", "http://" + getConfigAdddress() + "/resources/blocks.json", true);
    xhr.setOnload(this);
    xhr.send();

    Platform.runRepeated(new Runnable() {
        @Override
        public void run() {
            if (connection == null) return;
            if (Duration.currentTimeMillis() - lastKeepAlive > 1000) {
                lastKeepAlive = Duration.currentTimeMillis();
                connection.send(new KeepAlive());
            }
        }
    }, 1000);
}
 
Example #3
Source File: GadgetWidget.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Registers the Gadget object as RPC event listener with the Gadget RPC
 * Controller after waiting for the Gadget RPC library to load.
 */
private void scheduleControllerRegistration(
    final String url, final long width, final long height) {
  new ScheduleTimer() {
    private double loadWarningTime =
        Duration.currentTimeMillis() + GADGET_RPC_LOAD_WARNING_TIMEOUT_MS;
    @Override
    public void run() {
      if (!isActive()) {
        cancel();
        log("Not active.");
        return;
      } else if (gadgetLibraryLoaded()) {
        cancel();
        controllerRegistration(url, width, height);
      } else {
        if (Duration.currentTimeMillis() > loadWarningTime) {
          log("Gadget RPC script failed to load on time.");
          loadWarningTime += GADGET_RPC_LOAD_WARNING_TIMEOUT_MS;
        }
      }
    }
  }.scheduleRepeating(GADGET_RPC_LOAD_TIMER_MS);
}
 
Example #4
Source File: AnimatedScrollPanel.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
 
Example #5
Source File: ChainableCommand.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the tracking information on each link in the chain
 *
 * @param actionName the name of action this chain of commands represents
 * @param chainDuration duration to be used for the entire chain
 */
private void initTrackingInformation(String actionName, Duration chainDuration) {
  this.actionName = actionName;
  // Note that all links in the chain have a reference to the same chainDuration.
  this.chainDuration = chainDuration;
  if (nextCommand != null) {
    nextCommand.initTrackingInformation(actionName, chainDuration);
  }
}
 
Example #6
Source File: SchedulerTimerService.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public double currentTimeMillis() {
  // Replace this with just Duration.currentTimeMillis() when it is itself
  // implemented with a GWT.isClient() check.
  return GWT.isClient()
      ? Duration.currentTimeMillis()
      : System.currentTimeMillis();
}
 
Example #7
Source File: DateUtils.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * This is used to get a efficient time for JS.
 * Warning! Use TimerService if you want to actually test and control the time.
 */
public double currentTimeMillis() {
  // Use an optimised time for JS when running in JS.
  if (!GWT.isClient()) {
    return System.currentTimeMillis();
  } else {
    return Duration.currentTimeMillis();
  }
}
 
Example #8
Source File: AnimatedScrollPanel.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
 
Example #9
Source File: InputManager.java    From ThinkMap with Apache License 2.0 5 votes vote down vote up
private boolean onKeyDown(char keyCode) {
    switch (keyCode) {
        case 'W':
            movingDirection = 1;
            return true;
        case 'S':
            movingDirection = -1;
            return true;
        case 'A':
            sideDirection = -1;
            return true;
        case 'D':
            sideDirection = 1;
            return true;
        case 32:
            double now = Duration.currentTimeMillis();
            if (now - lastJump > 120 && now - lastJump < 250) {
                flying = !flying;
            } else {
                if (onGround) {
                    vSpeed = 0.15f;
                }
            }
            lastJump = now;
            return true;
    }
    return false;
}
 
Example #10
Source File: SchedulerTimerService.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public double currentTimeMillis() {
  // Replace this with just Duration.currentTimeMillis() when it is itself
  // implemented with a GWT.isClient() check.
  return GWT.isClient()
      ? Duration.currentTimeMillis()
      : System.currentTimeMillis();
}
 
Example #11
Source File: DateUtils.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * This is used to get a efficient time for JS.
 * Warning! Use TimerService if you want to actually test and control the time.
 */
public double currentTimeMillis() {
  // Use an optimised time for JS when running in JS.
  if (!GWT.isClient()) {
    return System.currentTimeMillis();
  } else {
    return Duration.currentTimeMillis();
  }
}
 
Example #12
Source File: DomLogger.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * @return Timestamp for use in log
 */
private static String timeStamp() {
  double ts = Duration.currentTimeMillis() / 1000.0;
  // divide the startTime to second from millsecond and seconds is much easier to read
  // for the user.
  if (TIMESTAMP_FORMAT != null) {
    return TIMESTAMP_FORMAT.format(ts);
  } else {
    return Double.toString(ts);
  }
}
 
Example #13
Source File: Profiler.java    From flow with Apache License 2.0 5 votes vote down vote up
/**
 * Outputs the time passed since various events recorded in
 * performance.timing if supported by the browser.
 */
public static void logBootstrapTimings() {
    if (isEnabled()) {
        double now = Duration.currentTimeMillis();

        String[] keys = new String[] { "navigationStart",
                "unloadEventStart", "unloadEventEnd", "redirectStart",
                "redirectEnd", "fetchStart", "domainLookupStart",
                "domainLookupEnd", "connectStart", "connectEnd",
                "requestStart", "responseStart", "responseEnd",
                "domLoading", "domInteractive",
                "domContentLoadedEventStart", "domContentLoadedEventEnd",
                "domComplete", "loadEventStart", "loadEventEnd" };

        LinkedHashMap<String, Double> timings = new LinkedHashMap<>();

        for (String key : keys) {
            double value = getPerformanceTiming(key);
            if (value == 0) {
                // Ignore missing value
                continue;
            }
            timings.put(key, Double.valueOf(now - value));
        }

        if (timings.isEmpty()) {
            Console.log(
                    "Bootstrap timings not supported, please ensure your browser supports performance.timing");
            return;
        }

        if (getConsumer() != null) {
            getConsumer().addBootstrapData(timings);
        }
    }
}
 
Example #14
Source File: ChainableCommand.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Kick off the chain of commands.
 *
 * @param actionName the name of action this chain of commands represents
 * @param node the project node to which the chain of commands is applied
 * @param finallyCommand a command to execute after the chain is finished,
 *                       regardless of whether it succeeds
 */
public final void startExecuteChain(String actionName, ProjectNode node,
    Command finallyCommand) {
  // The node must not be null.
  // If you are calling startExecuteChain with null for the node parameter, maybe you should
  // question why you are using a ChainableCommand at all. ChainableCommands were designed to
  // perform an operation on a ProjectNode.
  Preconditions.checkNotNull(node);

  setFinallyCommand(finallyCommand);
  initTrackingInformation(actionName, new Duration());

  executeLink(node);
}
 
Example #15
Source File: DomLogger.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * @return Timestamp for use in log
 */
private static String timeStamp() {
  double ts = Duration.currentTimeMillis() / 1000.0;
  // divide the startTime to second from millsecond and seconds is much easier to read
  // for the user.
  if (TIMESTAMP_FORMAT != null) {
    return TIMESTAMP_FORMAT.format(ts);
  } else {
    return Double.toString(ts);
  }
}
 
Example #16
Source File: GwtSimpleTimer.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double getTime() {
  return Duration.currentTimeMillis();
}
 
Example #17
Source File: GadgetDataStoreImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
boolean expired() {
  return Duration.currentTimeMillis() > expirationTime;
}
 
Example #18
Source File: GadgetDataStoreImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
CacheElement(GadgetMetadata metadata, String securityToken) {
  this.metadata = metadata;
  this.securityToken = securityToken;
  expirationTime = Duration.currentTimeMillis() + CACHE_EXPIRATION_TIME_MS;
}
 
Example #19
Source File: TimeSlicedCommandRepeater.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if and only if there is time remaining in the current slice.
 */
private boolean hasTimeLeft() {
  return Duration.currentTimeMillis() < timeSliceEnd;
}
 
Example #20
Source File: ClientChronometer.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
public long stop() {
    stopTime = Duration.currentTimeMillis();
    return stopTime.longValue() * 1000000;
}
 
Example #21
Source File: Utils.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public double currentTimeMillis() {
  return Duration.currentTimeMillis();
}
 
Example #22
Source File: FinderPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
            mouseDown = true;

  /*
   * Resize glassElem to take up the entire scrollable window area,
   * which is the greater of the scroll size and the client size.
   */
            int width = Math.max(Window.getClientWidth(),
                    Document.get().getScrollWidth());
            int height = Math.max(Window.getClientHeight(),
                    Document.get().getScrollHeight());
            glassElem.getStyle().setHeight(height, Style.Unit.PX);
            glassElem.getStyle().setWidth(width, Style.Unit.PX);
            Document.get().getBody().appendChild(glassElem);

            offset = getEventPosition(event) - getAbsolutePosition();
            Event.setCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEUP:
            mouseDown = false;

            glassElem.removeFromParent();

            // Handle double-clicks.
            // Fake them since the double-click event aren't fired.
            if (this.toggleDisplayAllowed) {
                double now = Duration.currentTimeMillis();
                if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
                    now = 0;
                    toggleCollapsedState();
                }
                this.lastClick = now;
            }

            Event.releaseCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEMOVE:
            if (mouseDown) {
                int size;
                if (reverse) {
                    size = getTargetPosition() + getTargetSize() - getSplitterSize()
                            - getEventPosition(event) + offset;
                } else {
                    size = getEventPosition(event) - getTargetPosition() - offset;
                }
                ((LayoutData) target.getLayoutData()).hidden = false;
                setAssociatedWidgetSize(size);
                event.preventDefault();
            }
            break;
    }
}
 
Example #23
Source File: CollapsibleSplitLayoutPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
            mouseDown = true;

  /*
   * Resize glassElem to take up the entire scrollable window area,
   * which is the greater of the scroll size and the client size.
   */
            int width = Math.max(Window.getClientWidth(),
                    Document.get().getScrollWidth());
            int height = Math.max(Window.getClientHeight(),
                    Document.get().getScrollHeight());
            glassElem.getStyle().setHeight(height, Style.Unit.PX);
            glassElem.getStyle().setWidth(width, Style.Unit.PX);
            Document.get().getBody().appendChild(glassElem);

            offset = getEventPosition(event) - getAbsolutePosition();
            Event.setCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEUP:
            mouseDown = false;

            glassElem.removeFromParent();

            // Handle double-clicks.
            // Fake them since the double-click event aren't fired.
            if (this.toggleDisplayAllowed) {
                double now = Duration.currentTimeMillis();
                if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
                    now = 0;
                    toggleCollapsedState();
                }
                this.lastClick = now;
            }

            Event.releaseCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEMOVE:
            if (mouseDown) {
                int size;
                if (reverse) {
                    size = getTargetPosition() + getTargetSize() - getSplitterSize()
                            - getEventPosition(event) + offset;
                } else {
                    size = getEventPosition(event) - getTargetPosition() - offset;
                }
                ((LayoutData) target.getLayoutData()).hidden = false;
                setAssociatedWidgetSize(size);
                event.preventDefault();
            }
            break;
    }
}
 
Example #24
Source File: AuthImpl.java    From requestor with Apache License 2.0 4 votes vote down vote up
@Override
public double now() {
    return Duration.currentTimeMillis();
}
 
Example #25
Source File: DigestAuth.java    From requestor with Apache License 2.0 4 votes vote down vote up
private String generateClientNonce(String nonce, String nc) {
    return MD5.hash(nc + nonce + Duration.currentTimeMillis() + getRandom());
}
 
Example #26
Source File: ClientChronometer.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
public long start() {
    stopTime = null;
    startTime = Duration.currentTimeMillis();
    return startTime.longValue() * 1000000;
}
 
Example #27
Source File: NavItemEditorView.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
@Override
public String generateId() {
    return Double.toString(Duration.currentTimeMillis());
}
 
Example #28
Source File: GwtSimpleTimer.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double getTime() {
  return Duration.currentTimeMillis();
}
 
Example #29
Source File: TimeSlicedCommandRepeater.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if and only if there is time remaining in the current slice.
 */
private boolean hasTimeLeft() {
  return Duration.currentTimeMillis() < timeSliceEnd;
}
 
Example #30
Source File: ProfileSessionImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
private double getCurrentTime() {
  return GWT.isClient()
      ? Duration.currentTimeMillis()
      : System.currentTimeMillis();
}