Search in sources :

Example 11 with Size

use of org.rstudio.core.client.Size in project rstudio by rstudio.

the class DomMetrics method measureHTML.

public static Size measureHTML(String html, String styleName) {
    // create HTML widget which matches the specified style
    HTML measureHTML = new HTML();
    measureHTML.setStyleName(styleName);
    measureHTML.getElement().getStyle().setFloat(Style.Float.LEFT);
    measureHTML.setWordWrap(false);
    // add it to the dom (hidden)
    RootPanel.get().add(measureHTML, -2000, -2000);
    // insert the text (preformatted) and measure it
    measureHTML.setHTML(html);
    Size textSize = new Size(measureHTML.getOffsetWidth(), measureHTML.getOffsetHeight());
    RootPanel.get().remove(measureHTML);
    // return the size
    return textSize;
}
Also used : Size(org.rstudio.core.client.Size) HTML(com.google.gwt.user.client.ui.HTML)

Example 12 with Size

use of org.rstudio.core.client.Size in project rstudio by rstudio.

the class DomMetrics method adjustedCodeElementSize.

public static Size adjustedCodeElementSize(String code, int contentPad, int clientMargin) {
    // line numbers
    final int LINE_NUMBERS_WIDTH = 100;
    // calculate the size of the text the adjust for line numbers
    Size textSize = DomMetrics.measureCode(code);
    textSize = new Size(textSize.width + LINE_NUMBERS_WIDTH, textSize.height);
    // compute the editor size
    Size minimumSize = new Size(300, 200);
    Size editorSize = DomMetrics.adjustedElementSize(textSize, minimumSize, contentPad, clientMargin);
    return editorSize;
}
Also used : Size(org.rstudio.core.client.Size)

Example 13 with Size

use of org.rstudio.core.client.Size in project rstudio by rstudio.

the class DomMetrics method adjustedElementSizeToDefaultMax.

public static Size adjustedElementSizeToDefaultMax() {
    Size size = new Size(Window.getClientWidth(), Window.getClientHeight());
    size = DomMetrics.adjustedElementSize(size, null, // pad
    70, // client margin
    100);
    return size;
}
Also used : Size(org.rstudio.core.client.Size)

Example 14 with Size

use of org.rstudio.core.client.Size in project rstudio by rstudio.

the class ScreenUtils method getAdjustedWindowSize.

public static Size getAdjustedWindowSize(Size preferredSize) {
    // compute available height (trim to max)
    NativeScreen screen = NativeScreen.get();
    int height = Math.min(screen.getAvailHeight(), preferredSize.height);
    // trim height for large monitors
    if (screen.getAvailHeight() >= (preferredSize.height - 100)) {
        if (BrowseCap.isMacintosh())
            height = height - 107;
        else if (BrowseCap.isWindows())
            height = height - 89;
        else
            height = height - 80;
    } else {
        // adjust for window framing, etc.
        if (Desktop.isDesktop())
            height = height - 40;
        else
            height = height - 60;
        // extra adjustment for firefox on windows (extra chrome in url bar)
        if (BrowseCap.isWindows() && BrowseCap.isFirefox())
            height = height - 25;
    }
    // available height, excluding the menubar/taskbar)
    if (BrowseCap.isLinux() && BrowseCap.isChrome())
        height = height - 50;
    // compute width (trim to max)
    int width = Math.min(preferredSize.width, screen.getAvailWidth() - 20);
    // return size
    return new Size(width, height);
}
Also used : Size(org.rstudio.core.client.Size) NativeScreen(org.rstudio.core.client.dom.NativeScreen)

Example 15 with Size

use of org.rstudio.core.client.Size in project rstudio by rstudio.

the class SatelliteManager method openSatellite.

// open a satellite window (optionally activate existing)
public void openSatellite(String name, JavaScriptObject params, Size preferredSize, boolean adjustSize, Point position, boolean activate) {
    // if we don't need to.
    if (isCurrentWindowSatellite()) {
        Debug.log("Satellite windows can't launch other satellites");
        assert false;
        return;
    }
    // check for a re-activation of an existing window
    for (ActiveSatellite satellite : satellites_) {
        if (satellite.getName().equals(name)) {
            WindowEx window = satellite.getWindow();
            if (!window.isClosed()) {
                // it that it has been reactivated, then exit. 
                if (!Desktop.isDesktop()) {
                    // window will be reloaded)
                    if (!BrowseCap.isChrome() || !activate) {
                        if (activate)
                            window.focus();
                        callNotifyReactivated(window, params);
                        return;
                    } else {
                        // for Chrome, let the window know it's about to be 
                        // closed and reopened
                        callNotifyPendingReactivate(window);
                    }
                } else // desktop mode: activate and return
                {
                    if (activate) {
                        Desktop.getFrame().activateSatelliteWindow(SatelliteUtils.getSatelliteWindowName(satellite.getName()));
                    }
                    callNotifyReactivated(window, params);
                    return;
                }
            }
        }
    }
    // anything while the satellite is being loaded/reactivated
    if (!pendingEventsBySatelliteName_.containsKey(name)) {
        pendingEventsBySatelliteName_.put(name, new ArrayList<JavaScriptObject>());
    }
    // by the satellite within the call to registerAsSatellite)
    if (params != null)
        satelliteParams_.put(name, params);
    // set size and position, if desired
    Size windowSize = adjustSize ? ScreenUtils.getAdjustedWindowSize(preferredSize) : preferredSize;
    NewWindowOptions options = new NewWindowOptions();
    options.setFocus(activate);
    if (position != null)
        options.setPosition(position);
    // open the satellite - it will call us back on registerAsSatellite
    // at which time we'll call setSessionInfo, setParams, etc.
    RStudioGinjector.INSTANCE.getGlobalDisplay().openSatelliteWindow(name, windowSize.width, windowSize.height, options);
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) NewWindowOptions(org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions) Size(org.rstudio.core.client.Size) WindowEx(org.rstudio.core.client.dom.WindowEx)

Aggregations

Size (org.rstudio.core.client.Size)26 WindowEx (org.rstudio.core.client.dom.WindowEx)5 HTML (com.google.gwt.user.client.ui.HTML)2 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)2 Widget (com.google.gwt.user.client.ui.Widget)2 Point (org.rstudio.core.client.Point)2 Handler (org.rstudio.core.client.command.Handler)2 NativeScreen (org.rstudio.core.client.dom.NativeScreen)2 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 NewWindowOptions (org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions)2 VCSApplicationParams (org.rstudio.studio.client.vcs.VCSApplicationParams)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Document (com.google.gwt.dom.client.Document)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 JSONString (com.google.gwt.json.client.JSONString)1 Command (com.google.gwt.user.client.Command)1 DockLayoutPanel (com.google.gwt.user.client.ui.DockLayoutPanel)1