List of usage examples for com.google.gwt.core.client Duration currentTimeMillis
public static native double currentTimeMillis() ;
From source file:ca.nanometrics.gflot.client.example.SlidingWindowExample.java
License:Open Source License
private FakeRpcServiceAsync getRpcService() { return new FakeRpcServiceAsync() { public void getNewData(final AsyncCallback<DataPoint[]> callback) { callback.onSuccess(//from www . ja v a 2 s.c om new DataPoint[] { new DataPoint(Duration.currentTimeMillis(), Random.nextDouble()) }); } }; }
From source file:ca.wimsc.client.common.widgets.google.Momentum.java
License:Apache License
/** * Start decelerating. Checks if the current velocity is above the minumum * threshold to start decelerating. If so then deceleration will begin, if not * then nothing happens.// www . ja va2 s .c o m * * @param velocity The initial velocity. The velocity passed here should be in * terms of number of pixels / millisecond. initiating deceleration. * @param minCoord The content's scrollable boundary. * @param maxCoord The content's scrollable boundary. * @param initialOffset The current offset of the element within its * boundaries. * @return True if deceleration has been initiated. */ public boolean start(Point velocity, Point minCoord, Point maxCoord, Point initialOffset) { this.minCoord = minCoord; this.maxCoord = maxCoord; currentOffset = new Point(initialOffset); previousOffset = new Point(initialOffset); this.velocity = adjustInitialVelocity(velocity); if (isVelocityAboveThreshold(MIN_START_VELOCITY)) { decelerating = true; startTime = Duration.currentTimeMillis(); stepNumber = 0; stepFunction.schedule((int) MS_PER_FRAME); return true; } return false; }
From source file:ca.wimsc.client.common.widgets.google.Momentum.java
License:Apache License
/** * Calculate the next offset of the element and animate it to that position. *//*from w w w . j a v a 2s. c om*/ private void step() { // If deceleration is stopped between frames this is possible. Need to abort // the step if this happens. if (!decelerating) { return; } double now = Duration.currentTimeMillis(); double framesExpected = Math.floor((now - startTime) / MS_PER_FRAME); // Do at least one step, and more if subsequent steps are not necessary or // if we are falling behind. do { stepWithoutAnimation(); } while (isVelocityAboveThreshold(DECELERATION_STOP_VELOCITY) && (!isStepNecessary() || framesExpected > stepNumber)); double floorY = currentOffset.y; double floorX = currentOffset.x; // If we have moved a whole integer then notify the delegate and update the // previous position. if (decelerating) { delegate.onDecelerate(floorX, floorY, velocity); previousOffset.y = floorY; previousOffset.x = floorX; } // This condition checks of deceleration is over. if (!isBouncing() && !isVelocityAboveThreshold(DECELERATION_STOP_VELOCITY)) { stop(); return; } stepFunction.schedule((int) (MS_PER_FRAME * (1 + stepNumber - framesExpected))); }
From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java
License:Apache License
/** * Touch move handler./* ww w. ja v a2s. c o m*/ * * @param e The touchmove event. */ @SuppressWarnings("unused") private void onMove(final TouchEvent e) { if (!tracking || dragDelegate == null) { return; } // Prevent native scrolling. e.preventDefault(); com.google.gwt.dom.client.Touch touch = getTouchFromEvent(e); Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY()); double moveX = lastTouchPosition.x - touchCoordinate.x; double moveY = lastTouchPosition.y - touchCoordinate.y; totalMoveX += Math.abs(moveX); totalMoveY += Math.abs(moveY); lastTouchPosition.x = touchCoordinate.x; lastTouchPosition.y = touchCoordinate.y; // Handle case where they are getting close to leaving the window. // End events are unreliable when the touch is leaving the viewport area. // If they are close to the bottom or the right, and we don't get any other // touch events for another 100ms, assume they have left the screen. This // does not seem to be a problem for scrolling off the top or left of the // viewport area. if (scrollOffTimer != null) { scrollOffTimer.cancel(); } if ((Window.getClientHeight() - touchCoordinate.y) < TOUCH_END_WORKAROUND_THRESHOLD || (Window.getClientWidth() - touchCoordinate.x) < TOUCH_END_WORKAROUND_THRESHOLD) { scrollOffTimer = new Timer() { @Override public void run() { e.setTimeStamp(Duration.currentTimeMillis()); onEnd(e); } }; scrollOffTimer.schedule(100); } boolean firstDrag = false; if (!dragging) { if (totalMoveY > MIN_TRACKING_FOR_DRAG || totalMoveX > MIN_TRACKING_FOR_DRAG) { dragging = true; firstDrag = true; dragDelegate.onDragStart(e); } } if (dragging) { dragDelegate.onDragMove(e); lastEvent = e; // This happens when they are dragging slowly. If they are dragging slowly // then we should reset the start time and position to where they are now. // This will be important during the drag end when we report to the // draggable delegate what kind of drag just happened. if (e.getTimeStamp() - recentTime > MAX_TRACKING_TIME) { recentTime = e.getTimeStamp(); recentTouchPosition = touchCoordinate; } } }
From source file:com.arcbees.analytics.client.ClientAnalytics.java
License:Apache License
@Override public TimingOptions endTimingEvent(String trackerName, String timingCategory, String timingVariableName) { final String key = getTimingKey(timingCategory, timingVariableName); if (timingEvents.containsKey(key)) { return sendTiming(trackerName, timingCategory, timingVariableName, (int) (Duration.currentTimeMillis() - timingEvents.remove(key))); }// ww w. j a v a 2 s . com return new AnalyticsOptions(new JsonOptionsCallback() { @Override public void onCallback(JSONObject options) { // Do nothing a timing event was ended before it was started. // This is here just to stop a crash. } }).timingOptions(timingCategory, timingVariableName, 0); }
From source file:com.arcbees.analytics.client.ClientAnalytics.java
License:Apache License
@Override public void startTimingEvent(String timingCategory, String timingVariableName) { timingEvents.put(getTimingKey(timingCategory, timingVariableName), Duration.currentTimeMillis()); }
From source file:com.cgxlib.xq.client.plugins.events.EventsListener.java
License:Apache License
public void onBrowserEvent(Event event) { double now = Duration.currentTimeMillis(); // Workaround for Issue_20 if (lastType.equals(event.getType()) && now - lastEvnt < 10 && "body".equalsIgnoreCase(element.getTagName())) { return;// w ww . j a v a 2 s . co m } lastEvnt = now; lastType = event.getType(); // Execute the original Gwt listener if (getOriginalEventListener() != null && getOriginalEventListener() != this) { getOriginalEventListener().onBrowserEvent(event); } dispatchEvent(event); }
From source file:com.goodow.wind.channel.rpc.impl.AjaxRpc.java
License:Apache License
@Override public RpcHandle makeRequest(Method method, String serviceName, MapFromStringToString params, final Rpc.RpcCallback rpcCallback) { final int requestId = nextRequestId; nextRequestId++;/* w ww .jav a2 s.c o m*/ // See the javadoc for HARD_RELOAD. if (connectionState == ConnectionState.HARD_RELOAD) { return new Handle(requestId); } final String requestData; final RequestBuilder.Method httpMethod; StringBuilder urlBuilder = new StringBuilder(rpcRoot + "/" + serviceName + "?"); // NOTE: For some reason, IE6 seems not to perform some requests // it's already made, resulting in... no data. Inserting some // unique value into the request seems to fix that. if (!Browser.getInfo().isWebKit() && !Browser.getInfo().isGecko()) { urlBuilder.append("_no_cache=" + requestId + "" + Duration.currentTimeMillis() + "&"); } if (method == Method.GET) { httpMethod = RequestBuilder.GET; addParams(urlBuilder, params); requestData = ""; } else { httpMethod = RequestBuilder.POST; requestData = addParams(new StringBuilder(), params).toString(); } final String url = urlBuilder.toString(); RequestBuilder r = new RequestBuilder(httpMethod, url); if (method == Method.POST) { r.setHeader("Content-Type", "application/x-www-form-urlencoded"); r.setHeader("X-Same-Domain", "true"); } log.log(Level.INFO, "RPC Request, id=" + requestId + " method=" + httpMethod + " urlSize=" + url.length() + " bodySize=" + requestData.length()); class RpcRequestCallback implements RequestCallback { @Override public void onError(Request request, Throwable exception) { if (!handles.hasKey(requestId)) { log.log(Level.INFO, "RPC FailureDrop, id=" + requestId + " " + exception.getMessage()); return; } removeHandle(); error(exception); } @Override public void onResponseReceived(Request request, Response response) { RpcHandle handle = handles.get(requestId); if (handle == null) { // It's been dropped log.log(Level.INFO, "RPC SuccessDrop, id=" + requestId); return; } // Clear it now, before callbacks removeHandle(); int statusCode = response.getStatusCode(); String data = response.getText(); Result result; if (statusCode < 100) { result = Result.RETRYABLE_FAILURE; maybeSetConnectionState(ConnectionState.OFFLINE); } else if (statusCode == 200) { result = Result.OK; maybeSetConnectionState(ConnectionState.CONNECTED); consecutiveFailures = 0; } else if (statusCode >= 500) { result = Result.RETRYABLE_FAILURE; consecutiveFailures++; if (consecutiveFailures > MAX_CONSECUTIVE_FAILURES) { maybeSetConnectionState(ConnectionState.OFFLINE); } else { maybeSetConnectionState(ConnectionState.CONNECTED); } } else { result = Result.PERMANENT_FAILURE; maybeSetConnectionState(ConnectionState.SOFT_RELOAD); } switch (result) { case OK: log.log(Level.INFO, "RPC Success, id=" + requestId); try { rpcCallback.onSuccess(data); } catch (JsonException e) { // Semi-HACK: Treat parse errors as login problems // due to loading a login or authorization page. (It's unlikely // we'd otherwise get a parse error from a 200 OK result). // The simpler solution of detecting redirects is not possible // with XmlHttpRequest, the web is unfortunately broken. // TODO Possible alternatives: // either change our server side to not require // login through web.xml but to check if UserService says currentUser==null (or // whatever it does if not logged in) and return a well-defined "not logged in" // response instead, or to prefix all responses from the server with a fixed string // (like we do with "OK" elsewhere) and assume not logged in if that prefix is // missing. We could strip off that prefix here and make it transparent to the // callbacks. maybeSetConnectionState(ConnectionState.LOGGED_OUT); error(new Exception("RPC failed due to message exception, treating as auth failure" + ", status code: " + statusCode + ", data: " + data)); } break; case RETRYABLE_FAILURE: error(new Exception("RPC failed, status code: " + statusCode + ", data: " + data)); break; case PERMANENT_FAILURE: fatal(new Exception("RPC bad request, status code: " + statusCode + ", data: " + data)); break; default: throw new AssertionError("Unknown result " + result); } } private void error(Throwable e) { log.log(Level.WARNING, "RPC Failure, id=" + requestId + " " + e.getMessage() + " Request url:" + url, e); rpcCallback.onConnectionError(e); } private void fatal(Throwable e) { log.log(Level.WARNING, "RPC Bad Request, id=" + requestId + " " + e.getMessage() + " Request url:" + url, e); rpcCallback.onFatalError(e); } private void removeHandle() { handles.remove(requestId); } } RpcRequestCallback innerCallback = new RpcRequestCallback(); try { // TODO: store the Request object somewhere so we can e.g. cancel it r.sendRequest(requestData, innerCallback); Handle handle = new Handle(requestId); handles.put(handle.getId(), handle); return handle; } catch (RequestException e) { // TODO: Decide if this should be a badRequest. innerCallback.error(e); return null; } }
From source file:com.google.gwt.demos.gwtcanvas.client.SuiteDemo.java
License:Apache License
@SuppressWarnings("deprecation") private void drawClock() { int a = (int) Duration.currentTimeMillis(); canvas.saveContext();/*from www . j a va 2s.c o m*/ canvas.clear(); canvas.translate(175, 175); canvas.scale(0.8f, 0.8f); canvas.rotate((float) (-Math.PI / 2)); canvas.saveContext(); canvas.beginPath(); canvas.setLineWidth(7); canvas.setStrokeStyle(new Color("#325FA2")); canvas.setFillStyle(new Color("#fff")); canvas.arc(0, 0, 142, 0, (float) (Math.PI * 2), true); canvas.fill(); canvas.arc(0, 0, 142, 0, (float) (Math.PI * 2), true); canvas.stroke(); canvas.restoreContext(); canvas.setStrokeStyle(Color.BLACK); canvas.setFillStyle(Color.WHITE); canvas.setLineWidth(4); canvas.setLineCap("round"); // Hour marks canvas.saveContext(); for (int i = 0; i < 12; ++i) { canvas.beginPath(); canvas.rotate((float) (Math.PI / 6)); canvas.moveTo(100, 0); canvas.lineTo(120, 0); canvas.stroke(); } canvas.restoreContext(); // Minute marks canvas.saveContext(); canvas.setLineWidth(2.5f); for (int i = 0; i < 60; ++i) { if (i % 5 != 0) { canvas.beginPath(); canvas.moveTo(117, 0); canvas.lineTo(120, 0); canvas.stroke(); } canvas.rotate((float) (Math.PI / 30)); } canvas.restoreContext(); Date date = new Date(); int sec = date.getSeconds(); int min = date.getMinutes(); int hr = date.getHours(); hr = (hr >= 12) ? hr - 12 : hr; canvas.setFillStyle(Color.BLACK); // write Hours canvas.saveContext(); canvas.rotate((float) (hr * Math.PI / 6 + Math.PI / 360 * min + Math.PI / 21600 * sec)); canvas.setLineWidth(7); canvas.beginPath(); canvas.moveTo(-20, 0); canvas.lineTo(80, 0); canvas.stroke(); canvas.restoreContext(); // write Minutes canvas.saveContext(); canvas.rotate((float) (Math.PI / 30 * min + Math.PI / 1800 * sec)); canvas.setLineWidth(5); canvas.beginPath(); canvas.moveTo(-28, 0); canvas.lineTo(112, 0); canvas.stroke(); canvas.restoreContext(); // Write seconds canvas.saveContext(); canvas.rotate((float) (sec * Math.PI / 30)); canvas.setStrokeStyle(new Color("#D40000")); canvas.setFillStyle(new Color("#D40000")); canvas.setLineWidth(3); canvas.beginPath(); canvas.moveTo(-30, 0); canvas.lineTo(83, 0); canvas.stroke(); canvas.beginPath(); canvas.moveTo(107, 0); canvas.lineTo(121, 0); canvas.stroke(); canvas.beginPath(); canvas.arc(0, 0, 10, 0, (float) (Math.PI * 2), true); canvas.fill(); canvas.beginPath(); canvas.arc(95, 0, 10, 0, (float) (Math.PI * 2), true); canvas.stroke(); canvas.beginPath(); canvas.setFillStyle(new Color("#555")); canvas.arc(0, 0, 3, 0, (float) (Math.PI * 2), true); canvas.fill(); canvas.restoreContext(); canvas.restoreContext(); int b = (int) Duration.currentTimeMillis() - a; timer.schedule(1000 - b); }
From source file:com.google.speedtracer.client.util.WorkQueue.java
License:Apache License
public void execute() throws RuntimeException { commandQueued = false;// w w w. ja va2s. c o m // Execute the first item off the queue. Node node = queue.remove(0); executeStartTime = Duration.currentTimeMillis(); node.execute(); enqueueCommand(); }