use of com.google.gwt.user.client.Timer in project rstudio by rstudio.
the class TextEditingTargetWidget method createToolbar.
private Toolbar createToolbar(TextFileType fileType) {
Toolbar toolbar = new EditingTargetToolbar(commands_, true);
toolbar.addLeftWidget(commands_.saveSourceDoc().createToolbarButton());
sourceOnSave_.getElement().getStyle().setMarginRight(0, Unit.PX);
toolbar.addLeftWidget(sourceOnSave_);
srcOnSaveLabel_.getElement().getStyle().setMarginRight(9, Unit.PX);
toolbar.addLeftWidget(srcOnSaveLabel_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands_.checkSpelling().createToolbarButton());
toolbar.addLeftWidget(findReplace_.createFindReplaceButton());
toolbar.addLeftWidget(createCodeTransformMenuButton());
notebookSeparatorWidget_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(notebookToolbarButton_ = commands_.compileNotebook().createToolbarButton());
int mod = BrowseCap.hasMetaKey() ? KeyboardShortcut.META : KeyboardShortcut.CTRL;
String cmdText = new KeyboardShortcut(mod + KeyboardShortcut.SHIFT, 'K').toString(true);
cmdText = DomUtils.htmlToText(cmdText);
notebookToolbarButton_.setTitle("Compile Report (" + cmdText + ")");
texSeparatorWidget_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(texToolbarButton_ = createLatexFormatButton());
toolbar.addLeftSeparator();
toolbar.addLeftWidget(previewHTMLButton_ = commands_.previewHTML().createToolbarButton());
knitDocumentButton_ = commands_.knitDocument().createToolbarButton(false);
knitDocumentButton_.getElement().getStyle().setMarginRight(0, Unit.PX);
toolbar.addLeftWidget(knitDocumentButton_);
toolbar.addLeftWidget(compilePdfButton_ = commands_.compilePDF().createToolbarButton());
rmdFormatButton_ = new ToolbarPopupMenuButton(false, true);
rmdFormatButton_.getMenu().setAutoOpen(true);
toolbar.addLeftWidget(rmdFormatButton_);
runDocumentMenuButton_ = new ToolbarPopupMenuButton(false, true);
addClearKnitrCacheMenu(runDocumentMenuButton_);
runDocumentMenuButton_.addSeparator();
runDocumentMenuButton_.addMenuItem(commands_.clearPrerenderedOutput().createMenuItem(false), "");
toolbar.addLeftWidget(runDocumentMenuButton_);
runDocumentMenuButton_.setVisible(false);
ToolbarPopupMenu rmdOptionsMenu = new ToolbarPopupMenu();
rmdOptionsMenu.addItem(commands_.editRmdFormatOptions().createMenuItem(false));
rmdOptionsButton_ = new ToolbarButton(null, new ImageResource2x(StandardIcons.INSTANCE.options2x()), rmdOptionsMenu, false);
toolbar.addLeftWidget(rmdOptionsButton_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands_.synctexSearch().createToolbarButton());
// create menu of chunk skeletons based on common engine types
ToolbarPopupMenu insertChunksMenu = new ToolbarPopupMenu();
insertChunksMenu.addItem(commands_.insertChunkR().createMenuItem(false));
insertChunksMenu.addSeparator();
if (!BrowseCap.isWindowsDesktop()) {
insertChunksMenu.addItem(commands_.insertChunkBash().createMenuItem(false));
}
insertChunksMenu.addItem(commands_.insertChunkPython().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkRCPP().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkSQL().createMenuItem(false));
insertChunksMenu.addItem(commands_.insertChunkStan().createMenuItem(false));
insertChunkMenu_ = new ToolbarButton("Insert", commands_.insertChunk().getImageResource(), insertChunksMenu, true);
toolbar.addRightWidget(insertChunkMenu_);
// create button that just runs default chunk insertion
insertChunkButton_ = commands_.insertChunk().createToolbarButton(false);
toolbar.addRightWidget(insertChunkButton_);
toolbar.addRightWidget(runButton_ = commands_.executeCode().createToolbarButton(false));
toolbar.addRightSeparator();
toolbar.addRightWidget(runLastButton_ = commands_.executeLastCode().createToolbarButton(false));
toolbar.addRightWidget(goToPrevButton_ = commands_.goToPrevSection().createToolbarButton(false));
toolbar.addRightWidget(goToNextButton_ = commands_.goToNextSection().createToolbarButton(false));
toolbar.addRightSeparator();
final String SOURCE_BUTTON_TITLE = "Source the active document";
sourceButton_ = new ToolbarButton("Source", commands_.sourceActiveDocument().getImageResource(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (uiPrefs_.sourceWithEcho().getValue())
commands_.sourceActiveDocumentWithEcho().execute();
else
commands_.sourceActiveDocument().execute();
}
});
sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
toolbar.addRightWidget(sourceButton_);
uiPrefs_.sourceWithEcho().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue())
sourceButton_.setTitle(SOURCE_BUTTON_TITLE + " (with echo)");
else
sourceButton_.setTitle(SOURCE_BUTTON_TITLE);
}
});
ToolbarPopupMenu sourceMenu = new ToolbarPopupMenu();
sourceMenu.addItem(commands_.sourceActiveDocument().createMenuItem(false));
sourceMenu.addItem(commands_.sourceActiveDocumentWithEcho().createMenuItem(false));
sourceMenuButton_ = new ToolbarButton(sourceMenu, true);
toolbar.addRightWidget(sourceMenuButton_);
//toolbar.addRightSeparator();
ToolbarPopupMenu chunksMenu = new ToolbarPopupMenu();
chunksMenu.addItem(commands_.executeCode().createMenuItem(false));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeCurrentChunk().createMenuItem(false));
chunksMenu.addItem(commands_.executeNextChunk().createMenuItem(false));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeSetupChunk().createMenuItem(false));
chunksMenu.addItem(runSetupChunkOptionMenu_ = new UIPrefMenuItem<Boolean>(uiPrefs_.autoRunSetupChunk(), true, "Run Setup Chunk Automatically", uiPrefs_));
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executePreviousChunks().createMenuItem(false));
chunksMenu.addItem(commands_.executeSubsequentChunks().createMenuItem(false));
if (uiPrefs_.showRmdChunkOutputInline().getValue()) {
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.restartRRunAllChunks().createMenuItem(false));
chunksMenu.addItem(commands_.restartRClearOutput().createMenuItem(false));
}
chunksMenu.addSeparator();
chunksMenu.addItem(commands_.executeAllCode().createMenuItem(false));
chunksButton_ = new ToolbarButton("Run", commands_.executeCode().getImageResource(), chunksMenu, true);
toolbar.addRightWidget(chunksButton_);
ToolbarPopupMenu shinyLaunchMenu = shinyViewerMenu_;
shinyLaunchButton_ = new ToolbarButton(shinyLaunchMenu, true);
shinyLaunchButton_.setVisible(false);
toolbar.addRightWidget(shinyLaunchButton_);
if (SessionUtils.showPublishUi(session_, uiPrefs_)) {
toolbar.addRightSeparator();
publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_APP, false, null);
toolbar.addRightWidget(publishButton_);
}
toggleDocOutlineButton_ = new LatchingToolbarButton("", new ImageResource2x(StandardIcons.INSTANCE.outline2x()), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final double initialSize = editorPanel_.getWidgetSize(docOutlineWidget_);
// Clicking the icon toggles the outline widget's visibility. The
// 'destination' below is the width we would like to set -- we
// animate to that position for a slightly nicer visual treatment.
final double destination = docOutlineWidget_.getOffsetWidth() > 5 ? 0 : Math.min(editorPanel_.getOffsetWidth(), target_.getPreferredOutlineWidgetSize());
// Update tooltip ('Show'/'Hide' depending on current visibility)
String title = toggleDocOutlineButton_.getTitle();
if (destination != 0)
title = title.replace("Show ", "Hide ");
else
title = title.replace("Hide ", "Show ");
toggleDocOutlineButton_.setTitle(title);
toggleDocOutlineButton_.setLatched(destination != 0);
new Animation() {
@Override
protected void onUpdate(double progress) {
double size = destination * progress + initialSize * (1 - progress);
editorPanel_.setWidgetSize(docOutlineWidget_, size);
editor_.onResize();
}
@Override
protected void onComplete() {
target_.setPreferredOutlineWidgetVisibility(destination != 0);
}
}.run(500);
}
});
// Time-out setting the latch just to ensure the document outline
// has actually been appropriately rendered.
new Timer() {
@Override
public void run() {
String title = commands_.toggleDocumentOutline().getTooltip();
title = editorPanel_.getWidgetSize(docOutlineWidget_) > 0 ? title.replace("Show ", "Hide ") : title.replace("Hide ", "Show ");
toggleDocOutlineButton_.setTitle(title);
toggleDocOutlineButton_.setLatched(docOutlineWidget_.getOffsetWidth() > 0);
}
}.schedule(100);
toolbar.addRightSeparator();
toolbar.addRightWidget(toggleDocOutlineButton_);
return toolbar;
}
use of com.google.gwt.user.client.Timer in project rstudio by rstudio.
the class NotebookHtmlRenderer method onRmdRenderPending.
@Override
public void onRmdRenderPending(RmdRenderPendingEvent event) {
if (event.getDocId() != sentinel_.getId())
return;
// wait up to a second for the R Markdown render to start before we
// initiate a render of the notebook
renderTimer_ = new Timer() {
@Override
public void run() {
if (renderCommand_ != null) {
renderCommand_.execute();
}
}
};
renderTimer_.schedule(1000);
}
use of com.google.gwt.user.client.Timer in project rstudio by rstudio.
the class AceThemes method applyTheme.
private void applyTheme(final String themeName) {
// add theme styles
if (currentStyleEl_ != null)
currentStyleEl_.removeFromParent();
currentStyleEl_ = Document.get().createLinkElement();
currentStyleEl_.setType("text/css");
currentStyleEl_.setRel("stylesheet");
currentStyleEl_.setHref(getThemeUrl(themeName));
Document.get().getBody().appendChild(currentStyleEl_);
addDarkClassIfNecessary(themeName);
// Deferred so that the browser can render the styles.
new Timer() {
@Override
public void run() {
events_.fireEvent(new EditorThemeChangedEvent(themeName));
}
}.schedule(100);
}
use of com.google.gwt.user.client.Timer in project playn by threerings.
the class WebGLDemo method onModuleLoad.
@Override
public void onModuleLoad() {
canvas = Document.get().createElement("canvas").cast();
Document.get().getBody().appendChild(canvas);
canvas.setWidth(CANVAS_WIDTH);
canvas.setHeight(CANVAS_HEIGHT);
gl = WebGLRenderingContext.getContext(canvas);
gl.viewport(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
init();
new Timer() {
@Override
public void run() {
draw();
}
}.scheduleRepeating(100);
}
use of com.google.gwt.user.client.Timer in project opentsdb by OpenTSDB.
the class QueryUi method refreshGraph.
private void refreshGraph() {
final Date start = start_datebox.getValue();
if (start == null) {
graphstatus.setText("Please specify a start time.");
return;
}
final Date end = end_datebox.getValue();
if (end != null && !autoreload.getValue()) {
if (end.getTime() <= start.getTime()) {
end_datebox.addStyleName("dateBoxFormatError");
graphstatus.setText("End time must be after start time!");
return;
}
}
final StringBuilder url = new StringBuilder();
url.append("q?start=");
final String start_text = start_datebox.getTextBox().getText();
if (start_text.endsWith(" ago") || start_text.endsWith("-ago")) {
url.append(start_text);
} else {
url.append(FULLDATE.format(start));
}
if (end != null && !autoreload.getValue()) {
url.append("&end=");
final String end_text = end_datebox.getTextBox().getText();
if (end_text.endsWith(" ago") || end_text.endsWith("-ago")) {
url.append(end_text);
} else {
url.append(FULLDATE.format(end));
}
} else {
// If there's no end-time, the graph may change while the URL remains
// the same. No browser seems to re-fetch an image once it's been
// fetched, even if we destroy the DOM object and re-created it with the
// same src attribute. This has nothing to do with caching headers sent
// by the server. The browsers simply won't retrieve the same URL again
// through JavaScript manipulations, period. So as a workaround, we add
// a special parameter that the server will delete from the query.
url.append("&ignore=" + nrequests++);
}
if (global_annotations.getValue()) {
url.append("&global_annotations");
}
if (timezone.length() > 1)
url.append("&tz=").append(timezone);
if (!addAllMetrics(url)) {
return;
}
addLabels(url);
addFormats(url);
addYRanges(url);
addLogscales(url);
if (nokey.getValue()) {
url.append("&nokey");
} else if (!keypos.isEmpty() || horizontalkey.getValue()) {
url.append("&key=");
if (!keypos.isEmpty()) {
url.append(keypos);
}
if (horizontalkey.getValue()) {
url.append(" horiz");
}
if (keybox.getValue()) {
url.append(" box");
}
}
url.append("&wxh=").append(wxh.getText());
if (smooth.getValue()) {
url.append("&smooth=csplines");
}
url.append("&style=").append(styles.getValue(styles.getSelectedIndex()));
if (hide_annotations) {
url.append("&no_annotations=true");
}
if (show_global_annotations) {
url.append("&global_annotations=true");
}
final String unencodedUri = url.toString();
final String uri = URL.encode(unencodedUri);
if (uri.equals(lastgraphuri)) {
// Don't re-request the same graph.
return;
} else if (pending_requests++ > 0) {
return;
}
lastgraphuri = uri;
graphstatus.setText("Loading graph...");
asyncGetJson(uri + "&json", new GotJsonCallback() {
public void got(final JSONValue json) {
if (autoreoload_timer != null) {
autoreoload_timer.cancel();
autoreoload_timer = null;
}
final JSONObject result = json.isObject();
final JSONValue err = result.get("err");
String msg = "";
if (err != null) {
displayError("An error occurred while generating the graph: " + err.isString().stringValue());
graphstatus.setText("Please correct the error above.");
} else {
clearError();
String history = // Remove "q?".
unencodedUri.substring(2).replaceFirst("ignore=[^&]*&", // Unnecessary cruft.
"");
if (autoreload.getValue()) {
history += "&autoreload=" + autoreoload_interval.getText();
}
if (!history.equals(URL.decode(History.getToken()))) {
History.newItem(history, false);
}
final JSONValue nplotted = result.get("plotted");
final JSONValue cachehit = result.get("cachehit");
if (cachehit != null) {
msg += "Cache hit (" + cachehit.isString().stringValue() + "). ";
}
if (nplotted != null && nplotted.isNumber().doubleValue() > 0) {
graph.setUrl(uri + "&png");
graph.setVisible(true);
msg += result.get("points").isNumber() + " points retrieved, " + nplotted + " points plotted";
} else {
graph.setVisible(false);
msg += "Your query didn't return anything";
}
final JSONValue timing = result.get("timing");
if (timing != null) {
msg += " in " + timing + "ms.";
} else {
msg += '.';
}
}
final JSONValue info = result.get("info");
if (info != null) {
if (!msg.isEmpty()) {
msg += ' ';
}
msg += info.isString().stringValue();
}
graphstatus.setText(msg);
if (result.get("etags") != null) {
final JSONArray etags = result.get("etags").isArray();
final int netags = etags.size();
for (int i = 0; i < netags; i++) {
if (i >= metrics.getWidgetCount()) {
break;
}
final Widget widget = metrics.getWidget(i);
if (!(widget instanceof MetricForm)) {
break;
}
final MetricForm metric = (MetricForm) widget;
final JSONArray tags = etags.get(i).isArray();
// Skip if no tags were associated with the query.
if (null != tags) {
for (int j = 0; j < tags.size(); j++) {
metric.autoSuggestTag(tags.get(j).isString().stringValue());
}
}
}
}
if (autoreload.getValue()) {
final int reload_in = Integer.parseInt(autoreoload_interval.getValue());
if (reload_in >= 5) {
autoreoload_timer = new Timer() {
public void run() {
// hasn't been updated in the mean time.
if (autoreload.getValue() && lastgraphuri == uri) {
// Force refreshGraph to believe that we want a new graph.
lastgraphuri = "";
refreshGraph();
}
}
};
autoreoload_timer.schedule(reload_in * 1000);
}
}
if (--pending_requests > 0) {
pending_requests = 0;
refreshGraph();
}
}
});
}
Aggregations