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

项目:walkaround    文件:UploadFormPopup.java   
/**
 * Creates an upload popup.
 */
public UploadFormPopup() {
  form = BINDER.createAndBindUi(this);

  PopupChrome chrome = PopupChromeFactory.createPopupChrome();
  chrome.enableTitleBar();
  popup = PopupFactory.createPopup(null, new CenterPopupPositioner(), chrome, false);
  popup.getTitleBar().setTitleText("Upload attachment");
  popup.add(form);

  iframe = Document.get().createIFrameElement();
  iframe.setName("_uploadform" + iframeId++);
  // HACK(danilatos): Prevent browser from caching due to whatever reason
  iframe.setSrc("/uploadform?nocache=" + Duration.currentTimeMillis());
  form.getElement().setAttribute("target", iframe.getName());

  onloadRegistration =
      DomHelper.registerEventHandler(iframe, "load", new JavaScriptEventListener() {
        @Override
        public void onJavaScriptEvent(String name, Event event) {
          onIframeLoad();
        }
      });
  UIObject.setVisible(iframe, false);
}
项目:Wiab.pro    文件:ScreenControllerImpl.java   
private void processScreenChange(ChangeSource changeSource) {
  if (scrollPanel == null) {
    return;
  }

  lastChangeTime = Duration.currentTimeMillis();
  lastChangeSource = changeSource;
  lastScrollPosition = scrollPanel.getScrollTop();
  lastScrollDirection = calculateScrollDirection();        
  lastAbsoluteScrollSpeed = calculateAbsoluteScrollSpeed();    
  lastScrollSpeedChange = calculateScrollSpeedChange();    

  if (!ChangeSource.PROGRAM.equals(changeSource)) {      
    triggerOnScreenChanged();

    needsSupplementUpdate = true;
  }  

  previousChangeTime = lastChangeTime;
  previousScrollPosition = lastScrollPosition;
  previousAbsoluteScrollSpeed = lastAbsoluteScrollSpeed;
  previousScrollDirection = lastScrollDirection;
}
项目:Wiab.pro    文件:GadgetWidget.java   
@Override
public boolean execute() {
  if (!isActive()) {
    log("Not active.");
    return false;
  } else if (gadgetLibraryLoaded()) {
    controllerRegistration(crUrl, crWidth, crHeight);
    return false;
  } else {
    if (Duration.currentTimeMillis() > loadWarningTime) {
      showBrokenGadget("Gadget RPC script failed to load on time.");
      return false;
    }
  }
  return true;      
}
项目:che    文件:BasicIncrementalScheduler.java   
@Override
public void run() {
  if (isPaused) {
    return;
  }

  try {
    double start = Duration.currentTimeMillis();
    boolean keepRunning = worker.run(currentWorkAmount);
    updateWorkAmount(Duration.currentTimeMillis() - start);
    if (keepRunning) {
      schedule();
    } else {
      clearWorker();
    }
  } catch (Throwable t) {
    Log.error(getClass(), "Could not run worker", t);
  }
}
项目:GridStack    文件:GwtGridStack.java   
public void initialize(Integer width, Integer height, GwtGridStackOptions options) {
    if(initialized) {
        LOGGER.severe("gridstack already initialized");
        return;
    }

    getElement().addClassName(INITIALIZING_CLASSNAME);

    if(width != null) {
        getElement().setAttribute("data-gs-width", width.toString());
    }
    if(height != null) {
        getElement().setAttribute("data-gs-height", height.toString());
    }
    Duration duration = new Duration();
    initializeGridStack(options);
    LOGGER.info("Initialize grid stack took " + duration.elapsedMillis());
    initialized = true;
    getElement().removeClassName(INITIALIZING_CLASSNAME);
    getElement().addClassName(READY_CLASSNAME);

    for (GwtGridStackReadyListener readyListener : readyListeners) {
        readyListener.onReady();
    }
}
项目:quake2-gwt-port    文件:GwtResourceLoaderImpl.java   
private void processReadyList() {         
  new Timer() {
    @Override
    public void run() {
      for (int i = readyList.size() - 1; i >= 0; i--) {
        ResponseHandler handler = readyList.get(i);
        if (handler.sequenceNumber == currentSequenceNumber) {
          if (handler.response != null) {
            double t0 = Duration.currentTimeMillis();
            handler.callback.onSuccess(sbb.stringToByteBuffer(handler.response));
            Com.Printf("Processed #" + currentSequenceNumber + " in " + (Duration.currentTimeMillis() - t0) / 1000.0 + "s\r");
          }
          readyList.remove(i);
          currentSequenceNumber++;
          processReadyList();
          return;
        }
      }
    }
  }.schedule(RECEIVED_WAIT_TIME);
}
项目: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);
}
项目:incubator-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);
}
项目:gwt-comet    文件:CometClient.java   
private Timer createHeartbeatTimer() {
    return new Timer() {
        @Override
        public void run() {
            double currentTimeMillis = Duration.currentTimeMillis();
            double difference = currentTimeMillis - lastReceivedTime;
            if (difference >= heartbeatTimeout) {
                doDisconnect();
                doOnError(new CometException("Heartbeat failed"), false, CometClientTransportWrapper.this);
            }
            else {
                // we have received a message since the timer was
                // schedule so reschedule it.
                schedule(heartbeatTimeout - (int) difference);
            }
        }
    };
}
项目: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);
  }
}
项目: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);
}
项目:Wiab.pro    文件: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);
  }
}
项目:Wiab.pro    文件:GadgetDataStoreImpl.java   
private void cleanupExpiredCache() {
  GadgetLog.log("GadgetDataStoreImpl.cleanupExpiredCache");
  double currentTime = Duration.currentTimeMillis();
  Iterator<CacheElement> it = metadataCache.values().iterator();
  while (it.hasNext()) {
    if (currentTime > it.next().getExpirationTime()) {
      it.remove();
    }
  }
}
项目:Wiab.pro    文件: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();
}
项目:Wiab.pro    文件:AnimatedScrollPanel.java   
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
项目:Wiab.pro    文件: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();
  }
}
项目: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;
}
项目:incubator-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);
  }
}
项目:incubator-wave    文件: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();
}
项目:incubator-wave    文件:AnimatedScrollPanel.java   
@Override
public void moveTo(double location) {
  startLocation = getViewport().getStart();
  endLocation = location;
  counter = new Duration();
  execute();
  scheduler.scheduleDelayed(this, 0);
}
项目:incubator-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();
  }
}
项目:FallenGalaxy    文件:Animation.java   
/**
 * Run this animation at the given startTime. If the startTime has already
 * passed, the animation will be synchronize as if it started at the
 * specified start time. If the animation is already running, it will be
 * canceled first.
 * 
 * @param duration
 *            the duration of the animation in milliseconds
 * @param startTime
 *            the synchronized start time in milliseconds
 */
