Example usage for com.google.gwt.dom.client Style setProperty

List of usage examples for com.google.gwt.dom.client Style setProperty

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Style setProperty.

Prototype

public void setProperty(String name, String value) 

Source Link

Usage

From source file:org.opencms.ade.containerpage.client.ui.CmsContainerPageElement.java

License:Open Source License

/**
 * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getDragHelper(org.opencms.gwt.client.dnd.I_CmsDropTarget)
 *//*from   w  w  w.j av  a2  s  . co  m*/
public Element getDragHelper(I_CmsDropTarget target) {

    Element helper = CmsDomUtil.clone(getElement());
    target.getElement().appendChild(helper);
    // preparing helper styles
    String width = CmsDomUtil.getCurrentStyle(helper, CmsDomUtil.Style.width);
    Style style = helper.getStyle();
    style.setPosition(Position.ABSOLUTE);
    style.setMargin(0, Unit.PX);
    style.setProperty(CmsDomUtil.Style.width.name(), width);
    style.setZIndex(I_CmsLayoutBundle.INSTANCE.constants().css().zIndexDND());
    helper.addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragging());
    helper.addClassName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().shadow());
    if (!CmsDomUtil.hasBackground(helper)) {
        helper.addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragElementBackground());
    }

    if (!CmsDomUtil.hasBorder(helper)) {
        helper.addClassName(I_CmsLayoutBundle.INSTANCE.dragdropCss().dragElementBorder());
    }
    return helper;
}

From source file:org.opencms.gwt.client.seo.CmsSeoOptionsDialog.java

License:Open Source License

/**
 * Creates a new dialog instance.<p>
 *
 * @param structureId the structure id of the resource whose aliases are being edited
 * @param infoBean a bean containing the information to display in the resource info box
 * @param aliases the existing aliases of the resource
 * @param propertyConfig the property configuration
 * @param propertyEditorHandler the property editor handler
 *///from w  ww  .ja va  2  s . c om
public CmsSeoOptionsDialog(CmsUUID structureId, CmsListInfoBean infoBean, List<CmsAliasBean> aliases,
        Map<String, CmsXmlContentProperty> propertyConfig, I_CmsPropertyEditorHandler propertyEditorHandler) {

    super(aliasMessages.seoOptions());
    setGlassEnabled(true);
    setAutoHideEnabled(false);
    setModal(true);

    //-----------------------INFO BOX -------------------------------------------

    CmsListItemWidget liWidget = new CmsListItemWidget(infoBean);
    liWidget.setStateIcon(StateIcon.standard);
    m_panel.add(liWidget);

    //------------------------ PROPERTIES ------------------------------------------
    LinkedHashMap<String, CmsXmlContentProperty> props = new LinkedHashMap<String, CmsXmlContentProperty>();
    for (String seoProperty : seoProperties) {
        if (propertyConfig.containsKey(seoProperty)) {
            props.put(seoProperty, propertyConfig.get(seoProperty));
        }
    }
    m_propertyEditor = new CmsSimplePropertyEditor(props, propertyEditorHandler);
    m_propertyEditor.getForm().setFormHandler(this);
    m_formSubmitHandler = new CmsPropertySubmitHandler(propertyEditorHandler);
    m_structureId = structureId;
    m_propertyFieldset.getElement().getStyle().setMarginTop(10, Unit.PX);
    m_propertyFieldset.getContentPanel().getElement().getStyle().setOverflow(Overflow.VISIBLE);
    m_propertyFieldset.setLegend(
            org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_PROPERTIES_0));
    m_propertyEditor.initializeWidgets(this);
    m_panel.add(m_propertyFieldset);

    //------------------------ ALIASES ------------------------------------------

    CmsFieldSet aliasFieldset = new CmsFieldSet();
    aliasFieldset.setLegend(aliasMessages.aliases());
    m_aliasList = new CmsAliasList(structureId, aliases);
    aliasFieldset.getElement().getStyle().setMarginTop(10, Unit.PX);
    CmsScrollPanel scrollPanel = GWT.create(CmsScrollPanel.class);
    scrollPanel.setWidget(m_aliasList);
    aliasFieldset.addContent(scrollPanel);
    m_panel.add(scrollPanel);
    Style style = scrollPanel.getElement().getStyle();
    style.setProperty("minHeight", "300px"); //$NON-NLS-1$ //$NON-NLS-2$
    style.setProperty("maxHeight", "450px"); //$NON-NLS-1$ //$NON-NLS-2$
    style.setOverflowY(Overflow.AUTO);

    setMainContent(m_panel);
    addButton(createCancelButton());
    addButton(saveButton());

}

