use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class MathJaxLoader method ensureMathJaxLoaded.
public static void ensureMathJaxLoaded() {
if (MATHJAX_LOADED)
return;
initializeMathJaxConfig();
ScriptElement mathJaxEl = createMathJaxScriptElement();
HeadElement headEl = Document.get().getHead();
headEl.appendChild(mathJaxEl);
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
if (isMathJaxReady()) {
MATHJAX_LOADED = true;
for (Callback callback : MATHJAX_CALLBACKS) callback.onLoaded(false);
onMathJaxLoaded();
return false;
}
RETRY_COUNT++;
return RETRY_COUNT < 50;
}
}, 500);
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class DiagnosticsBackgroundPopup method start.
public void start() {
isRunning_ = true;
stopRequested_ = false;
if (handler_ != null) {
handler_.removeHandler();
handler_ = null;
}
handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONMOUSEMOVE) {
movedMouseMostRecently_ = true;
Element target = Element.as(event.getNativeEvent().getEventTarget());
if (target.hasClassName("ace_gutter-cell")) {
lastMouseCoords_ = null;
hidePopup();
return;
}
lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
hidePopup();
}
} else {
movedMouseMostRecently_ = false;
}
}
});
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
if (stopRequested_)
return stopExecution();
// restarted later)
if (!docDisplay_.isFocused())
return stopExecution();
long currentTime = System.currentTimeMillis();
long lastModifiedTime = docDisplay_.getLastModifiedTime();
long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
// cursor was moved recently, then bail
if ((currentTime - lastModifiedTime) < 500)
return completeExecution();
if ((currentTime - lastCursorChangedTime) < 500)
return completeExecution();
Markers markers = editor_.getSession().getMarkers(true);
Position currentPos;
if (movedMouseMostRecently_) {
if (lastMouseCoords_ == null)
return completeExecution();
currentPos = editor_.toDocumentPosition(lastMouseCoords_);
} else {
currentPos = docDisplay_.getCursorPosition();
}
int[] keys = markers.getIds();
for (int i = 0; i < keys.length; i++) {
Marker marker = markers.get(keys[i]);
if (marker.getRange().containsRightExclusive(currentPos)) {
displayMarkerDiagnostics(marker);
return completeExecution();
}
}
return completeExecution();
}
}, 500);
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class HelpPane method setLocation.
private void setLocation(final String url) {
// allow subsequent calls to setLocation to override any previous
// call (necessary so two consecutive calls like we get during
// some startup scenarios don't result in the first url displaying
// rather than the second)
targetUrl_ = url;
RepeatingCommand navigateCommand = new RepeatingCommand() {
@Override
public boolean execute() {
if (getIFrameEx() != null && getIFrameEx().getContentWindow() != null) {
if (targetUrl_.equals(getUrl())) {
getIFrameEx().getContentWindow().reload();
} else {
frame_.setUrl(targetUrl_);
replaceFrameUrl(frame_.getIFrame().cast(), targetUrl_);
}
return false;
} else {
return true;
}
}
};
if (navigateCommand.execute())
Scheduler.get().scheduleFixedDelay(navigateCommand, 100);
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class AceEditorWidget method onLoad.
@Override
protected void onLoad() {
super.onLoad();
editor_.getRenderer().updateFontSize();
onResize();
fireEvent(new EditorLoadedEvent(editor_));
events_.fireEvent(new EditorLoadedEvent(editor_));
int delayMs = initToEmptyString_ ? 100 : 500;
// On Windows desktop sometimes we inexplicably end up at the wrong size
// if the editor is being resized while it's loading (such as when a new
// document is created while the source pane is hidden)
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
public boolean execute() {
if (isAttached())
onResize();
removeStyleName("loading");
return false;
}
}, delayMs);
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class PdfJsWindow method navigateTo.
public static void navigateTo(final PdfJsWindow win, final PdfLocation pdfLocation) {
double factor = win.getCurrentScale() * 96 / 72;
final double x = pdfLocation.getX() * factor;
final double y = pdfLocation.getY() * factor;
final double w = pdfLocation.getWidth() * factor;
final double h = pdfLocation.getHeight() * factor;
final Value<Integer> retries = new Value<Integer>(0);
// Sometimes pageContainer is null during load, so retry every 100ms
// until it's not, or we've tried 40 times.
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
Element pageContainer = win.getDocument().getElementById("pageContainer" + pdfLocation.getPage());
if (pageContainer == null) {
retries.setValue(retries.getValue() + 1);
return retries.getValue() < 40;
}
if (pdfLocation.isFromClick()) {
final DivElement div = win.getDocument().createDivElement();
div.getStyle().setPosition(Style.Position.ABSOLUTE);
div.getStyle().setTop(y, Unit.PX);
div.getStyle().setLeft(x, Unit.PX);
div.getStyle().setWidth(w, Unit.PX);
div.getStyle().setHeight(h, Unit.PX);
div.getStyle().setBackgroundColor("rgba(0, 126, 246, 0.1)");
div.getStyle().setProperty("transition", "opacity 4s");
// use DomUtils to set transition styles so gwt doesn't assert
// an invalid style name (no camelCase) in debug mode
DomUtils.setStyle(div, "-moz-transition", "opacity 4s");
DomUtils.setStyle(div, "-webkit-transition", "opacity 4s");
pageContainer.appendChild(div);
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
div.getStyle().setOpacity(0.0);
return false;
}
}, 2000);
}
// scroll to the page
win.goToPage(pdfLocation.getPage());
// if the target isn't on-screen then scroll to it
SyncTexCoordinates boundary = getBoundaryCoordinates(win, false);
if (boundary != null && pdfLocation.getY() > boundary.getY()) {
Element container = getViewerContainer(win);
container.setScrollTop(Math.max(0, DomUtils.topRelativeTo(getViewerContainer(win), pageContainer) + (int) y - 180));
}
win.focus();
return false;
}
}, 100);
}
Aggregations