Example usage for com.google.gwt.user.client.ui CellPanel setSpacing

List of usage examples for com.google.gwt.user.client.ui CellPanel setSpacing

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui CellPanel setSpacing.

Prototype

public void setSpacing(int spacing) 

Source Link

Document

Sets the amount of spacing between this panel's cells.

Usage

From source file:edu.caltech.ipac.firefly.commands.DynSearchCmd.java

protected DockLayoutPanel processSplitPanel(SplitPanelTag sp, Request inputReq, WidgetFactory factory,
        EventHub hub, PrimaryTableUILoader loader) {

    DynData hData = (DynData) Application.getInstance().getAppData(DynUtils.HYDRA_APP_DATA);

    SplitLayoutPanelFirefly slp = new SplitLayoutPanelFirefly();
    hub.bind(slp);/*from   w  ww .ja  va  2  s. c o m*/
    //        SplitLayoutPanel slp = new SplitLayoutPanel();
    slp.setSize("100%", "100%");
    slp.setMinCenterSize(30, 120);
    GwtUtil.setStyle(slp, "overflowX", "auto");

    LinkedHashSet<LayoutAreaTag> laTags = sp.getLayoutAreas();
    boolean centerAdded = false;
    for (LayoutAreaTag laTag : laTags) {
        if (centerAdded) {
            DynUtils.PopupMessage("XML Error",
                    "XML configuration file is invalid!  Center layouts must be added last within a SplitPanel!");
            break;
        }

        // if groupId set, store widget and parent splitlayoutpanel
        DynData.SplitLayoutPanelData panelData = null;
        String groupId = laTag.getGroupId();
        if (groupId != null) {
            panelData = new DynData.SplitLayoutPanelData(slp);
        }

        LayoutAreaTag.LayoutDirection dir = laTag.getType();
        boolean doTag = Boolean.parseBoolean(String.valueOf(laTag.getTagIt()));

        List<SplitPanelTag> spList = laTag.getSplitPanels();
        for (SplitPanelTag spItem : spList) {
            DockLayoutPanel slp2 = processSplitPanel(spItem, inputReq, factory, hub, loader);

            switch (dir) {
            case NORTH:
                slp.addNorth(slp2, laTag.getIntialHeight());
                break;

            case SOUTH:
                slp.addSouth(slp2, laTag.getIntialHeight());
                break;

            case EAST:
                slp.addEast(slp2, laTag.getIntialWidth());
                break;

            case WEST:
                slp.addWest(slp2, laTag.getIntialWidth());
                break;

            case CENTER:
                slp.add(slp2);
                centerAdded = true;
            }
        }

        List<FormTag> fList = laTag.getForms();
        if (fList != null && fList.size() > 0) {
            for (FormTag f : fList) {
                final String title = f.getTitle();
                final String helpId = StringUtils.isEmpty(f.getHelpId()) ? null : f.getHelpId();
                final Form form = GwtUtil.createForm(f, hub, null);
                form.getFieldCount(); // adds listeners

                Toolbar.CmdButton button = new Toolbar.CmdButton(title, title, title, new Command() {
                    public void execute() {
                        PopupUtil.showDialog(Application.getInstance().getToolBar(), form, title, "Done",
                                helpId);
                    }
                });
                Application.getInstance().getToolBar().addButton(button);
                WebEventManager.getAppEvManager().addListener(Name.SEARCH_RESULT_START, new WebEventListener() {
                    public void eventNotify(WebEvent ev) {
                        Application.getInstance().getToolBar().removeButton(title);
                        WebEventManager.getAppEvManager().removeListener(this);
                    }
                });
            }
        }

        String layoutType = laTag.getLayout();
        TabPane tp = null;
        CellPanel container = null;

        if (layoutType != null
                && (layoutType.equalsIgnoreCase("tab") || layoutType.equalsIgnoreCase("fixedTab"))) {
            tp = new TabPane();
            tp.setSize("100%", "100%");

            String tpName = laTag.getLayoutName();
            if (!StringUtils.isEmpty(tpName)) {
                tp.setTabPaneName(tpName);
            }

            if (layoutType.equalsIgnoreCase("tab")) {
                new NewTableEventHandler(hub, tp);
            }

        } else if (layoutType != null) {
            container = layoutType.equalsIgnoreCase("horizontal") ? new HorizontalPanel() : new VerticalPanel();
            container.setSize("100%", "100%");
            container.setSpacing(5);
            GwtUtil.setStyles(container, "borderSpacing", "10px 5px", "tableLayout", "fixed");
        }

        if (laTag.getId() != null) {
            tp.getElement().setId(laTag.getId());
        }

        List<LayoutContentTypeTag> lctList = laTag.getLayoutContentTypes();
        for (LayoutContentTypeTag lct : lctList) {
            if (lct instanceof TableTag) {
                TableTag t = (TableTag) lct;
                String queryId = t.getQueryId();

                // check constraintsTag
                boolean constraintCheck = true;
                List<QueryTag> queryTagList = searchTypeTag.getQueries();
                QueryTag queryTag = null;

                for (QueryTag q : queryTagList) {
                    if (queryId.equalsIgnoreCase(q.getId())) {
                        queryTag = q;

                        constraintCheck = checkConstraints(q.getConstraints(), inputReq);

                        // tables only have 1 QuerySource
                        break;
                    }
                }

                if (queryTag != null && constraintCheck) {
                    String searchProcessorId = queryTag.getSearchProcessorId();
                    if (searchProcessorId != null) {
                        Map<String, String> tableParams = new HashMap<String, String>();
                        tableParams.put(TablePanelCreator.TITLE, t.getTitle());
                        tableParams.put(TablePanelCreator.SHORT_DESC, t.getShortDescription());
                        tableParams.put(TablePanelCreator.QUERY_SOURCE, t.getQueryId());

                        List<ParamTag> pList = t.getParams();
                        for (ParamTag p : pList) {
                            tableParams.put(p.getKey(), p.getValue());
                        }

                        TableServerRequest tsReq = new TableServerRequest(searchProcessorId, inputReq);

                        tsReq.setParam(DynUtils.QUERY_ID, t.getQueryId());

                        // get query params
                        List<ParamTag> paramTagList = queryTag.getParams();
                        for (ParamTag p : paramTagList) {
                            tsReq.setParam(p.getKey(), p.getValue());
                        }

                        tableParams.put("QUERY_ID", searchProcessorId);

                        String tableType = t.getType();
                        final PrimaryTableUI primary = factory.createPrimaryUI(tableType, tsReq, tableParams);

                        DownloadTag dlTag = queryTag.getDownload();
                        DynDownloadSelectionDialog ddsd = DynUtils.makeDownloadDialog(dlTag, getForm());
                        if (ddsd != null) {
                            String dlId = dlTag.getId();

                            List<ParamTag> dlParams = dlTag.getParams();
                            List<SearchFormParamTag> sfParams = dlTag.getSearchFormParams();
                            for (SearchFormParamTag sfpt : sfParams) {
                                DynUtils.evaluateSearchFormParam(getForm(), sfpt, dlParams);
                            }

                            String downloadTitle = dlTag.getTitlePrefix();
                            if (!StringUtils.isEmpty(inputReq.getShortDesc())) {
                                downloadTitle += " " + inputReq.getShortDesc();
                            }
                            downloadTitle += " Search";
                            primary.addDownloadButton(ddsd, dlId, dlTag.getFilePrefix(), downloadTitle,
                                    DynUtils.convertToParamList(dlParams));
                        }

                        // process view, if exists
                        List<ViewTag> tviews = t.getViews();
                        if (tviews != null) {
                            HashMap<String, String> formFields = new HashMap<String, String>();
                            for (Param p : inputReq.getParams()) {
                                formFields.put(p.getName(), p.getValue());
                            }

                            for (ViewTag v : tviews) {
                                String vqueryId = !StringUtils.isEmpty(v.getQueryId()) ? v.getQueryId()
                                        : queryId;
                                Map<String, String> params = new HashMap<String, String>();
                                params.putAll(formFields);
                                params.put(DynUtils.QUERY_ID, vqueryId);
                                for (ParamTag pt : v.getParams()) {
                                    params.put(pt.getKey(), pt.getValue());
                                }
                                TablePanel.View view = factory.createTablePanelView(v.getType(), params);
                                if (primary instanceof TablePrimaryDisplay) {
                                    view.bind(hub);
                                    ((TablePrimaryDisplay) primary).getTable().addView(view);
                                }
                            }
                        }

                        if (primary != null)
                            primary.bind(hub);

                        loader.addTable(primary);

                        if (t.getId() != null) {
                            primary.getDisplay().getElement().setId(t.getId());
                        }

                        if (tp != null) {
                            tp.addTab(primary.getDisplay(), t.getTitle(), t.getShortDescription(), false);

                        } else if (container != null) {
                            //                                Widget w = createShadowTitlePanel(primary.getDisplay(), primary.getShortDesc(), laTag.getHelpId(), doTag);
                            SimplePanel wrapper = new SimplePanel();
                            wrapper.add(primary.getDisplay());
                            wrapper.setStyleName("shadow");
                            wrapper.addStyleName("expand-fully");
                            //                                w.setSize(getInitSizeStr(laTag.getIntialWidth()), getInitSizeStr(laTag.getIntialHeight()));
                            container.add(wrapper);
                            if (layoutType.equalsIgnoreCase("horizontal")) {
                                container.setCellHeight(wrapper, "100%");
                                container.setCellWidth(wrapper, 100 / lctList.size() + "%");
                            } else {
                                container.setCellWidth(wrapper, "100%");
                                container.setCellHeight(wrapper, 100 / lctList.size() + "%");
                            }
                        } else {
                            Widget w = createShadowTitlePanel(primary.getDisplay(), primary.getShortDesc(),
                                    laTag.getHelpId(), doTag);
                            switch (dir) {
                            case NORTH:
                                slp.addNorth(w, laTag.getIntialHeight());
                                break;

                            case SOUTH:
                                slp.addSouth(w, laTag.getIntialHeight());
                                break;

                            case EAST:
                                slp.addEast(w, laTag.getIntialWidth());
                                break;

                            case WEST:
                                slp.addWest(w, laTag.getIntialWidth());
                                break;

                            case CENTER:
                                slp.add(w);
                                centerAdded = true;
                            }
                        }
                    }
                }

            } else if (lct instanceof PreviewTag) {
                PreviewTag pv = (PreviewTag) lct;
                List<String> queryIds = pv.getQueryIds();

                // check constraintsTag of all possible queries
                boolean constraintCheck = false;

                if (queryIds != null) {
                    List<QueryTag> queryTagList = searchTypeTag.getQueries();
                    for (String queryId : queryIds) {
                        List<String> qIdList = StringUtils.asList(queryId, ",");

                        for (QueryTag q : queryTagList) {
                            if (qIdList.contains(q.getId())) {
                                constraintCheck = constraintCheck
                                        || checkConstraints(q.getConstraints(), inputReq);
                            }
                        }
                    }
                }
                ConstraintsTag c = pv.getConstraints();
                if (c != null) {
                    constraintCheck = constraintCheck && checkConstraints(c, inputReq);
                }

                if (queryIds == null || constraintCheck) {
                    Map<String, String> previewParams = new HashMap<String, String>();
                    List<ParamTag> pList = pv.getParams();
                    for (ParamTag p : pList) {
                        String key = p.getKey();
                        String value = p.getValue();

                        previewParams.put(key, value);
                    }

                    if (queryIds != null) {
                        previewParams.put("QUERY_ID", StringUtils.toString(queryIds, ","));
                    }

                    List<String> eventWorkerIds = pv.getEventWorkerIds();
                    if (eventWorkerIds != null) {
                        previewParams.put("EVENT_WORKER_ID", StringUtils.toString(eventWorkerIds, ","));
                    }

                    String previewType = pv.getType();
                    TablePreview preview = factory.createObserverUI(previewType, previewParams);

                    String previewId = pv.getId();
                    if (previewId != null) {
                        preview.setID(previewId);
                    }

                    if (preview != null)
                        preview.bind(hub);

                    if (tp != null) {
                        tp.addTab(preview.getDisplay(), pv.getTitle(), pv.getShortDescription(), false);

                    } else if (container != null) {
                        //                            Widget pw = createPreviewPanel(preview, pv.getFrameType(), laTag.getHelpId(), doTag);
                        //                            pw.setSize(getInitSizeStr(laTag.getIntialWidth()), getInitSizeStr(laTag.getIntialHeight()));
                        ResizablePanel wrapper = new ResizablePanel();
                        wrapper.add(preview.getDisplay());
                        wrapper.setStyleName("shadow");
                        wrapper.addStyleName("expand-fully");
                        container.add(wrapper);
                        if (layoutType.equalsIgnoreCase("horizontal")) {
                            container.setCellHeight(wrapper, "100%");
                        } else {
                            container.setCellWidth(wrapper, "100%");
                        }
                    } else {
                        Widget pw = createPreviewPanel(preview, pv.getFrameType(), laTag.getHelpId(), doTag);
                        Double size = null;
                        switch (dir) {
                        case NORTH:
                            size = new Double(laTag.getIntialHeight());
                            slp.addNorth(pw, size);

                            break;

                        case SOUTH:
                            size = new Double(laTag.getIntialHeight());
                            slp.addSouth(pw, size);
                            break;

                        case EAST:
                            size = new Double(laTag.getIntialWidth());
                            slp.addEast(pw, size);
                            break;

                        case WEST:
                            size = new Double(laTag.getIntialWidth());
                            slp.addWest(pw, size);
                            break;

                        case CENTER:
                            slp.add(pw);
                            centerAdded = true;
                        }

                        // if groupId set, store widget and parent splitlayoutpanel
                        if (panelData != null) {
                            panelData.addWidget(previewId, pw);
                            panelData.addSize(previewId, size);
                        }
                    }
                }
            }
        }

        // HtmlLoaderTag call the server, then display the result message as html
        List<HtmlLoaderTag> htmlLoaders = laTag.getHtmlLoaders();
        if (htmlLoaders != null) {
            for (HtmlLoaderTag htmlLoader : htmlLoaders) {
                HTML html = new HTML();
                LabelTag l = htmlLoader.getLabel();
                if (l != null) {
                    html.setHTML(l.getHtmlString());
                }
                doHtmlLoad(inputReq, htmlLoader, html);
                container.add(html);
            }
        }

        if (tp != null) {
            Widget w = null;
            String taTitle = laTag.getTitle();
            if (taTitle != null && taTitle.length() > 0) {
                w = createShadowTitlePanel(tp, taTitle, laTag.getHelpId(), doTag);
            } else {
                w = tp;
                if (!StringUtils.isEmpty(laTag.getHelpId())) {
                    tp.setHelpId(laTag.getHelpId());
                }
            }

            switch (dir) {
            case NORTH:
                slp.addNorth(w, laTag.getIntialHeight());
                break;

            case SOUTH:
                slp.addSouth(w, laTag.getIntialHeight());
                break;

            case EAST:
                slp.addEast(w, laTag.getIntialWidth());
                break;

            case WEST:
                slp.addWest(w, laTag.getIntialWidth());
                break;

            case CENTER:
                slp.add(w);
                centerAdded = true;
            }

            hub.bind(tp);

        } else if (container != null) {
            Widget w = null;
            String taTitle = laTag.getTitle();
            if (taTitle != null && taTitle.length() > 0) {
                w = createShadowTitlePanel(container, taTitle, laTag.getHelpId(), doTag);
            } else
                w = container;

            switch (dir) {
            case NORTH:
                slp.addNorth(w, laTag.getIntialHeight());
                break;

            case SOUTH:
                slp.addSouth(w, laTag.getIntialHeight());
                break;

            case EAST:
                slp.addEast(w, laTag.getIntialWidth());
                break;

            case WEST:
                slp.addWest(w, laTag.getIntialWidth());
                break;

            case CENTER:
                slp.add(w);
                centerAdded = true;
            }

        }
        // store panel data, if necessary
        if (panelData != null) {
            hData.addSplitLayoutPanelItem(groupId, panelData);
        }

    }

    return slp;
}