From source file:org.opencms.gwt.client.util.CmsTextMetrics.java

License:Open Source License

/**
 * Binds this text metrics instance to an element from which to copy existing
 * CSS styles that can affect the size of the rendered text.<p>
 * /*from  w  w  w .  j  a  v  a  2  s .  co m*/
 * @param element the element
 * @param attributes the attributes to bind
 */
protected void bind(Element element, CmsDomUtil.Style... attributes) {

    if (m_elem == null) {
        // create playground
        m_elem = DOM.createDiv();
        Style style = m_elem.getStyle();
        style.setVisibility(Style.Visibility.HIDDEN);
        style.setPosition(Style.Position.ABSOLUTE);
        style.setLeft(-5000, Style.Unit.PX);
        style.setTop(-5000, Style.Unit.PX);
    }
    // copy all relevant CSS properties
    Style style = m_elem.getStyle();
    for (CmsDomUtil.Style attr : attributes) {
        String attrName = attr.toString();
        style.setProperty(attrName, CmsDomUtil.getCurrentStyle(element, attr));
    }
    // append playground
    RootPanel.getBodyElement().appendChild(m_elem);
}

From source file:org.opencms.ui.client.CmsBreadCrumbConnector.java

License:Open Source License

/**
 * Updates the entry max-width according to the available space.<p>
 *///from  ww  w.  ja va  2 s  .  com
void updateMaxWidth() {

    Element base = getWidget().getElement();
    int availableWidth = base.getOffsetWidth();
    int requiredWidth = 0;
    NodeList<Element> children = CmsDomUtil.querySelectorAll("div > a, div > span", base);
    for (int i = 0; i < children.getLength(); i++) {
        Element child = children.getItem(i);
        Style style = child.getFirstChildElement().getStyle();
        style.setProperty("maxWidth", "none");
        requiredWidth += child.getOffsetWidth();
        style.clearProperty("maxWidth");
    }
    if (requiredWidth > availableWidth) {
        int padding = 30 + ((children.getLength() - 1) * 35);
        int maxWidth = (availableWidth - padding) / children.getLength();
        setMaxWidth(maxWidth + "px");
    } else {
        setMaxWidth("none");
    }
}

From source file:org.pentaho.ui.xul.gwt.AbstractGwtXulComponent.java

License:Open Source License

