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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations