Example usage for com.vaadin.client ComputedStyle ComputedStyle

List of usage examples for com.vaadin.client ComputedStyle ComputedStyle

Introduction

In this page you can find the example usage for com.vaadin.client ComputedStyle ComputedStyle.

Prototype

public ComputedStyle(Element elem) 

Source Link

Document

Gets this element's computed style object which can be used to gather information about the current state of the rendered node.

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.groupbox.CubaGroupBoxConnector.java

License:Apache License

protected void layoutGroupBox() {
    CubaGroupBoxWidget panel = getWidget();
    LayoutManager layoutManager = getLayoutManager();

    if (isBordersVisible()) {
        int captionWidth = layoutManager.getOuterWidth(panel.captionNode);
        int captionStartWidth = layoutManager.getInnerWidth(panel.captionStartDeco);
        int totalMargin = captionWidth + captionStartWidth;

        panel.captionNode.getStyle().setWidth(captionWidth, Unit.PX);
        panel.captionWrap.getStyle().setPaddingLeft(totalMargin, Unit.PX);
        panel.captionStartDeco.getStyle().setMarginLeft(0 - totalMargin, Unit.PX);
    }//  w  ww.jav  a 2  s  .  c  o m

    Profiler.enter("CubaGroupBoxConnector.layout getHeights");
    // Haulmont API get max height of caption components
    int top = layoutManager.getOuterHeight(panel.captionNode);
    top = Math.max(layoutManager.getOuterHeight(panel.captionStartDeco), top);
    top = Math.max(layoutManager.getOuterHeight(panel.captionEndDeco), top);

    int bottom = layoutManager.getInnerHeight(panel.bottomDecoration);
    Profiler.leave("PanelConnector.layout getHeights");

    Style style = panel.getElement().getStyle();
    int paddingTop = 0;
    int paddingBottom = 0;
    if (panel.hasAnyOuterMargin()) {
        Profiler.enter("PanelConnector.layout get values from styles");
        // Clear previously set values

        style.clearPaddingTop();
        style.clearPaddingBottom();
        // Calculate padding from styles
        ComputedStyle computedStyle = new ComputedStyle(panel.getElement());
        paddingTop = computedStyle.getIntProperty("padding-top");
        paddingBottom = computedStyle.getIntProperty("padding-bottom");
        Profiler.leave("PanelConnector.layout get values from styles");
    }

    Profiler.enter("PanelConnector.layout modify style");
    panel.captionWrap.getStyle().setMarginTop(-top, Style.Unit.PX);
    panel.bottomDecoration.getStyle().setMarginBottom(-bottom, Style.Unit.PX);
    style.setPaddingTop(top + paddingTop, Style.Unit.PX);
    style.setPaddingBottom(bottom + paddingBottom, Style.Unit.PX);
    Profiler.leave("PanelConnector.layout modify style");

    // Update scroll positions
    Profiler.enter("PanelConnector.layout update scroll positions");
    panel.contentNode.setScrollTop(panel.scrollTop);
    panel.contentNode.setScrollLeft(panel.scrollLeft);
    Profiler.leave("PanelConnector.layout update scroll positions");

    // Read actual value back to ensure update logic is correct
    Profiler.enter("PanelConnector.layout read scroll positions");
    panel.scrollTop = panel.contentNode.getScrollTop();
    panel.scrollLeft = panel.contentNode.getScrollLeft();
    Profiler.leave("PanelConnector.layout read scroll positions");
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadProgressWindow.java

License:Apache License

protected void constructDOM() {
    setStyleName(CLASSNAME);//  w w  w .java2 s.co m

    topTabStop = DOM.createDiv();
    topTabStop.setTabIndex(0);

    header = DOM.createDiv();
    header.setClassName(CLASSNAME + "-outerheader");

    headerText = DOM.createDiv();
    headerText.setClassName(CLASSNAME + "-header");

    contents = DOM.createDiv();
    contents.setClassName(CLASSNAME + "-contents");

    footer = DOM.createDiv();
    footer.setClassName(CLASSNAME + "-footer");

    resizeBox = DOM.createDiv();
    resizeBox.setClassName(CLASSNAME + "-resizebox");

    closeBox = DOM.createDiv();
    closeBox.setClassName(CLASSNAME + "-closebox");
    closeBox.setTabIndex(0);

    DOM.appendChild(footer, resizeBox);

    bottomTabStop = DOM.createDiv();
    bottomTabStop.setTabIndex(0);

    wrapper = DOM.createDiv();
    wrapper.setClassName(CLASSNAME + "-wrap");

    DOM.appendChild(wrapper, topTabStop);
    DOM.appendChild(wrapper, header);
    DOM.appendChild(header, closeBox);
    DOM.appendChild(header, headerText);
    DOM.appendChild(wrapper, contents);
    DOM.appendChild(wrapper, footer);
    DOM.appendChild(wrapper, bottomTabStop);
    DOM.appendChild(super.getContainerElement(), wrapper);

    sinkEvents(Event.ONDBLCLICK | Event.MOUSEEVENTS | Event.TOUCHEVENTS | Event.ONCLICK | Event.ONLOSECAPTURE);

    currentFileLabel = new VLabel();
    currentFileLabel.addStyleName("upload-file-label");
    currentFileLabel.setWidth("100%");

    progressBar = new VProgressBar();
    progressBar.addStyleName("upload-progressbar");
    progressBar.setIndeterminate(false);
    progressBar.setState(0);
    progressBar.setWidth("100%");

    cancelButton = new VButton();
    cancelButton.addStyleName("upload-cancel-button");
    cancelButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            closeWindow();
        }
    });

    contentPanel = new SimpleFocusablePanel();
    contentPanel.setStyleName("content-pane");
    contentPanel.addKeyDownHandler(this);
    contentPanel.addKeyUpHandler(this);

    setWidget(contentPanel);

    final FlowPanel verticalPanel = new FlowPanel();
    verticalPanel.setStyleName("vertical-panel");
    verticalPanel.addStyleName("v-widget");
    verticalPanel.addStyleName("v-has-width");
    verticalPanel.addStyleName("v-has-height");

    verticalPanel.add(currentFileLabel);
    verticalPanel.add(progressBar);
    verticalPanel.add(cancelButton);

    contentPanel.setWidget(verticalPanel);

    // do some calculations for window layout
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {
            Style contentStyle = contents.getStyle();

            ComputedStyle headerCs = new ComputedStyle(header);
            String headerHeight = headerCs.getProperty("height");
            contentStyle.setProperty("paddingTop", headerHeight);
            contentStyle.setProperty("marginTop", "-" + headerHeight);

            ComputedStyle footerCs = new ComputedStyle(footer);
            String footerHeight = footerCs.getProperty("height");
            contentStyle.setProperty("paddingBottom", footerHeight);
            contentStyle.setProperty("marginBottom", "-" + footerHeight);
        }
    });

    // Make the closebox accessible for assistive devices
    Roles.getButtonRole().set(closeBox);
    Roles.getButtonRole().setAriaLabelProperty(closeBox, "close button");

    // Provide the title to assistive devices
    AriaHelper.ensureHasId(headerText);
    Roles.getDialogRole().setAriaLabelledbyProperty(getElement(), Id.of(headerText));

    // Handlers to Prevent tab to leave the window
    // and backspace to cause browser navigation
    topEventBlocker = new Event.NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == topTabStop
                    && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && nativeEvent.getShiftKey()) {
                nativeEvent.preventDefault();
            }
            if (nativeEvent.getEventTarget().cast() == topTabStop
                    && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                nativeEvent.preventDefault();
            }
        }
    };

    bottomEventBlocker = new Event.NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            if (nativeEvent.getEventTarget().cast() == bottomTabStop
                    && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && !nativeEvent.getShiftKey()) {
                nativeEvent.preventDefault();
            }
            if (nativeEvent.getEventTarget().cast() == bottomTabStop
                    && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                nativeEvent.preventDefault();
            }
        }
    };
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.resizabletextarea.CubaResizableTextAreaWrapperWidget.java