public void layout() {
    if (this instanceof XulContainer == false) {
        // Core version of parser doesn't call layout unless the node is a container...
        return;/*from   ww w . j  a  v a2s  .c  o m*/
    }

    setVisible(isVisible());
    if (this.container != null) {
        this.container.clear();
    }

    Object w = getManagedObject();

    double totalFlex = 0.0;

    for (XulComponent comp : this.getChildNodes()) {

        if (comp.getManagedObject() == null) {
            continue;
        }
        if (comp.getFlex() > 0 && comp.isVisible()) {
            flexLayout = true;
            totalFlex += comp.getFlex();
        }
    }

    // if(flexLayout)
    // gc.fill = GridBagConstraints.BOTH;

    List<XulComponent> nodes = this.getChildNodes();

    XulContainer thisContainer = (XulContainer) this;

    Align alignment = (StringUtils.isEmpty(thisContainer.getAlign()) == false)
            ? Align.valueOf(thisContainer.getAlign().toUpperCase())
            : null;

    // TODO: this is a different behavior than we implemented in Swing.
    if (!flexLayout && StringUtils.isEmpty(thisContainer.getAlign()) == false) {
        SimplePanel fillerPanel = new SimplePanel();
        switch (alignment) {
        case END:
            container.add(fillerPanel);
            if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
                ((VerticalPanel) container).setCellHeight(fillerPanel, "100%");
            } else {
                ((HorizontalPanel) container).setCellWidth(fillerPanel, "100%");
            }
            break;
        case CENTER:
            container.add(fillerPanel);

            if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
                ((VerticalPanel) container).setCellHeight(fillerPanel, "50%");
            } else {
                ((HorizontalPanel) container).setCellWidth(fillerPanel, "50%");
            }
            break;
        }
    }

    for (int i = 0; i < children.size(); i++) {
        XulComponent comp = nodes.get(i);

        Object wrappedWidget = comp.getManagedObject();
        if (wrappedWidget == null || !(wrappedWidget instanceof Widget)) {
            continue;
        }
        Widget component = (Widget) wrappedWidget;
        component.getElement().setId(comp.getId());

        if (component == null) {
            continue;
        }
        SimplePanel componentWrapper = new SimplePanel();
        componentWrapper.add(component);
        container.add(componentWrapper);

        if (this.getOrientation() == Orient.VERTICAL) { // VBox
            container.setWidth("100%");

        } else { // HBox
            container.setHeight("100%");
        }

        if (flexLayout) {

            int componentFlex = comp.getFlex();
            if (componentFlex > 0) {

                String percentage = Math.round((componentFlex / totalFlex) * 100) + "%";
                if (this.getOrientation() == Orient.VERTICAL) { // VBox
                    ((VerticalPanel) container).setCellHeight(componentWrapper, percentage);
                    ((VerticalPanel) container).setCellWidth(componentWrapper, "100%");
                    component.setWidth("100%");

                    if (comp.getFlex() > 0) {
                        componentWrapper.setHeight("100%");
                        component.setHeight("100%");
                    }
                } else { // HBox
                    ((HorizontalPanel) container).setCellWidth(componentWrapper, percentage);
                    ((HorizontalPanel) container).setCellHeight(componentWrapper, "100%");
                    component.setHeight("100%");

                    if (comp.getFlex() > 0) {
                        componentWrapper.setWidth("100%");
                        component.setHeight("100%");
                    }
                }
            }
        }

        Style wrapperStyle = componentWrapper.getElement().getStyle();
        Style style = component.getElement().getStyle();
        // By default 100%, respect hard-coded width
        if (this.getOrientation() == Orient.VERTICAL) { // VBox
            if (comp.getWidth() > 0) {
                style.setProperty("width", comp.getWidth() + "px");
            } else {
                wrapperStyle.setProperty("width", "100%");
            }
            if (comp.getHeight() > 0) {
                style.setProperty("height", comp.getHeight() + "px");
            } else if (comp.getFlex() > 0) {
                wrapperStyle.setProperty("height", "100%");
            }
        } else { // HBox
            if (comp.getHeight() > 0) {
                style.setProperty("height", comp.getHeight() + "px");
            } else {
                wrapperStyle.setProperty("height", "100%");
            }
            if (comp.getWidth() > 0) {
                style.setProperty("width", comp.getWidth() + "px");
            } else if (comp.getFlex() > 0) {
                wrapperStyle.setProperty("width", "100%");
            }
        }
    }

    // TODO: this is a different behavior than we implemented in Swing.
    if (!flexLayout && container != null) {
        SimplePanel fillerPanel = new SimplePanel();
        if (alignment == null) {
            alignment = Align.START;
        }
        switch (alignment) {
        case START:
            if (this.getOrientation() != Orient.VERTICAL) {
                ((HorizontalPanel) container).setCellWidth(fillerPanel, "100%");
                container.add(fillerPanel);
            }
            break;
        case CENTER:
            container.add(fillerPanel);

            if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
                ((VerticalPanel) container).setCellHeight(fillerPanel, "50%");
            } else {
                ((HorizontalPanel) container).setCellWidth(fillerPanel, "50%");
            }
            break;
        case END:
            break;
        }
    }
    initialized = true;
}

