Search in sources :

Example 36 with SimplePanel

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);
    }
}
Also used : Context2d(com.google.gwt.canvas.dom.client.Context2d) Canvas(com.google.gwt.canvas.client.Canvas) SimplePanel(com.google.gwt.user.client.ui.SimplePanel)

Example 37 with SimplePanel

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());
            }
        }
    };
}
Also used : Command(com.google.gwt.user.client.Command) Element(com.google.gwt.dom.client.Element) Label(com.google.gwt.user.client.ui.Label) SlideLabel(org.rstudio.core.client.widget.SlideLabel) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) RootLayoutPanel(com.google.gwt.user.client.ui.RootLayoutPanel)

Example 38 with SimplePanel

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;
}
Also used : SimplePanel(com.google.gwt.user.client.ui.SimplePanel) CompileOutputBuffer(org.rstudio.studio.client.common.compile.CompileOutputBuffer)

Example 39 with SimplePanel

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;
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Widget(com.google.gwt.user.client.ui.Widget) SimplePanel(com.google.gwt.user.client.ui.SimplePanel)

Example 40 with SimplePanel

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_;
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) DockLayoutPanel(com.google.gwt.user.client.ui.DockLayoutPanel) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Size(org.rstudio.core.client.Size) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) Void(org.rstudio.studio.client.server.Void)

Aggregations

SimplePanel (com.google.gwt.user.client.ui.SimplePanel)60 Label (com.google.gwt.user.client.ui.Label)19 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)14 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)9 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 HTML (com.google.gwt.user.client.ui.HTML)7 Test (org.junit.Test)5 Element (com.google.gwt.dom.client.Element)4 Style (com.google.gwt.dom.client.Style)4 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 Button (com.google.gwt.user.client.ui.Button)4 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)4 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)3 Image (com.google.gwt.user.client.ui.Image)3 Widget (com.google.gwt.user.client.ui.Widget)3 HorizontalScrollWrapper (org.pentaho.mantle.client.ui.custom.HorizontalScrollWrapper)3 ListBoxTitle (org.pentaho.mantle.client.ui.custom.ListBoxTitle)3 Context (com.google.gwt.cell.client.Cell.Context)2