License:Apache License

protected void captureEvents(Event event) {
    event.preventDefault();//w  ww.  j a  va 2  s.com
    if (isEnabled() && event.getButton() == Event.BUTTON_LEFT) {
        if (!dragDrop) {
            dragDrop = true;
            DOM.setCapture(resizeElement);

            ComputedStyle cs = new ComputedStyle(getElement());
            setWidth(cs.getProperty("width"));
            setHeight(cs.getProperty("height"));

            getTextArea().getStyle().setProperty("width", "100%");
            getTextArea().getStyle().setProperty("height", "100%");
        }
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.resizabletextarea.CubaResizableTextAreaWrapperWidget.java

License:Apache License

protected void releaseCapture(Event event) {
    if (event.getButton() == Event.BUTTON_LEFT && dragDrop) {
        dragDrop = false;/* w  w  w.  j a  v  a2 s.c  o  m*/
        DOM.releaseCapture(resizeElement);

        if (resizeHandler != null) {
            ComputedStyle cs = new ComputedStyle(getElement());
            resizeHandler.sizeChanged(cs.getProperty("width"), cs.getProperty("height"));
            resizeHandler.textChanged(getText());
        }
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.resizabletextarea.CubaResizableTextAreaWrapperWidget.java

License:Apache License

protected void handleResize(Event event) {
    //calculate and set the new size
    if (dragDrop) {
        int mouseX = event.getClientX();
        int mouseY = event.getClientY();
        int absoluteLeft = getAbsoluteLeft();
        int absoluteTop = getAbsoluteTop();

        ComputedStyle cs = new ComputedStyle(getElement().getFirstChildElement());

        //do not allow mirror-functionality
        if (mouseY > absoluteTop + cs.getDoubleProperty("min-height")
                && mouseX > absoluteLeft + MINIMAL_WIDTH) {
            int width = mouseX - absoluteLeft + 2;
            int height = mouseY - absoluteTop + 2;

            switch (resizableDirection) {
            case BOTH:
                setHeight(height + "px");
                setWidth(width + "px");
                break;
            case VERTICAL:
                setHeight(height + "px");
                break;
            case HORIZONTAL:
                setWidth(width + "px");
                break;
            }/*from   w  ww  .  ja v a  2 s. com*/

            if (resizeHandler != null) {
                resizeHandler.handleResize();
            }
        }
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.suggestionfield.CubaSuggestionFieldWidget.java

License:Apache License

protected static double getMarginBorderPaddingWidth(Element element) {
    final ComputedStyle s = new ComputedStyle(element);
    return s.getMarginWidth() + s.getBorderWidth() + s.getPaddingWidth();
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.tableshared.TableWidgetDelegate.java

License:Apache License

public void showSortMenu(final Element target, final String columnId) {
    final VOverlay sortDirectionPopup = GWT.create(VOverlay.class);
    sortDirectionPopup.setOwner(tableWidget.getOwner());

    FlowPanel sortDirectionMenu = new FlowPanel();
    Label sortByDescendingButton = new Label(tableWidget.getSortDescendingLabel());
    Label sortByAscendingButton = new Label(tableWidget.getSortAscendingLabel());
    Label sortClearSortButton = new Label(tableWidget.getSortResetLabel());

    sortByDescendingButton.addStyleName(TABLE_SORT_CONTEXTMENU_ITEM);
    sortByAscendingButton.addStyleName(TABLE_SORT_CONTEXTMENU_ITEM);
    sortClearSortButton.addStyleName(TABLE_SORT_CONTEXTMENU_ITEM);

    sortDirectionMenu.add(sortByAscendingButton);
    sortDirectionMenu.add(sortByDescendingButton);
    sortDirectionMenu.add(sortClearSortButton);

    sortByDescendingButton.addClickHandler(event -> {
        updateVariable("sortcolumn", columnId, false);
        updateVariable("sortascending", false, false);

        tableWidget.getRowRequestHandler().deferRowFetch(); // some validation +
        // defer 250ms
        tableWidget.getRowRequestHandler().cancel(); // instead of waiting
        tableWidget.getRowRequestHandler().run(); // run immediately
        sortDirectionPopup.hide();/*from   w  w  w . j  ava  2 s  .  c  o  m*/
    });

    sortByAscendingButton.addClickHandler(event -> {
        updateVariable("sortcolumn", columnId, false);
        updateVariable("sortascending", true, false);

        tableWidget.getRowRequestHandler().deferRowFetch(); // some validation +
        // defer 250ms
        tableWidget.getRowRequestHandler().cancel(); // instead of waiting
        tableWidget.getRowRequestHandler().run(); // run immediately
        sortDirectionPopup.hide();
    });

    sortClearSortButton.addClickHandler(event -> {
        updateVariable("resetsortorder", columnId, true);
        sortDirectionPopup.hide();
    });

    sortDirectionMenu.addStyleName("c-table-contextmenu");
    sortDirectionPopup.setWidget(sortDirectionMenu);

    sortDirectionPopup.setAutoHideEnabled(true);
    ComputedStyle sortIndicatorStyle = new ComputedStyle(target);

    Tools.showPopup(sortDirectionPopup, target.getAbsoluteLeft(),
            target.getAbsoluteTop() + ((int) sortIndicatorStyle.getHeight()));
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.tablesort.TableCustomSortDelegate.java

License:Apache License

public void showSortMenu(final Element sortIndicator, final String columnId) {
    final VOverlay sortDirectionPopup = new VOverlay();
    sortDirectionPopup.setOwner(tableWidget.getOwner());

    FlowPanel sortDirectionMenu = new FlowPanel();
    Label sortByDescendingButton = new Label(tableWidget.getSortDescendingLabel());
    Label sortByAscendingButton = new Label(tableWidget.getSortAscendingLabel());
    Label sortClearSortButton = new Label(tableWidget.getSortResetLabel());

    sortByDescendingButton.addStyleName("cuba-table-contextmenu-item");
    sortByAscendingButton.addStyleName("cuba-table-contextmenu-item");
    sortClearSortButton.addStyleName("cuba-table-contextmenu-item");

    sortDirectionMenu.add(sortByAscendingButton);
    sortDirectionMenu.add(sortByDescendingButton);
    sortDirectionMenu.add(sortClearSortButton);

    sortByDescendingButton.addClickHandler(new ClickHandler() {
        @Override//from   w  w w.  ja va  2  s  . c  om
        public void onClick(ClickEvent event) {
            tableWidget.getClient().updateVariable(tableWidget.getPaintableId(), "sortcolumn", columnId, false);
            tableWidget.getClient().updateVariable(tableWidget.getPaintableId(), "sortascending", false, false);

            tableWidget.getRowRequestHandler().deferRowFetch(); // some validation +
            // defer 250ms
            tableWidget.getRowRequestHandler().cancel(); // instead of waiting
            tableWidget.getRowRequestHandler().run(); // run immediately
            sortDirectionPopup.hide();
        }
    });

    sortByAscendingButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            tableWidget.getClient().updateVariable(tableWidget.getPaintableId(), "sortcolumn", columnId, false);
            tableWidget.getClient().updateVariable(tableWidget.getPaintableId(), "sortascending", true, false);

            tableWidget.getRowRequestHandler().deferRowFetch(); // some validation +
            // defer 250ms
            tableWidget.getRowRequestHandler().cancel(); // instead of waiting
            tableWidget.getRowRequestHandler().run(); // run immediately
            sortDirectionPopup.hide();
        }
    });

    sortClearSortButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            tableWidget.getClient().updateVariable(tableWidget.getPaintableId(), "resetsortorder", columnId,
                    true);
            sortIndicator.addClassName("cuba-sort-indicator-visible");
            sortDirectionPopup.hide();
        }
    });

    sortDirectionMenu.addStyleName("cuba-table-contextmenu");
    sortDirectionPopup.setWidget(sortDirectionMenu);

    sortDirectionPopup.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            sortIndicator.removeClassName("cuba-sort-indicator-visible");
        }
    });

    sortDirectionPopup.setAutoHideEnabled(true);
    ComputedStyle sortIndicatorStyle = new ComputedStyle(sortIndicator);
    Tools.showPopup(sortDirectionPopup, sortIndicator.getAbsoluteLeft(),
            sortIndicator.getAbsoluteTop() + ((int) sortIndicatorStyle.getHeight()));
    sortIndicator.addClassName("cuba-sort-indicator-visible");
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetWidget.java