From source file:org.pentaho.ui.xul.gwt.util.GenericDialog.java

License:Open Source License

public GenericDialog(String tagName) {
    super(tagName);

    glasspane.setStyleName("glasspane");
    Style glassPaneStyle = glasspane.getElement().getStyle();
    glassPaneStyle.setProperty("width", "100%");
    glassPaneStyle.setProperty("height", "100%");
    glassPaneStyle.setProperty("display", "block");

}

From source file:org.rstudio.core.client.widget.FixedRatioWidget.java

License:Open Source License

public FixedRatioWidget(Widget widget, double aspect, int maxWidth) {
    widget_ = widget;//from  w w  w.  j a  va  2  s  .  c om

    HTMLPanel outer = new HTMLPanel("");
    Style outerStyle = outer.getElement().getStyle();
    outerStyle.setWidth(100, Unit.PCT);
    outerStyle.setProperty("maxWidth", maxWidth + "px");

    HTMLPanel panel = new HTMLPanel("");
    Style panelStyle = panel.getElement().getStyle();
    panelStyle.setPosition(Position.RELATIVE);
    panelStyle.setWidth(100, Unit.PCT);
    panelStyle.setHeight(0, Unit.PX);
    panelStyle.setPaddingBottom((double) 100 * ((double) 1 / aspect), Unit.PCT);
    outer.add(panel);

    Style widgetStyle = widget.getElement().getStyle();
    widgetStyle.setPosition(Position.ABSOLUTE);
    widgetStyle.setWidth(100, Unit.PCT);
    widgetStyle.setHeight(100, Unit.PCT);
    widgetStyle.setLeft(0, Unit.PX);
    widgetStyle.setTop(0, Unit.PX);

    panel.add(widget_);
    initWidget(outer);
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ImagePreviewer.java

License:Open Source License

private static void onPreviewImageLineWidget(final DocDisplay display, final DocUpdateSentinel sentinel,
        final String href, final String attributes, final Position position, final Range tokenRange) {
    // if we already have a line widget for this row, bail
    LineWidget lineWidget = display.getLineWidgetForRow(position.getRow());
    if (lineWidget != null)
        return;/*from   w ww  .j  a va 2  s  .  co m*/

    // shared mutable state that we hide in this closure
    final Mutable<PinnedLineWidget> plw = new Mutable<PinnedLineWidget>();
    final Mutable<ChunkOutputWidget> cow = new Mutable<ChunkOutputWidget>();
    final Mutable<HandlerRegistration> docChangedHandler = new Mutable<HandlerRegistration>();
    final Mutable<HandlerRegistration> renderHandler = new Mutable<HandlerRegistration>();

    // command that ensures state is cleaned up when widget hidden
    final Command onDetach = new Command() {
        private void detach() {
            // detach chunk output widget
            cow.set(null);

            // detach pinned line widget
            if (plw.get() != null)
                plw.get().detach();
            plw.set(null);

            // detach render handler
            if (renderHandler.get() != null)
                renderHandler.get().removeHandler();
            renderHandler.set(null);

            // detach doc changed handler
            if (docChangedHandler.get() != null)
                docChangedHandler.get().removeHandler();
            docChangedHandler.set(null);
        }

        @Override
        public void execute() {
            // if the associated chunk output widget has been cleaned up,
            // make a last-ditch detach effort anyhow
            ChunkOutputWidget widget = cow.get();
            if (widget == null) {
                detach();
                return;
            }

            // fade out and then detach
            FadeOutAnimation anim = new FadeOutAnimation(widget, new Command() {
                @Override
                public void execute() {
                    detach();
                }
            });

            anim.run(400);
        }
    };

    // construct placeholder for image
    final SimplePanel container = new SimplePanel();
    container.addStyleName(RES.styles().container());
    final Label noImageLabel = new Label("(No image at path " + href + ")");

    // resize command (used by various routines that need to respond
    // to width / height change events)
    final CommandWithArg<Integer> onResize = new CommandWithArg<Integer>() {
        private int state_ = -1;

        @Override
        public void execute(Integer height) {
            // defend against missing chunk output widget (can happen if a widget
            // is closed / dismissed before image finishes loading)
            ChunkOutputWidget widget = cow.get();
            if (widget == null)
                return;

            // don't resize if the chunk widget if we were already collapsed
            int state = widget.getExpansionState();
            if (state == state_ && state == ChunkOutputWidget.COLLAPSED)
                return;

            state_ = state;
            widget.getFrame().setHeight(height + "px");
            LineWidget lw = plw.get().getLineWidget();
            lw.setPixelHeight(height);
            display.onLineWidgetChanged(lw);
        }
    };

    // construct our image
    String srcPath = imgSrcPathFromHref(sentinel, href);
    final Image image = new Image(srcPath);
    image.addStyleName(RES.styles().image());

    // parse and inject attributes
    Map<String, String> parsedAttributes = HTMLAttributesParser.parseAttributes(attributes);
    final Element imgEl = image.getElement();
    for (Map.Entry<String, String> entry : parsedAttributes.entrySet()) {
        String key = entry.getKey();
        String val = entry.getValue();
        if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val))
            continue;
        imgEl.setAttribute(key, val);
    }

    // add load handlers to image
    DOM.sinkEvents(imgEl, Event.ONLOAD | Event.ONERROR);
    DOM.setEventListener(imgEl, new EventListener() {
        @Override
        public void onBrowserEvent(Event event) {
            if (DOM.eventGetType(event) == Event.ONLOAD) {
                final ImageElementEx imgEl = image.getElement().cast();

                int minWidth = Math.min(imgEl.naturalWidth(), 100);
                int maxWidth = Math.min(imgEl.naturalWidth(), 650);

                Style style = imgEl.getStyle();

                boolean hasWidth = imgEl.hasAttribute("width") || style.getProperty("width") != null;

                if (!hasWidth) {
                    style.setProperty("width", "100%");
                    style.setProperty("minWidth", minWidth + "px");
                    style.setProperty("maxWidth", maxWidth + "px");
                }

                // attach to container
                container.setWidget(image);

                // update widget
                int height = image.getOffsetHeight() + 10;
                onResize.execute(height);
            } else if (DOM.eventGetType(event) == Event.ONERROR) {
                container.setWidget(noImageLabel);
                onResize.execute(50);
            }
        }
    });

    // handle editor resize events
    final Timer renderTimer = new Timer() {
        @Override
        public void run() {
            int height = image.getOffsetHeight() + 30;
            onResize.execute(height);
        }
    };

    // initialize render handler
    renderHandler.set(display.addRenderFinishedHandler(new RenderFinishedEvent.Handler() {
        private int width_;

        @Override
        public void onRenderFinished(RenderFinishedEvent event) {
            int width = display.getBounds().getWidth();
            if (width == width_)
                return;

            width_ = width;
            renderTimer.schedule(100);
        }
    }));

    // initialize doc changed handler
    docChangedHandler.set(display.addDocumentChangedHandler(new DocumentChangedEvent.Handler() {
        private String href_ = href;
        private String attributes_ = StringUtil.notNull(attributes);

        private final Timer refreshImageTimer = new Timer() {
            @Override
            public void run() {
                // if the discovered href isn't an image link, just bail
                if (!ImagePreviewer.isImageHref(href_))
                    return;

                // set new src location (load handler will replace label as needed)
                container.setWidget(new SimplePanel());
                noImageLabel.setText("(No image at path " + href_ + ")");
                image.getElement().setAttribute("src", imgSrcPathFromHref(sentinel, href_));

                // parse and inject attributes
                Map<String, String> parsedAttributes = HTMLAttributesParser.parseAttributes(attributes_);
                final Element imgEl = image.getElement();
                for (Map.Entry<String, String> entry : parsedAttributes.entrySet()) {
                    String key = entry.getKey();
                    String val = entry.getValue();
                    if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val))
                        continue;
                    imgEl.setAttribute(key, val);
                }
            }
        };

        private void onDocumentChangedImpl(DocumentChangedEvent event) {
            int row = plw.get().getRow();
            Range range = event.getEvent().getRange();
            if (range.getStart().getRow() <= row && row <= range.getEnd().getRow()) {
                String line = display.getLine(row);
                if (ImagePreviewer.isStandaloneMarkdownLink(line)) {
                    // check to see if the URL text has been updated
                    Token hrefToken = null;
                    JsArray<Token> tokens = display.getTokens(row);
                    for (Token token : JsUtil.asIterable(tokens)) {
                        if (token.hasType("href")) {
                            hrefToken = token;
                            break;
                        }
                    }

                    if (hrefToken == null)
                        return;

                    String attributes = "";
                    int startBraceIdx = line.indexOf("){");
                    int endBraceIdx = line.lastIndexOf("}");
                    if (startBraceIdx != -1 && endBraceIdx != -1 && endBraceIdx > startBraceIdx) {
                        attributes = line.substring(startBraceIdx + 2, endBraceIdx).trim();
                    }

                    // if we have the same href as before, don't update
                    // (avoid flickering + re-requests of same URL)
                    if (hrefToken.getValue().equals(href_) && attributes.equals(attributes_))
                        return;

                    // cache href and schedule refresh of image
                    href_ = hrefToken.getValue();
                    attributes_ = attributes;

                    refreshImageTimer.schedule(700);
                } else {
                    onDetach.execute();
                }
            }
        }

        @Override
        public void onDocumentChanged(final DocumentChangedEvent event) {
            // ignore 'removeLines' events as they won't mutate the actual
            // line containing the markdown link
            String action = event.getEvent().getAction();
            if (action.equals("removeLines"))
                return;

            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    onDocumentChangedImpl(event);
                }
            });
        }
    }));

    ChunkOutputHost host = new ChunkOutputHost() {
        @Override
        public void onOutputRemoved(final ChunkOutputWidget widget) {
            onDetach.execute();
        }

        @Override
        public void onOutputHeightChanged(ChunkOutputWidget widget, int height, boolean ensureVisible) {
            onResize.execute(height);
        }
    };

    cow.set(new ChunkOutputWidget(sentinel.getId(), "md-image-preview-" + StringUtil.makeRandomId(8),
            RmdChunkOptions.create(), ChunkOutputWidget.EXPANDED, false, // can close
            host, ChunkOutputSize.Bare));

    ChunkOutputWidget outputWidget = cow.get();
    outputWidget.setRootWidget(container);
    outputWidget.hideSatellitePopup();
    outputWidget.getElement().getStyle().setMarginTop(4, Unit.PX);

    plw.set(new PinnedLineWidget(LINE_WIDGET_TYPE, display, outputWidget, position.getRow(), null, null));
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ImagePreviewPopup.java

License:Open Source License

private void showWithDimensions(String width, String height) {
    setVisible(true);//w  ww  .  ja v  a 2  s  .co  m

    ImageElementEx el = image_.getElement().cast();
    Style style = el.getStyle();

    boolean isWide = el.naturalWidth() > el.naturalHeight();
    if (isWide)
        style.setProperty("maxWidth", width);
    else
        style.setProperty("maxHeight", height);
}

From source file:org.thechiselgroup.biomixer.client.core.ui.popup.DefaultPopup.java

License:Apache License

private void attachPopup() {
    NEffectPanel effectPanel = getEffectPanel();

    Style style = effectPanel.getElement().getStyle();

    /*//from  w  w w . j  a  v a2  s.co  m
     * INFO: position is fixed, not absolute, because there are problems
     * with absolute positioning when the window is scrolled.
     */
    style.setProperty(CSS.POSITION, CSS.FIXED);
    style.setProperty(CSS.Z_INDEX, Integer.toString(zIndex));
    style.setPropertyPx(CSS.LEFT, location.getX());
    style.setPropertyPx(CSS.TOP, location.getY());

    rootPanel.add(effectPanel);
}