List of usage examples for com.google.gwt.dom.client Style setProperty
public void setProperty(String name, String value)
From source file:com.vaadin.client.ui.VAbstractSplitPanel.java
License:Apache License
private void setSplitPosition(String pos, boolean rememberPosition) { if (pos == null) { return;//from w w w . j a v a2 s. c o m } pos = checkSplitPositionLimits(pos); if (rememberPosition && !pos.equals(position)) { position = convertToPositionUnits(pos); } // Convert percentage values to pixels if (pos.indexOf("%") > 0) { int size = orientation == Orientation.HORIZONTAL ? getOffsetWidth() : getOffsetHeight(); float percentage = Float.parseFloat(pos.substring(0, pos.length() - 1)); pos = percentage / 100 * size + "px"; } String attributeName; if (orientation == Orientation.HORIZONTAL) { if (positionReversed) { attributeName = "right"; } else { attributeName = "left"; } } else { if (positionReversed) { attributeName = "bottom"; } else { attributeName = "top"; } } Style style = splitter.getStyle(); if (!pos.equals(style.getProperty(attributeName))) { style.setProperty(attributeName, pos); updateSizes(); } }
From source file:com.vaadin.client.ui.VComboBox.java
License:Apache License
/** * Calculates the width of the select if the select has undefined width. * Should be called when the width changes or when the icon changes. * <p>/* w w w . j a v a2s .c o m*/ * For internal use only. May be removed or replaced in the future. */ public void updateRootWidth() { debug("VComboBox: updateRootWidth()"); if (connector.isUndefinedWidth()) { /* * When the select has a undefined with we need to check that we are * only setting the text box width relative to the first page width * of the items. If this is not done the text box width will change * when the popup is used to view longer items than the text box is * wide. */ int w = WidgetUtil.getRequiredWidth(this); if (dataReceivedHandler.isWaitingForInitialData() && suggestionPopupMinWidth > w) { /* * We want to compensate for the paddings just to preserve the * exact size as in Vaadin 6.x, but we get here before * MeasuredSize has been initialized. * Util.measureHorizontalPaddingAndBorder does not work with * border-box, so we must do this the hard way. */ Style style = getElement().getStyle(); String originalPadding = style.getPadding(); String originalBorder = style.getBorderWidth(); style.setPaddingLeft(0, Unit.PX); style.setBorderWidth(0, Unit.PX); style.setProperty("padding", originalPadding); style.setProperty("borderWidth", originalBorder); // Use util.getRequiredWidth instead of getOffsetWidth here int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil.getRequiredWidth(selectedItemIcon); int buttonWidth = popupOpener == null ? 0 : WidgetUtil.getRequiredWidth(popupOpener); /* * Instead of setting the width of the wrapper, set the width of * the combobox. Subtract the width of the icon and the * popupopener */ tb.setWidth(suggestionPopupMinWidth - iconWidth - buttonWidth + "px"); } /* * Lock the textbox width to its current value if it's not already * locked. This can happen after setWidth("") which resets the * textbox width to "100%". */ if (!tb.getElement().getStyle().getWidth().endsWith("px")) { int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon.getOffsetWidth(); tb.setWidth(tb.getOffsetWidth() - iconWidth + "px"); } } }
From source file:com.vaadin.client.ui.VFilterSelect.java
License:Apache License
/** * Calculates the width of the select if the select has undefined width. * Should be called when the width changes or when the icon changes. * <p>// w w w. j a v a 2 s. c o m * For internal use only. May be removed or replaced in the future. */ public void updateRootWidth() { ComponentConnector paintable = ConnectorMap.get(client).getConnector(this); if (paintable.isUndefinedWidth()) { /* * When the select has a undefined with we need to check that we are * only setting the text box width relative to the first page width * of the items. If this is not done the text box width will change * when the popup is used to view longer items than the text box is * wide. */ int w = WidgetUtil.getRequiredWidth(this); if ((!initDone || currentPage + 1 < 0) && suggestionPopupMinWidth > w) { /* * We want to compensate for the paddings just to preserve the * exact size as in Vaadin 6.x, but we get here before * MeasuredSize has been initialized. * Util.measureHorizontalPaddingAndBorder does not work with * border-box, so we must do this the hard way. */ Style style = getElement().getStyle(); String originalPadding = style.getPadding(); String originalBorder = style.getBorderWidth(); style.setPaddingLeft(0, Unit.PX); style.setBorderWidth(0, Unit.PX); style.setProperty("padding", originalPadding); style.setProperty("borderWidth", originalBorder); // Use util.getRequiredWidth instead of getOffsetWidth here int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil.getRequiredWidth(selectedItemIcon); int buttonWidth = popupOpener == null ? 0 : WidgetUtil.getRequiredWidth(popupOpener); /* * Instead of setting the width of the wrapper, set the width of * the combobox. Subtract the width of the icon and the * popupopener */ tb.setWidth((suggestionPopupMinWidth - iconWidth - buttonWidth) + "px"); } /* * Lock the textbox width to its current value if it's not already * locked */ if (!tb.getElement().getStyle().getWidth().endsWith("px")) { int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon.getOffsetWidth(); tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px"); } } }
From source file:com.vaadin.client.ui.VTabsheet.java
License:Apache License
/** For internal use only. May be removed or replaced in the future. */ public void updateDynamicWidth() { // Find width consumed by tabs TableCellElement spacerCell = ((TableElement) tb.getElement().cast()).getRows().getItem(0).getCells() .getItem(tb.getTabCount());/*from w ww.j a v a 2s . c o m*/ int spacerWidth = spacerCell.getOffsetWidth(); DivElement div = (DivElement) spacerCell.getFirstChildElement(); int spacerMinWidth = spacerCell.getOffsetWidth() - div.getOffsetWidth(); int tabsWidth = tb.getOffsetWidth() - spacerWidth + spacerMinWidth; // Find content width Style style = tabPanel.getElement().getStyle(); String overflow = style.getProperty("overflow"); style.setProperty("overflow", "hidden"); style.setPropertyPx("width", tabsWidth); boolean hasTabs = tabPanel.getWidgetCount() > 0; Style wrapperstyle = null; if (hasTabs) { wrapperstyle = getCurrentlyDisplayedWidget().getElement().getParentElement().getStyle(); wrapperstyle.setPropertyPx("width", tabsWidth); } // Get content width from actual widget int contentWidth = 0; if (hasTabs) { contentWidth = getCurrentlyDisplayedWidget().getOffsetWidth(); } style.setProperty("overflow", overflow); // Set widths to max(tabs,content) if (tabsWidth < contentWidth) { tabsWidth = contentWidth; } int outerWidth = tabsWidth + getContentAreaBorderWidth(); tabs.getStyle().setPropertyPx("width", outerWidth); style.setPropertyPx("width", tabsWidth); if (hasTabs) { wrapperstyle.setPropertyPx("width", tabsWidth); } contentNode.getStyle().setPropertyPx("width", tabsWidth); super.setWidth(outerWidth + "px"); updateOpenTabSize(); }
From source file:com.vaadin.client.ui.VTabsheet.java
License:Apache License
/** * Layouts the tab-scroller elements, and applies styles. *//*from ww w. j av a 2s.c o m*/ private void updateTabScroller() { if (!isDynamicWidth()) { tabs.getStyle().setWidth(100, Unit.PCT); } // Make sure scrollerIndex is valid if (scrollerIndex < 0 || scrollerIndex > tb.getTabCount()) { scrollerIndex = tb.getFirstVisibleTab(); } else if (tb.getTabCount() > 0 && tb.getTab(scrollerIndex).isHiddenOnServer()) { scrollerIndex = tb.getNextVisibleTab(scrollerIndex); } boolean scrolled = isScrolledTabs(); boolean clipped = isClippedTabs(); if (tb.getTabCount() > 0 && tb.isVisible() && (scrolled || clipped)) { scroller.getStyle().clearDisplay(); DOM.setElementProperty(scrollerPrev, "className", SCROLLER_CLASSNAME + (scrolled ? "Prev" : PREV_SCROLLER_DISABLED_CLASSNAME)); DOM.setElementProperty(scrollerNext, "className", SCROLLER_CLASSNAME + (clipped ? "Next" : "Next-disabled")); // the active tab should be focusable if and only if it is visible boolean isActiveTabVisible = scrollerIndex <= activeTabIndex && !isClipped(tb.selected); tb.selected.setTabulatorIndex(isActiveTabVisible ? tabulatorIndex : -1); } else { scroller.getStyle().setDisplay(Display.NONE); } if (BrowserInfo.get().isSafari()) { /* * another hack for webkits. tabscroller sometimes drops without * "shaking it" reproducable in * com.vaadin.tests.components.tabsheet.TabSheetIcons */ final Style style = scroller.getStyle(); style.setProperty("whiteSpace", "normal"); Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { style.setProperty("whiteSpace", ""); } }); } }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * Force webkit to redraw an element//from w w w .j a va2 s. co m * * @param element * The element that should be redrawn */ public static void forceWebkitRedraw(Element element) { Style style = element.getStyle(); String s = style.getProperty("webkitTransform"); if (s == null || s.length() == 0) { style.setProperty("webkitTransform", "scale(1)"); } else { style.setProperty("webkitTransform", ""); } }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * Temporarily sets the {@code styleProperty} to {@code tempValue} and then * resets it to its current value. Used mainly to work around rendering * issues in IE (and possibly in other browsers) * //from w w w .jav a 2 s . c om * @param element * The target element * @param styleProperty * The name of the property to set * @param tempValue * The temporary value */ public static void setStyleTemporarily(Element element, final String styleProperty, String tempValue) { final Style style = element.getStyle(); final String currentValue = style.getProperty(styleProperty); style.setProperty(styleProperty, tempValue); // Read a style-based property to force the browser to recalculate the // element's dimensions with the temporary style. element.getOffsetWidth(); style.setProperty(styleProperty, currentValue); }
From source file:com.vaadin.terminal.gwt.client.SimpleTree.java
License:Open Source License
public SimpleTree() { setElement(Document.get().createDivElement()); Style style = getElement().getStyle(); style.setProperty("whiteSpace", "nowrap"); style.setPadding(3, Unit.PX);/*from w w w .ja v a2s. c o m*/ style = handle.getStyle(); style.setDisplay(Display.NONE); style.setProperty("textAlign", "center"); style.setWidth(10, Unit.PX); style.setCursor(Cursor.POINTER); style.setBorderStyle(BorderStyle.SOLID); style.setBorderColor("#666"); style.setBorderWidth(1, Unit.PX); style.setMarginRight(3, Unit.PX); style.setProperty("borderRadius", "4px"); handle.setInnerHTML("+"); getElement().appendChild(handle); getElement().appendChild(text); style = children.getStyle(); style.setPaddingLeft(20, Unit.PX); style.setDisplay(Display.NONE); getElement().appendChild(children); addDomHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (event.getNativeEvent().getEventTarget().cast() == handle) { if (children.getStyle().getDisplay().intern() == Display.NONE.getCssName()) { open(event.getNativeEvent().getShiftKey()); } else { close(); } } else if (event.getNativeEvent().getEventTarget().cast() == text) { select(event); } } }, ClickEvent.getType()); }
From source file:com.vaadin.terminal.gwt.client.ui.FocusableScrollPanel.java
License:Open Source License
public FocusableScrollPanel() { // Prevent IE standard mode bug when a AbsolutePanel is contained. Style style = getElement().getStyle(); style.setOverflow(Overflow.AUTO);//from w w w .j a v a 2s . c o m style.setProperty("zoom", "1"); style.setPosition(Position.RELATIVE); }
From source file:com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout.java
License:Open Source License
public CellBasedLayout() { super();// w w w.j a v a2s. c o m setElement(Document.get().createDivElement()); getElement().getStyle().setProperty("overflow", "hidden"); if (BrowserInfo.get().isIE()) { getElement().getStyle().setProperty("position", "relative"); getElement().getStyle().setProperty("zoom", "1"); } root = Document.get().createDivElement(); root.getStyle().setProperty("overflow", "hidden"); if (BrowserInfo.get().isIE()) { root.getStyle().setProperty("position", "relative"); } getElement().appendChild(root); Style style = clearElement.getStyle(); style.setProperty("width", "0px"); style.setProperty("height", "0px"); style.setProperty("clear", "both"); style.setProperty("overflow", "hidden"); root.appendChild(clearElement); }