From source file:org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor.java

License:Open Source License

public ExportPlotSizeEditor(int initialWidth, int initialHeight, boolean keepRatio, Widget extraWidget,
        ExportPlotPreviewer previewer, final Observer observer) {
    // alias objects and resources
    previewer_ = previewer;//  w  w  w  .j a  v a 2  s .  co m
    observer_ = observer;
    ExportPlotResources resources = ExportPlotResources.INSTANCE;

    // main widget
    VerticalPanel verticalPanel = new VerticalPanel();

    // if we have an extra widget then enclose it within a horizontal
    // panel with it on the left and the options on the right
    HorizontalPanel topPanel = new HorizontalPanel();
    CellPanel optionsPanel = null;
    HorizontalPanel widthAndHeightPanel = null;
    if (extraWidget != null) {
        topPanel.setWidth("100%");

        topPanel.add(extraWidget);
        topPanel.setCellHorizontalAlignment(extraWidget, HasHorizontalAlignment.ALIGN_LEFT);

        optionsPanel = new VerticalPanel();
        optionsPanel.setStylePrimaryName(resources.styles().verticalSizeOptions());
        optionsPanel.setSpacing(0);
        topPanel.add(optionsPanel);
        topPanel.setCellHorizontalAlignment(optionsPanel, HasHorizontalAlignment.ALIGN_RIGHT);

        widthAndHeightPanel = new HorizontalPanel();
        widthAndHeightPanel.setStylePrimaryName(resources.styles().widthAndHeightEntry());
        configureHorizontalOptionsPanel(widthAndHeightPanel);
        optionsPanel.add(widthAndHeightPanel);
    } else {
        optionsPanel = topPanel;
        optionsPanel.setStylePrimaryName(resources.styles().horizontalSizeOptions());
        widthAndHeightPanel = topPanel;
        configureHorizontalOptionsPanel(topPanel);
    }

    // image width
    widthAndHeightPanel.add(createImageOptionLabel("Width:"));
    widthTextBox_ = createImageSizeTextBox();
    widthTextBox_.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            // screen out programmatic sets
            if (settingDimenensionInProgress_)
                return;

            // enforce min size
            int width = constrainWidth(getImageWidth());

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                double ratio = (double) lastHeight_ / (double) lastWidth_;
                int height = constrainHeight((int) (ratio * (double) width));
                setHeightTextBox(height);
            }

            // set width
            setWidthTextBox(width);
        }

    });
    widthAndHeightPanel.add(widthTextBox_);

    // image height
    widthAndHeightPanel.add(new HTML("&nbsp;&nbsp;"));
    widthAndHeightPanel.add(createImageOptionLabel("Height:"));
    heightTextBox_ = createImageSizeTextBox();
    heightTextBox_.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            // screen out programmatic sets
            if (settingDimenensionInProgress_)
                return;

            // enforce min size
            int height = constrainHeight(getImageHeight());

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                double ratio = (double) lastWidth_ / (double) lastHeight_;
                int width = constrainWidth((int) (ratio * (double) height));
                setWidthTextBox(width);
            }

            // always set height
            setHeightTextBox(height);
        }

    });
    widthAndHeightPanel.add(heightTextBox_);

    // add width and height panel to options panel container if necessary
    if (widthAndHeightPanel != optionsPanel)
        optionsPanel.add(widthAndHeightPanel);

    // lock ratio check box
    keepRatioCheckBox_ = new CheckBox();
    keepRatioCheckBox_.setStylePrimaryName(resources.styles().maintainAspectRatioCheckBox());
    keepRatioCheckBox_.setValue(keepRatio);
    keepRatioCheckBox_.setText("Maintain aspect ratio");
    optionsPanel.add(keepRatioCheckBox_);

    // image and sizer in layout panel (create now so we can call
    // setSize in update button click handler)
    previewPanel_ = new LayoutPanel();

    // update button
    ThemedButton updateButton = new ThemedButton("Update Preview", new ClickHandler() {
        public void onClick(ClickEvent event) {
            updatePreview();
        }
    });
    updateButton.setStylePrimaryName(resources.styles().updateImageSizeButton());
    optionsPanel.add(updateButton);

    // add top panel
    verticalPanel.add(topPanel);

    // previewer
    Widget previewWidget = previewer_.getWidget();

    // Stops mouse events from being routed to the iframe, which would
    // interfere with resizing
    final GlassPanel glassPanel = new GlassPanel(previewWidget);
    glassPanel.getChildContainerElement().getStyle().setOverflow(Overflow.VISIBLE);
    glassPanel.setSize("100%", "100%");

    previewPanel_.add(glassPanel);
    previewPanel_.setWidgetLeftRight(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX);
    previewPanel_.setWidgetTopBottom(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX);
    previewPanel_.getWidgetContainerElement(glassPanel).getStyle().setOverflow(Overflow.VISIBLE);

    // resize gripper
    gripper_ = new ResizeGripper(new ResizeGripper.Observer() {
        @Override
        public void onResizingStarted() {
            int startWidth = getImageWidth();
            int startHeight = getImageHeight();

            widthAspectRatio_ = (double) startWidth / (double) startHeight;
            heightAspectRatio_ = (double) startHeight / (double) startWidth;

            glassPanel.setGlass(true);
        }

        @Override
        public void onResizing(int xDelta, int yDelta) {
            // get start width and height
            int startWidth = getImageWidth();
            int startHeight = getImageHeight();

            // calculate new height and width 
            int newWidth = constrainWidth(startWidth + xDelta);
            int newHeight = constrainHeight(startHeight + yDelta);

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                if (Math.abs(xDelta) > Math.abs(yDelta))
                    newHeight = (int) (heightAspectRatio_ * (double) newWidth);
                else
                    newWidth = (int) (widthAspectRatio_ * (double) newHeight);
            }

            // set text boxes
            setWidthTextBox(newWidth);
            setHeightTextBox(newHeight);

            // set image preview size
            setPreviewPanelSize(newWidth, newHeight);
        }

        @Override
        public void onResizingCompleted() {
            glassPanel.setGlass(false);
            previewer_.updatePreview(getImageWidth(), getImageHeight());
            observer.onResized(true);
        }

        private double widthAspectRatio_ = 1.0;
        private double heightAspectRatio_ = 1.0;
    });

    // layout gripper
    previewPanel_.add(gripper_);
    previewPanel_.setWidgetRightWidth(gripper_, 0, Unit.PX, gripper_.getImageWidth(), Unit.PX);
    previewPanel_.setWidgetBottomHeight(gripper_, 0, Unit.PX, gripper_.getImageHeight(), Unit.PX);

    // constrain dimensions
    initialWidth = constrainWidth(initialWidth);
    initialHeight = constrainHeight(initialHeight);

    // initialie text boxes
    setWidthTextBox(initialWidth);
    setHeightTextBox(initialHeight);

    // initialize preview
    setPreviewPanelSize(initialWidth, initialHeight);

    verticalPanel.add(previewPanel_);

    // set initial focus widget
    if (extraWidget == null)
        initialFocusWidget_ = widthTextBox_;
    else
        initialFocusWidget_ = null;

    initWidget(verticalPanel);

}

