use of org.rstudio.core.client.Size in project rstudio by rstudio.
the class ZoomUtils method getZoomWindowSize.
public static Size getZoomWindowSize(Size sourceFrameSize, Size defaultSize) {
int width, height;
if (defaultSize != null) {
// trim based on available screen size
NativeScreen screen = NativeScreen.get();
width = Math.min(screen.getAvailWidth(), defaultSize.width);
height = Math.min(screen.getAvailHeight(), defaultSize.height);
} else {
final int PADDING = 20;
// calculate ideal heigh and width. try to be as large as possible
// within the bounds of the current client size
Size bounds = new Size(Window.getClientWidth() - PADDING, Window.getClientHeight() - PADDING);
float widthRatio = bounds.width / ((float) sourceFrameSize.width);
float heightRatio = bounds.height / ((float) sourceFrameSize.height);
float ratio = Math.min(widthRatio, heightRatio);
// constrain initial width to between 300 and 1,200 pixels
width = Math.max(300, (int) (ratio * sourceFrameSize.width));
width = Math.min(1200, width);
// constrain initial height to between 300 and 900 pixels
height = Math.max(300, (int) (ratio * sourceFrameSize.height));
height = Math.min(900, height);
}
return new Size(width, height);
}
use of org.rstudio.core.client.Size in project rstudio by rstudio.
the class ShinyGadgetDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
frame_ = new RStudioFrame();
frame_.addStyleName(ThemeStyles.INSTANCE.borderedIFrame());
// compute the widget size and set it
Size minimumSize = new Size(300, 300);
Size size = DomMetrics.adjustedElementSize(preferredSize_, minimumSize, // pad
0, // client margin
100);
frame_.setSize(size.width + "px", size.height + "px");
if (Desktop.isDesktop())
Desktop.getFrame().setShinyDialogUrl(url_);
frame_.setUrl(url_);
return frame_;
}
use of org.rstudio.core.client.Size in project rstudio by rstudio.
the class ExportPlotDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
VerticalPanel mainPanel = new VerticalPanel();
// enforce maximum initial dimensions based on screen size
Size maxSize = new Size(Window.getClientWidth() - 100, Window.getClientHeight() - 200);
int width = Math.min(options_.getWidth(), maxSize.width);
int height = Math.min(options_.getHeight(), maxSize.height);
sizeEditor_ = new ExportPlotSizeEditor(width, height, options_.getKeepRatio(), createTopLeftWidget(), previewer_, new ExportPlotSizeEditor.Observer() {
@Override
public void onResized(boolean withMouse) {
if (!withMouse)
center();
}
});
mainPanel.add(sizeEditor_);
Widget bottomWidget = createBottomWidget();
if (bottomWidget != null)
mainPanel.add(bottomWidget);
return mainPanel;
}
use of org.rstudio.core.client.Size in project rstudio by rstudio.
the class ShinyApplication method activateWindow.
private void activateWindow(ShinyApplicationParams params) {
WindowEx win = satelliteManager_.getSatelliteWindowObject(ShinyApplicationSatellite.NAME);
boolean isRefresh = win != null && (params == null || (params_ != null && params.getPath().equals(params_.getPath())));
boolean isChrome = !Desktop.isDesktop() && BrowseCap.isChrome();
if (params != null)
params_ = params;
if (win == null || (!isRefresh && !isChrome)) {
// If there's no window yet, or we're switching apps in a browser
// other than Chrome, do a normal open
satelliteManager_.openSatellite(ShinyApplicationSatellite.NAME, params_, new Size(960, 1100));
} else if (isChrome) {
// we have a window and we're Chrome, so force a close and reopen
satelliteManager_.forceReopenSatellite(ShinyApplicationSatellite.NAME, params_, true);
} else {
satelliteManager_.activateSatelliteWindow(ShinyApplicationSatellite.NAME);
}
}
use of org.rstudio.core.client.Size 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