Search in sources :

Example 6 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class PlotsPanePreviewer method getPreviewClientRect.

public Rectangle getPreviewClientRect() {
    WindowEx win = imageFrame_.getElement().<IFrameElementEx>cast().getContentWindow();
    Document doc = win.getDocument();
    NodeList<Element> images = doc.getElementsByTagName("img");
    if (images.getLength() > 0) {
        ElementEx img = images.getItem(0).cast();
        return new Rectangle(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());
    } else {
        return new Rectangle(0, 0, 0, 0);
    }
}
Also used : IFrameElementEx(org.rstudio.core.client.dom.IFrameElementEx) ElementEx(org.rstudio.core.client.dom.ElementEx) Element(com.google.gwt.dom.client.Element) Rectangle(org.rstudio.core.client.Rectangle) WindowEx(org.rstudio.core.client.dom.WindowEx) Document(com.google.gwt.dom.client.Document)

Example 7 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class DesktopExport method export.

public static void export(final ExportPlotSizeEditor sizeEditor, final OperationWithInput<Rectangle> exporter, final Operation onCompleted) {
    sizeEditor.prepareForExport(new Command() {

        @Override
        public void execute() {
            // hide gripper
            sizeEditor.setGripperVisible(false);
            // get zoom level
            double zoomLevel = BrowseCap.isMacintoshDesktop() ? getSafariZoomFactor() : Desktop.getFrame().getZoomLevel();
            // get the preview iframe rect
            ElementEx iframe = sizeEditor.getPreviewIFrame().<ElementEx>cast();
            final Rectangle viewerRect = new Rectangle((int) Math.ceil(zoomLevel * iframe.getClientLeft()), (int) Math.ceil(zoomLevel * iframe.getClientTop()), (int) Math.ceil(zoomLevel * iframe.getClientWidth()), (int) Math.ceil(zoomLevel * iframe.getClientHeight())).inflate(-1);
            // perform the export
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    exporter.execute(viewerRect);
                    // show gripper
                    sizeEditor.setGripperVisible(true);
                    // call onCompleted
                    if (onCompleted != null)
                        onCompleted.execute();
                }
            });
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ElementEx(org.rstudio.core.client.dom.ElementEx) Rectangle(org.rstudio.core.client.Rectangle)

Aggregations

ElementEx (org.rstudio.core.client.dom.ElementEx)7 Document (com.google.gwt.dom.client.Document)3 Rectangle (org.rstudio.core.client.Rectangle)3 Command (com.google.gwt.user.client.Command)2 IFrameElementEx (org.rstudio.core.client.dom.IFrameElementEx)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (com.google.gwt.dom.client.Element)1 NodeList (com.google.gwt.dom.client.NodeList)1 SpanElement (com.google.gwt.dom.client.SpanElement)1 DesktopFrame (org.rstudio.studio.client.application.DesktopFrame)1 ExportPlotSizeEditor (org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor)1 HelpNavigateEvent (org.rstudio.studio.client.workbench.views.help.events.HelpNavigateEvent)1