Java Code Examples for com.google.gwt.core.client.Duration#currentTimeMillis()

The following examples show how to use com.google.gwt.core.client.Duration#currentTimeMillis() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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();
}
 
Example 14
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 15
Source File: GadgetDataStoreImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
boolean expired() {
  return Duration.currentTimeMillis() > expirationTime;
}
 
Example 16
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 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: 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 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: GwtSimpleTimer.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double getTime() {
  return Duration.currentTimeMillis();
}