License:Apache License

@Override
public void updateContentNodeHeight() {
    if (!isDynamicHeight()) {
        ComputedStyle fullHeight = new ComputedStyle(getElement());
        double contentHeight = fullHeight.getHeight();

        ComputedStyle tabsCs = new ComputedStyle(tabs);
        contentHeight -= tabsCs.getHeight();

        contentHeight -= deco.getOffsetHeight();

        ComputedStyle cs = new ComputedStyle(contentNode);
        contentHeight -= cs.getPaddingHeight();
        contentHeight -= cs.getBorderHeight();

        if (contentHeight < 0) {
            contentHeight = 0;//from  w ww  .ja  v a  2s .co  m
        }

        // Set proper values for content element
        double ceilHeight = Math.ceil(contentHeight);

        contentNode.getStyle().setHeight(ceilHeight, Style.Unit.PX);
    } else {
        contentNode.getStyle().clearHeight();
    }
}

From source file:com.haulmont.cuba.web.widgets.client.addons.aceeditor.AceEditorConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);

    setTextChangeEventMode(getState().changeMode);
    setTextChangeTimeout(getState().changeTimeout);

    ClientSideDocDiff.dmp.setDiff_EditCost(getState().diff_editCost);

    // TODO: are these needed?
    //      widget.setHideErrors(getState().hideErrors);
    //      widget.setRequired(getState().required);
    //      widget.setModified(getState().modified);

    boolean firstTime = !getWidget().isInitialized();
    if (firstTime) {
        // To make sure Ace config is applied before the editor is created,
        // we delay the initialization till then first call to onStateChanged,
        // not initializing in createWidget() right away.
        applyConfig(getState().config);/*w w w .  ja  v a 2 s . c  om*/
        getWidget().initialize();
    }

    getWidget().setMode(getState().mode);
    getWidget().setTheme(getState().theme);
    listenToSelectionChanges = getState().listenToSelectionChanges;
    listenToFocusChanges = getState().listenToFocusChanges;
    getWidget().setUseWorker(getState().useWorker);
    getWidget().setWordwrap(getState().wordwrap);

    getWidget().setShowGutter(getState().showGutter);
    getWidget().setShowPrintMargin(getState().showPrintMargin);
    getWidget().setHighlightActiveLineEnabled(getState().highlightActiveLine);

    getWidget().setEnabled(getState().enabled);
    //        getWidget().setPropertyReadOnly(getState().propertyReadOnly);
    getWidget().setTabIndex(getState().tabIndex);
    getWidget().setReadOnly(getState().readOnly);

    if (stateChangeEvent.hasPropertyChanged("fontSize")) {
        String fontSize = getState().fontSize;

        if ("auto".equals(fontSize)) {
            // detect font size from CSS
            Element fontSizeMeasureElement = Document.get().createDivElement();
            fontSizeMeasureElement.setClassName("ace_editor");
            fontSizeMeasureElement.getStyle().setPosition(Style.Position.FIXED);
            fontSizeMeasureElement.getStyle().setVisibility(Style.Visibility.HIDDEN);
            getWidget().getElement().appendChild(fontSizeMeasureElement);

            ComputedStyle cs = new ComputedStyle(fontSizeMeasureElement);
            fontSize = cs.getProperty("fontSize");

            getWidget().getElement().removeChild(fontSizeMeasureElement);
        }

        getWidget().setFontSize(fontSize);
    }

    getWidget().setHighlightSelectedWord(getState().highlightSelectedWord);
    getWidget().setShowInvisibles(getState().showInvisibles);
    getWidget().setDisplayIndentGuides(getState().displayIndentGuides);

    getWidget().setUseSoftTabs(getState().softTabs);
    getWidget().setTabSize(getState().tabSize);

    // TODO: How should we deal with immediateness. Since there's already textChangeEventMode...
    //immediate = getState().immediate;

    if (firstTime) {
        shadow = AceDoc.fromTransport(getState().initialValue);
        getWidget().setDoc(shadow);
    }

    if (getState().selection != null) {
        AceRange sel = AceRange.fromTransport(getState().selection);
        if (firstTime) {
            getWidget().setSelection(sel);
        } else {
            selectionAfterApplyingDiff = sel;
        }
    }

    if (getState().scrollToRow != -1) {
        if (firstTime) {
            getWidget().scrollToRow(getState().scrollToRow);
        } else {
            scrollToRowAfterApplyingDiff = getState().scrollToRow;
        }
    }
}