public void run(int duration, double startTime) {
    // Cancel the animation if it is running
    cancel();

    // Save the duration and startTime
    this.running = true;
    this.duration = duration;
    this.startTime = startTime;

    // Start synchronously if start time has passed
    double curTime = Duration.currentTimeMillis();
    if (update(curTime, Math.max(0, curTime - startTime))) {
        return;
    }

    // Add to the list of animations

    // We use a static list of animations and a single timer, and create
    // them
    // only if we are the only active animation. This is safe since JS is
    // single-threaded.
    if (animations == null) {
        animations = new ArrayList<Animation>();
        animationTimer = new Timer() {
            @Override
            public void run() {
                updateAnimations();
            }
        };
        animationTimer.schedule(DEFAULT_FRAME_DELAY);
    }

    animations.add(this);
}
项目:FallenGalaxy    文件:Animation.java   
/**
 * Update all {@link Animation Animations}.
 */
private static void updateAnimations() {
    double curTime = Duration.currentTimeMillis();
    double elapsedTime = lastFrameTime == -1 ? 0 : curTime - lastFrameTime;
    lastFrameTime = curTime;

    // Duplicate the animations list in case it changes as we iterate over
    // it
    Animation[] curAnimations = new Animation[animations.size()];
    curAnimations = animations.toArray(curAnimations);

    // Iterator through the animations
    for (Animation animation : curAnimations) {
        try {
            if (animation.running && animation.update(curTime, elapsedTime)) {
                // We can't just remove the animation at the index, because
                // calling
                // animation.update may have the side effect of canceling this
                // animation, running new animations, or canceling other
                // animations.
                animations.remove(animation);
            }
        } catch (Exception e) {
            Utilities.log("Animation error: " + (animation != null ?
                animation.getClass() + " " + animation.toString() : "<null>") +
                " (animation removed)", e);
            animations.remove(animation);
        }
    }

    // Reschedule the timer
    animationTimer.schedule(DEFAULT_FRAME_DELAY);
}
项目:gwt-comet    文件:CometClient.java   
@Override
public void onConnected(int heartbeat) {
    heartbeatTimeout = heartbeat + connectionTimeout;
    lastReceivedTime = Duration.currentTimeMillis();

    cancelTimers();
    heartbeatTimer.schedule(heartbeatTimeout);

    doOnConnected(heartbeat, this);
}
项目:gwt-comet    文件:CometTransport.java   
public String getUrl(int connectionCount) {
    StringBuilder url = new StringBuilder(client.getUrl());
    if (client.getSerializer() != null && client.getSerializer().getMode() == SerialMode.DE_RPC) {
        url.append(url.indexOf("?") > 0 ? '&' : '?');
        url.append(MODULE_BASE_PARAMETER).append('=').append(GWT.getModuleBaseURL());
        url.append('&').append(STRONG_NAME_PARAMETER).append('=').append(GWT.getPermutationStrongName());
    }

    url.append(url.indexOf("?") > 0 ? '&' : '?');
    url.append("t=").append(Integer.toString((int) (Duration.currentTimeMillis() % Integer.MAX_VALUE), Character.MAX_RADIX));
    url.append("&c=").append(Integer.toString(connectionCount, Character.MAX_RADIX));

    return url.toString();
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
void stop() {
    doStop();
    cometTest = null;
    stopTime = Duration.currentTimeMillis();
    output("stop " + name + " " + (stopTime - startTime) + "ms", "black");
    if (pass && failure == null) {
        output("pass!", "lime");
    }
    else {
        output("fail  :\n" + (failure == null ? "unknown" : failure), "red");
    }
    runNext();
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onConnected(int heartbeat) {
    connectedTime = Duration.currentTimeMillis();
    connectedCount++;
    output("connected " + connectedCount + " " + (connectedTime - startTime) + "ms heartbeat: " + heartbeat, "silver");
    assertTrue("connected once", connectedCount == 1);
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onDisconnected() {
    disconnectedTime = Duration.currentTimeMillis();
    disconnectedCount++;
    output("disconnected " + disconnectedCount + " " + (disconnectedTime - connectedTime) + "ms", "silver");
    assertTrue("disconnected once", disconnectedCount == 1);
    stop();
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onError(Throwable exception, boolean connected) {
    double errorTime = Duration.currentTimeMillis();
    errorCount++;
    output("error " + errorCount + " " + (errorTime - startTime) + "ms " + connected + " " + exception, "red");
    fail(exception.toString());
    stop();
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onConnected(int heartbeat) {
    connectedTime = Duration.currentTimeMillis();
    connectedCount++;
    if (connectedCount > 1) {
        pass();
        stop();
    }
    else {
        output("connected " + connectedCount + " " + (connectedTime - startTime) + "ms heartbeat: " + heartbeat, "silver");
        output("stop your server now!", "blue");
    }
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onError(Throwable exception, boolean connected) {
    double errorTime = Duration.currentTimeMillis();
    errorCount++;
    output("error " + errorCount + " " + (errorTime - startTime) + "ms " + connected + " " + exception, "silver");
    output("start your server now!", "blue");
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onError(Throwable exception, boolean connected) {
    double errorTime = Duration.currentTimeMillis();
    errorCount++;
    output("error " + errorCount + " " + (errorTime - startTime) + "ms " + connected + " " + exception, "lime");
    assertTrue("status code exception", exception instanceof StatusCodeException);
    if (exception instanceof StatusCodeException) {
        assertEquals("status code", 417, ((StatusCodeException) exception).getStatusCode());
        assertEquals("status message", "Oh Noes!", ((StatusCodeException) exception).getEncodedResponse());
    }
    stop();
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onMessage(List<? extends Serializable> messages) {
    super.onMessage(messages);
    double now = Duration.currentTimeMillis();
    for (Serializable m : messages) {
        double message;
        if (m instanceof TestData) {
            message = ((TestData) m).d;
        }
        else if (m instanceof String) {
            message = Double.parseDouble((String) m);
        }
        else {
            continue;
        }
        double messageLatency = now - message;
        latency += messageLatency;
        if (messageLatency < min) {
            min = messageLatency;
        }
        if (messageLatency > max) {
            max = messageLatency;
        }
        if (messageLatency > 250) {
            output("latency " + messageLatency, "red");
        }
    }
}
项目:gwt-comet    文件:CometTestEntryPoint.java   
@Override
public void onMessage(List<? extends Serializable> messages) {
    super.onMessage(messages);
    int waitTime = messages.size() * 10;
    double time = Duration.currentTimeMillis() + waitTime;
    while (Duration.currentTimeMillis() < time) {
    }
    output("waited " + waitTime + "ms " + messages.size() + "messages", "black");
}
项目: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();
}
项目:Wiab.pro    文件:ScreenControllerImpl.java   
@Override
public boolean isScrolling() {
  return leftMouseButtonPressed ||
      (lastChangeSource != ChangeSource.PARENT_RESIZE &&
      Duration.currentTimeMillis() - lastChangeTime < SCROLL_FINISH_DELTA_TIME_MS);
}
项目:Wiab.pro    文件:GadgetDataStoreImpl.java   
CacheElement(GadgetMetadata metadata) {
  this.metadata = metadata;
  expirationTime = Duration.currentTimeMillis() + Flags.get().gadgetMetadataLifetimeMs();
}
项目:Wiab.pro    文件:TimeSlicedCommandRepeater.java   
/**
 * @return true if and only if there is time remaining in the current slice.
 */
private boolean hasTimeLeft() {
  return Duration.currentTimeMillis() < timeSliceEnd;
}
项目:Wiab.pro    文件:GwtSimpleTimer.java   
/** {@inheritDoc} */
public double getTime() {
  return Duration.currentTimeMillis();
}
项目:Wiab.pro    文件:DynamicDomRenderer.java   
/** @return listener to the screen controller. */
public ScreenController.Listener getScreenListener() {
  return new ScreenController.Listener() {

    @Override
    public void onScreenChanged() {
      // If parent window size is changed => unfix all blips' heights, and schedule their fixing.
      if (screen.getLastChangeSource() == ScreenController.ChangeSource.PARENT_RESIZE) {
        setAllRenderedBlipsHeightsFixed(false);
        getTimer().scheduleDelayed(fixAllRenderedBlipSizeTask, FIX_ALL_RENDERED_BLIP_SIZES_MS);
      }

      boolean shouldRender = !screen.isLeftMouseButtonPressed() && !placeholders.isEmpty();
      if (shouldRender) {
        calculateRenderParameters();
        double currentTime = Duration.currentTimeMillis();    

        // Renders immediately when acceleration is negative (scrolling is slowed)
        // and the scrolling speed is small for two times in a row.
        boolean shouldRenderImmediately = !screen.isScrolling() ||
            (screen.getLastScrollSpeedChange() == ScrollSpeedChange.SLOWED_DOWN
            && screen.getPreviousAbsoluteScrollSpeed() <= Flags.get().immediateRenderScrollSpeedPxS()
            && screen.getLastAbsoluteScrollSpeed() <= Flags.get().immediateRenderScrollSpeedPxS());

        if (!shouldRenderImmediately && planRenderTime != NEVER && currentTime > planRenderTime) {
          shouldRenderImmediately = true;
        }

        if (shouldRenderImmediately) {
          if (!inProcess) {
            dynamicRendering();
            planRenderTime = NEVER;
            getTimer().cancel(dynamicRenderingTask);
          }
        } else {
          // Addition to timer to make rendering at equal time intervals during scroll down.
          if (screen.getLastScrollDirection() == ScrollDirection.DOWN) {
            if (planRenderTime == NEVER) {
              planRenderTime = (long) (currentTime) + Flags.get().afterScrollRenderDelayMs();
            }
          }
          getTimer().scheduleDelayed(dynamicRenderingTask, Flags.get().afterScrollRenderDelayMs());
        }
      }
    }
  };
}