From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.ExportPlotSizeEditor.java

License:Open Source License

public ExportPlotSizeEditor(int initialWidth, int initialHeight, boolean keepRatio, Widget extraWidget,
        PlotsServerOperations server, final Observer observer) {
    // alias objects and resources
    server_ = server;/*from   ww w. j  a  v a 2 s. c  om*/
    ExportPlotResources resources = ExportPlotResources.INSTANCE;

    // main widget
    VerticalPanel verticalPanel = new VerticalPanel();

    // if we have an extra widget then enclose it within a horizontal
    // panel with it on the left and the options on the right
    HorizontalPanel topPanel = new HorizontalPanel();
    CellPanel optionsPanel = null;
    HorizontalPanel widthAndHeightPanel = null;
    if (extraWidget != null) {
        topPanel.setWidth("100%");

        topPanel.add(extraWidget);
        topPanel.setCellHorizontalAlignment(extraWidget, HasHorizontalAlignment.ALIGN_LEFT);

        optionsPanel = new VerticalPanel();
        optionsPanel.setStylePrimaryName(resources.styles().verticalSizeOptions());
        optionsPanel.setSpacing(0);
        topPanel.add(optionsPanel);
        topPanel.setCellHorizontalAlignment(optionsPanel, HasHorizontalAlignment.ALIGN_RIGHT);

        widthAndHeightPanel = new HorizontalPanel();
        widthAndHeightPanel.setStylePrimaryName(resources.styles().widthAndHeightEntry());
        configureHorizontalOptionsPanel(widthAndHeightPanel);
        optionsPanel.add(widthAndHeightPanel);
    } else {
        optionsPanel = topPanel;
        optionsPanel.setStylePrimaryName(resources.styles().horizontalSizeOptions());
        widthAndHeightPanel = topPanel;
        configureHorizontalOptionsPanel(topPanel);
    }

    // image width
    widthAndHeightPanel.add(createImageOptionLabel("Width:"));
    widthTextBox_ = createImageSizeTextBox();
    widthTextBox_.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            // screen out programmatic sets
            if (settingDimenensionInProgress_)
                return;

            // enforce min size
            int width = constrainWidth(getImageWidth());

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                double ratio = (double) lastHeight_ / (double) lastWidth_;
                int height = constrainHeight((int) (ratio * (double) width));
                setHeightTextBox(height);
            }

            // set width
            setWidthTextBox(width);
        }

    });
    widthAndHeightPanel.add(widthTextBox_);

    // image height
    widthAndHeightPanel.add(new HTML("&nbsp;&nbsp;"));
    widthAndHeightPanel.add(createImageOptionLabel("Height:"));
    heightTextBox_ = createImageSizeTextBox();
    heightTextBox_.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            // screen out programmatic sets
            if (settingDimenensionInProgress_)
                return;

            // enforce min size
            int height = constrainHeight(getImageHeight());

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                double ratio = (double) lastWidth_ / (double) lastHeight_;
                int width = constrainWidth((int) (ratio * (double) height));
                setWidthTextBox(width);
            }

            // always set height
            setHeightTextBox(height);
        }

    });
    widthAndHeightPanel.add(heightTextBox_);

    // add width and height panel to options panel container if necessary
    if (widthAndHeightPanel != optionsPanel)
        optionsPanel.add(widthAndHeightPanel);

    // lock ratio check box
    keepRatioCheckBox_ = new CheckBox();
    keepRatioCheckBox_.setStylePrimaryName(resources.styles().maintainAspectRatioCheckBox());
    keepRatioCheckBox_.setValue(keepRatio);
    keepRatioCheckBox_.setText("Maintain aspect ratio");
    optionsPanel.add(keepRatioCheckBox_);

    // image and sizer in layout panel (create now so we can call
    // setSize in update button click handler)
    previewPanel_ = new LayoutPanel();

    // update button
    ThemedButton updateButton = new ThemedButton("Update Preview", new ClickHandler() {
        public void onClick(ClickEvent event) {
            setPreviewPanelSize(getImageWidth(), getImageHeight());

            updateImage();

            observer.onPlotResized(false);
        }
    });
    updateButton.setStylePrimaryName(resources.styles().updateImageSizeButton());
    optionsPanel.add(updateButton);

    // add top panel
    verticalPanel.add(topPanel);

    // image frame
    imageFrame_ = new ImageFrame();
    imageFrame_.setUrl("about:blank");
    imageFrame_.setSize("100%", "100%");
    imageFrame_.setMarginHeight(0);
    imageFrame_.setMarginWidth(0);
    imageFrame_.setStylePrimaryName(resources.styles().imagePreview());

    // Stops mouse events from being routed to the iframe, which would
    // interfere with resizing
    final GlassPanel glassPanel = new GlassPanel(imageFrame_);
    glassPanel.getChildContainerElement().getStyle().setOverflow(Overflow.VISIBLE);
    glassPanel.setSize("100%", "100%");

    previewPanel_.add(glassPanel);
    previewPanel_.setWidgetLeftRight(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX);
    previewPanel_.setWidgetTopBottom(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX);
    previewPanel_.getWidgetContainerElement(glassPanel).getStyle().setOverflow(Overflow.VISIBLE);

    // resize gripper
    ResizeGripper gripper = new ResizeGripper(new ResizeGripper.Observer() {
        @Override
        public void onResizingStarted() {
            int startWidth = getImageWidth();
            int startHeight = getImageHeight();

            widthAspectRatio_ = (double) startWidth / (double) startHeight;
            heightAspectRatio_ = (double) startHeight / (double) startWidth;

            glassPanel.setGlass(true);
        }

        @Override
        public void onResizing(int xDelta, int yDelta) {
            // get start width and height
            int startWidth = getImageWidth();
            int startHeight = getImageHeight();

            // calculate new height and width 
            int newWidth = constrainWidth(startWidth + xDelta);
            int newHeight = constrainHeight(startHeight + yDelta);

            // preserve aspect ratio if requested
            if (getKeepRatio()) {
                if (Math.abs(xDelta) > Math.abs(yDelta))
                    newHeight = (int) (heightAspectRatio_ * (double) newWidth);
                else
                    newWidth = (int) (widthAspectRatio_ * (double) newHeight);
            }

            // set text boxes
            setWidthTextBox(newWidth);
            setHeightTextBox(newHeight);

            // set image preview size
            setPreviewPanelSize(newWidth, newHeight);
        }

        @Override
        public void onResizingCompleted() {
            glassPanel.setGlass(false);
            updateImage();
            observer.onPlotResized(true);
        }

        private double widthAspectRatio_ = 1.0;
        private double heightAspectRatio_ = 1.0;
    });

    // layout gripper
    previewPanel_.add(gripper);
    previewPanel_.setWidgetRightWidth(gripper, 0, Unit.PX, gripper.getImageWidth(), Unit.PX);
    previewPanel_.setWidgetBottomHeight(gripper, 0, Unit.PX, gripper.getImageHeight(), Unit.PX);

    // constrain dimensions
    initialWidth = constrainWidth(initialWidth);
    initialHeight = constrainHeight(initialHeight);

    // initialie text boxes
    setWidthTextBox(initialWidth);
    setHeightTextBox(initialHeight);

    // initialize preview
    setPreviewPanelSize(initialWidth, initialHeight);

    verticalPanel.add(previewPanel_);

    // set initial focus widget
    if (extraWidget == null)
        initialFocusWidget_ = widthTextBox_;
    else
        initialFocusWidget_ = null;

    initWidget(verticalPanel);

}