类com.google.gwt.core.client.Duration源码实例Demo

下面列出了怎么用com.google.gwt.core.client.Duration的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: swellrt   文件: GadgetWidget.java
/**
 * 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);
}
 
源代码2 项目: ThinkMap   文件: MapViewer.java
/**
 * 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);
}
 
源代码3 项目: incubator-retired-wave   文件: GadgetWidget.java
/**
 * 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);
}
 
源代码4 项目: appinventor-extensions   文件: ChainableCommand.java
/**
 * 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);
  }
}
 
源代码5 项目: appinventor-extensions   文件: ChainableCommand.java
/**
 * 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);
}
 
源代码6 项目: flow   文件: Profiler.java
/**
 * 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);
        }
    }
}
 
源代码7 项目: swellrt   文件: DomLogger.java
/**
 * @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);
  }
}
 
源代码8 项目: swellrt   文件: SchedulerTimerService.java
@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();
}
 
源代码9 项目: swellrt   文件: AnimatedScrollPanel.java
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
 
源代码10 项目: swellrt   文件: DateUtils.java
/**
 * 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();
  }
}
 
源代码11 项目: ThinkMap   文件: InputManager.java
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;
}
 
源代码12 项目: incubator-retired-wave   文件: DomLogger.java
/**
 * @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);
  }
}
 
@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();
}
 
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
 
源代码15 项目: incubator-retired-wave   文件: DateUtils.java
/**
 * 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();
  }
}
 
源代码16 项目: appinventor-extensions   文件: ChainableCommand.java
/**
 * Resets the start time for the link duration timer
 *
 */
private final void resetLinkDuration() {
  // Note that each link in the chain has a unique linkDuration.
  linkDuration = new Duration();
}
 
源代码17 项目: flow   文件: ResourceLoader.java
/**
 * Load a stylesheet and notify a listener when the stylesheet is loaded.
 * Calling this method when the stylesheet is currently loading or already
 * loaded doesn't cause the stylesheet to be loaded again, but the listener
 * will still be notified when appropriate.
 *
 * @param stylesheetUrl
 *            the url of the stylesheet to load
 * @param resourceLoadListener
 *            the listener that will get notified when the stylesheet is
 *            loaded
 */
public void loadStylesheet(final String stylesheetUrl,
        final ResourceLoadListener resourceLoadListener) {
    final String url = WidgetUtil.getAbsoluteUrl(stylesheetUrl);
    final ResourceLoadEvent event = new ResourceLoadEvent(this, url);
    if (loadedResources.has(url)) {
        if (resourceLoadListener != null) {
            resourceLoadListener.onLoad(event);
        }
        return;
    }

    if (addListener(url, resourceLoadListener, loadListeners)) {
        LinkElement linkElement = getDocument().createLinkElement();
        linkElement.setRel("stylesheet");
        linkElement.setType("text/css");
        linkElement.setHref(url);

        if (BrowserInfo.get().isSafariOrIOS()) {
            // Safari doesn't fire any events for link elements
            // See http://www.phpied.com/when-is-a-stylesheet-really-loaded/
            Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
                private final Duration duration = new Duration();

                @Override
                public boolean execute() {
                    int styleSheetLength = getStyleSheetLength(url);
                    if (getStyleSheetLength(url) > 0) {
                        fireLoad(event);
                        return false; // Stop repeating
                    } else if (styleSheetLength == 0) {
                        // "Loaded" empty sheet -> most likely 404 error
                        fireError(event);
                        return true;
                    } else if (duration.elapsedMillis() > 60 * 1000) {
                        fireError(event);
                        return false;
                    } else {
                        return true; // Continue repeating
                    }
                }
            }, 10);
        } else {
            addOnloadHandler(linkElement, new StyleSheetLoadListener(url),
                    event);
            if (BrowserInfo.get().isOpera()) {
                // Opera onerror never fired, assume error if no onload in x
                // seconds
                new Timer() {
                    @Override
                    public void run() {
                        if (!loadedResources.has(url)) {
                            fireError(event);
                        }
                    }
                }.schedule(5 * 1000);
            }
        }

        getHead().appendChild(linkElement);
    }
}
 
源代码18 项目: swellrt   文件: GadgetDataStoreImpl.java
CacheElement(GadgetMetadata metadata, String securityToken) {
  this.metadata = metadata;
  this.securityToken = securityToken;
  expirationTime = Duration.currentTimeMillis() + CACHE_EXPIRATION_TIME_MS;
}
 
源代码19 项目: swellrt   文件: GadgetDataStoreImpl.java
boolean expired() {
  return Duration.currentTimeMillis() > expirationTime;
}
 
源代码20 项目: swellrt   文件: ProfileSessionImpl.java
private double getCurrentTime() {
  return GWT.isClient()
      ? Duration.currentTimeMillis()
      : System.currentTimeMillis();
}
 
源代码21 项目: swellrt   文件: TimeSlicedCommandRepeater.java
/**
 * @return true if and only if there is time remaining in the current slice.
 */
private boolean hasTimeLeft() {
  return Duration.currentTimeMillis() < timeSliceEnd;
}
 
源代码22 项目: swellrt   文件: GwtSimpleTimer.java
/** {@inheritDoc} */
public double getTime() {
  return Duration.currentTimeMillis();
}
 
源代码23 项目: dashbuilder   文件: NavItemEditorView.java
@Override
public String generateId() {
    return Double.toString(Duration.currentTimeMillis());
}
 
源代码24 项目: dashbuilder   文件: ClientChronometer.java
public long start() {
    stopTime = null;
    startTime = Duration.currentTimeMillis();
    return startTime.longValue() * 1000000;
}
 
源代码25 项目: dashbuilder   文件: ClientChronometer.java
public long stop() {
    stopTime = Duration.currentTimeMillis();
    return stopTime.longValue() * 1000000;
}
 
源代码26 项目: requestor   文件: DigestAuth.java
private String generateClientNonce(String nonce, String nc) {
    return MD5.hash(nc + nonce + Duration.currentTimeMillis() + getRandom());
}
 
源代码27 项目: requestor   文件: AuthImpl.java
@Override
public double now() {
    return Duration.currentTimeMillis();
}
 
CacheElement(GadgetMetadata metadata, String securityToken) {
  this.metadata = metadata;
  this.securityToken = securityToken;
  expirationTime = Duration.currentTimeMillis() + CACHE_EXPIRATION_TIME_MS;
}
 
boolean expired() {
  return Duration.currentTimeMillis() > expirationTime;
}
 
/**
 * @return true if and only if there is time remaining in the current slice.
 */
private boolean hasTimeLeft() {
  return Duration.currentTimeMillis() < timeSliceEnd;
}