use of com.google.gwt.user.client.ui.SimplePanel in project rstudio by rstudio.
the class FontDetector method isFontSupported.
public static boolean isFontSupported(String fontName) {
SimplePanel panel = null;
try {
// default font name as a reference point
final String defaultFontName = "Arial";
if (defaultFontName.equals(fontName))
return true;
// make sure canvas is supported
if (!Canvas.isSupported())
return false;
// add a temporary div to the dom
panel = new SimplePanel();
panel.setHeight("200px");
panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
panel.getElement().getStyle().setOverflow(Overflow.SCROLL);
RootPanel.get().add(panel, -2000, -2000);
// add a canvas element to the div and get the 2d drawing context
final Canvas canvas = Canvas.createIfSupported();
canvas.setWidth("512px");
canvas.setHeight("64px");
canvas.getElement().getStyle().setLeft(400, Unit.PX);
canvas.getElement().getStyle().setBackgroundColor("#ffe");
panel.add(canvas);
final Context2d ctx = canvas.getContext2d();
ctx.setFillStyle("#000000");
// closure to generate a hash for a font
class HashGenerator {
public String getHash(String fontName) {
ctx.setFont("57px " + fontName + ", " + defaultFontName);
int width = canvas.getOffsetWidth();
int height = canvas.getOffsetHeight();
ctx.clearRect(0, 0, width, height);
ctx.fillText("TheQuickBrownFox", 2, 50);
return canvas.toDataUrl();
}
}
;
// get hashes and compare them
HashGenerator hashGenerator = new HashGenerator();
String defaultHash = hashGenerator.getHash(defaultFontName);
String fontHash = hashGenerator.getHash(fontName);
return !defaultHash.equals(fontHash);
} catch (Exception ex) {
Debug.log(ex.toString());
return false;
} finally {
if (panel != null)
RootPanel.get().remove(panel);
}
}
use of com.google.gwt.user.client.ui.SimplePanel in project rstudio by rstudio.
the class RStudio method showProgress.
private Command showProgress() {
final Label background = new Label();
background.getElement().getStyle().setZIndex(1000);
background.getElement().getStyle().setBackgroundColor("#e1e2e5");
final RootLayoutPanel rootPanel = RootLayoutPanel.get();
rootPanel.add(background);
rootPanel.setWidgetTopBottom(background, 0, Style.Unit.PX, 0, Style.Unit.PX);
rootPanel.setWidgetLeftRight(background, 0, Style.Unit.PX, 0, Style.Unit.PX);
String progressUrl = ProgressImages.createLargeGray().getUrl();
StringBuilder str = new StringBuilder();
str.append("<img src=\"");
str.append(progressUrl);
str.append("\"");
if (BrowseCap.devicePixelRatio() > 1.0)
str.append("width=24 height=24");
str.append("/>");
final SimplePanel progressPanel = new SimplePanel();
final Element div = progressPanel.getElement();
div.setInnerHTML(str.toString());
div.getStyle().setWidth(100, Style.Unit.PCT);
div.getStyle().setMarginTop(200, Style.Unit.PX);
div.getStyle().setProperty("textAlign", "center");
div.getStyle().setZIndex(1000);
ElementIds.assignElementId(div, ElementIds.LOADING_SPINNER);
rootPanel.add(progressPanel);
return new Command() {
public void execute() {
try {
rootPanel.remove(progressPanel);
rootPanel.remove(background);
} catch (Exception e) {
Debug.log(e.toString());
}
}
};
}
use of com.google.gwt.user.client.ui.SimplePanel in project rstudio by rstudio.
the class HTMLPreviewProgressDialog method createDisplayWidget.
@Override
protected Widget createDisplayWidget(Object param) {
SimplePanel panel = new SimplePanel();
int height = Window.getClientHeight() - 150;
int maxHeight = (Integer) param;
if (maxHeight != -1)
height = Math.min(maxHeight, height);
panel.getElement().getStyle().setHeight(height, Unit.PX);
output_ = new CompileOutputBuffer();
panel.setWidget(output_);
return panel;
}
use of com.google.gwt.user.client.ui.SimplePanel in project rstudio by rstudio.
the class IgnoreDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.add(dirChooser_);
verticalPanel.add(ignoresCaption_);
final String aceWidth = "400px";
final String aceHeight = "300px";
Widget editorWidget = editor_.getWidget();
editorWidget.setSize(aceWidth, aceHeight);
SimplePanel panel = new SimplePanel();
panel.addStyleName(RES.styles().editorFrame());
panel.setSize(aceWidth, aceHeight);
panel.setWidget(editor_.getWidget());
verticalPanel.add(panel);
return verticalPanel;
}
use of com.google.gwt.user.client.ui.SimplePanel in project rstudio by rstudio.
the class EditSnippetsDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
panel_ = new DockLayoutPanel(Unit.PX);
// compute the widget size and set it
Size size = new Size(900, 900);
size = DomMetrics.adjustedElementSize(size, null, // pad
70, // client margin
100);
panel_.setWidth(size.width + "px");
panel_.setHeight(size.height + "px");
// snippet types
snippetTypes_ = new WidgetListBox<EditableSnippets>();
snippetTypes_.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
updateEditor(snippetTypes_.getSelectedItem());
}
});
snippetTypes_.addItem(new EditableSnippets("R", FileTypeRegistry.R));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.CPP));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.MARKDOWN));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.TEX));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.JS));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.HTML));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.CSS));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.SQL));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.JAVA));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.PYTHON));
snippetTypes_.addItem(new EditableSnippets(FileTypeRegistry.STAN));
panel_.addWest(snippetTypes_, 150);
// editor
docDisplay_ = new AceEditor();
docDisplay_.setUseSoftTabs(false);
docDisplay_.setTabSize(uiPrefs_.numSpacesForTab().getValue());
docDisplay_.addValueChangeHandler(new ValueChangeHandler<Void>() {
@Override
public void onValueChange(ValueChangeEvent<Void> event) {
editorDirty_ = true;
}
});
docDisplay_.setFileType(FileTypeRegistry.SNIPPETS);
SimplePanel panel = new SimplePanel();
panel.addStyleName("EditDialog");
panel.getElement().getStyle().setMarginLeft(8, Unit.PX);
panel.setWidget(docDisplay_.asWidget());
panel_.add(panel);
TextEditingTarget.syncFontSize(releaseOnDismiss_, events_, this, fontSizeManager_);
snippetTypes_.setSelectedIndex(0, true);
return panel_;
}
Aggregations