List of usage examples for com.google.gwt.dom.client Style setWidth
public void setWidth(double value, Unit unit)
From source file:com.vaadin.client.SimpleTree.java
License:Apache License
public SimpleTree() { setElement(Document.get().createDivElement()); Style style = getElement().getStyle(); style.setProperty("whiteSpace", "nowrap"); style.setPadding(3, Unit.PX);/*w w w. j a v a 2 s . c o m*/ style.setPaddingLeft(12, Unit.PX); // handle styling style = handle.getStyle(); style.setDisplay(Display.NONE); style.setTextAlign(TextAlign.CENTER); style.setWidth(0.5, Unit.EM); style.setHeight(0.5, Unit.EM); style.setCursor(Cursor.POINTER); style.setBackgroundColor("gray"); style.setColor("white"); style.setPadding(4, Unit.PX); style.setMarginRight(3, Unit.PX); style.setLineHeight(0.5, Unit.EM); handle.setInnerHTML("+"); getElement().appendChild(handle); getElement().appendChild(text); // children styling style = children.getStyle(); style.setPaddingLeft(1.5, Unit.EM); style.setDisplay(Display.NONE); getElement().appendChild(children); addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (event.getNativeEvent().getEventTarget().cast() == handle) { if (children.getStyle().getDisplay().intern() == Display.NONE.getCssName()) { open(event.getNativeEvent().getAltKey()); } else { close(); } } else if (event.getNativeEvent().getEventTarget().cast() == text) { select(event); } } }, ClickEvent.getType()); }
From source file:com.vaadin.client.ui.audio.AudioConnector.java
License:Apache License
@Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); // Opera (12.14) has a bug where an audio element w/o controls is shown // as 150x300px, which is not usually desired. However, in order to show // the error/alt message, we only do this in the exact situation. if (BrowserInfo.get().isOpera() && stateChangeEvent.hasPropertyChanged("showControls")) { Style style = getWidget().getElement().getStyle(); if (!getState().showControls) { if (isUndefinedHeight() && isUndefinedWidth() && getWidget().getOffsetHeight() == 150 && getWidget().getOffsetWidth() == 300) { // only if no size set and 150x300 style.setWidth(0, Unit.PX); style.setHeight(0, Unit.PX); }/*w w w. ja v a 2 s . c om*/ } else { // clear sizes if it's supposed to be undefined if (isUndefinedHeight()) { style.clearHeight(); } if (isUndefinedWidth()) { style.clearWidth(); } } } }
From source file:com.vaadin.client.ui.calendar.schedule.DateCellDayEvent.java
License:Apache License
@Override @SuppressWarnings("deprecation") public void onMouseMove(MouseMoveEvent event) { if (startY < 0 && startX < 0) { return;/*from w ww .jav a2s .co m*/ } if (isDisabled()) { Event.releaseCapture(getElement()); mouseMoveStarted = false; startY = -1; startX = -1; removeGlobalResizeStyle(); return; } int currentY = event.getClientY(); int currentX = event.getClientX(); int moveY = (currentY - startY); int moveX = (currentX - startX); if ((moveY < 5 && moveY > -6) && (moveX < 5 && moveX > -6)) { return; } if (!mouseMoveStarted) { setWidth(moveWidth); getElement().getStyle().setMarginLeft(0, Unit.PX); mouseMoveStarted = true; } HorizontalPanel parent = (HorizontalPanel) getParent().getParent(); int relativeX = event.getRelativeX(parent.getElement()) - weekGrid.timebar.getOffsetWidth(); int halfHourDiff = 0; if (moveY > 0) { halfHourDiff = (startYrelative + moveY) / slotHeight; } else { halfHourDiff = (moveY - startYrelative) / slotHeight; } int dateCellWidth = getDateCellWidth(); long dayDiff = 0; if (moveX >= 0) { dayDiff = (startXrelative + moveX) / dateCellWidth; } else { dayDiff = (moveX - (dateCellWidth - startXrelative)) / dateCellWidth; } int dayOffset = relativeX / dateCellWidth; // sanity check for right side overflow int dateCellCount = weekGrid.getDateCellCount(); if (dayOffset >= dateCellCount) { dayOffset--; dayDiff--; } int dayOffsetPx = calculateDateCellOffsetPx(dayOffset) + weekGrid.timebar.getOffsetWidth(); GWT.log("DateCellWidth: " + dateCellWidth + " dayDiff: " + dayDiff + " dayOffset: " + dayOffset + " dayOffsetPx: " + dayOffsetPx + " startXrelative: " + startXrelative + " moveX: " + moveX); if (relativeX < 0 || relativeX >= getDatesWidth()) { return; } Style s = getElement().getStyle(); Date from = calendarEvent.getStartTime(); Date to = calendarEvent.getEndTime(); long duration = to.getTime() - from.getTime(); if (!clickTargetsResize() && weekGrid.getCalendar().isEventMoveAllowed()) { long daysMs = dayDiff * DateConstants.DAYINMILLIS; from.setTime(startDatetimeFrom.getTime() + daysMs); from.setTime(from.getTime() + ((long) halfHourInMilliSeconds * halfHourDiff)); to.setTime((from.getTime() + duration)); calendarEvent.setStartTime(from); calendarEvent.setEndTime(to); calendarEvent.setStart(new Date(from.getTime())); calendarEvent.setEnd(new Date(to.getTime())); // Set new position for the event long startFromMinutes = (from.getHours() * 60) + from.getMinutes(); long range = calendarEvent.getRangeInMinutes(); startFromMinutes = calculateStartFromMinute(startFromMinutes, from, to, dayOffsetPx); if (startFromMinutes < 0) { range += startFromMinutes; } updatePosition(startFromMinutes, range); s.setLeft(dayOffsetPx, Unit.PX); if (weekGrid.getDateCellWidths() != null) { s.setWidth(weekGrid.getDateCellWidths()[dayOffset], Unit.PX); } else { setWidth(moveWidth); } } else if (clickTarget == topResizeBar) { long oldStartTime = startDatetimeFrom.getTime(); long newStartTime = oldStartTime + ((long) halfHourInMilliSeconds * halfHourDiff); if (!isTimeRangeTooSmall(newStartTime, startDatetimeTo.getTime())) { newStartTime = startDatetimeTo.getTime() - getMinTimeRange(); } from.setTime(newStartTime); calendarEvent.setStartTime(from); calendarEvent.setStart(new Date(from.getTime())); // Set new position for the event long startFromMinutes = (from.getHours() * 60) + from.getMinutes(); long range = calendarEvent.getRangeInMinutes(); updatePosition(startFromMinutes, range); } else if (clickTarget == bottomResizeBar) { long oldEndTime = startDatetimeTo.getTime(); long newEndTime = oldEndTime + ((long) halfHourInMilliSeconds * halfHourDiff); if (!isTimeRangeTooSmall(startDatetimeFrom.getTime(), newEndTime)) { newEndTime = startDatetimeFrom.getTime() + getMinTimeRange(); } to.setTime(newEndTime); calendarEvent.setEndTime(to); calendarEvent.setEnd(new Date(to.getTime())); // Set new position for the event long startFromMinutes = (startDatetimeFrom.getHours() * 60) + startDatetimeFrom.getMinutes(); long range = calendarEvent.getRangeInMinutes(); startFromMinutes = calculateStartFromMinute(startFromMinutes, from, to, dayOffsetPx); if (startFromMinutes < 0) { range += startFromMinutes; } updatePosition(startFromMinutes, range); } }
From source file:com.vaadin.client.ui.VMenuBar.java
License:Apache License
private int adjustPopupHeight(int top, final int shadowSpace) { // Check that the popup will fit the screen int availableHeight = RootPanel.getBodyElement().getOffsetHeight() - top - shadowSpace; int missingHeight = popup.getOffsetHeight() - availableHeight; if (missingHeight > 0) { // First move the top of the popup to get more space // Don't move above top of screen, don't move more than needed int moveUpBy = Math.min(top - shadowSpace, missingHeight); // Update state top -= moveUpBy;/*from w w w . j a v a 2 s . co m*/ missingHeight -= moveUpBy; availableHeight += moveUpBy; if (missingHeight > 0) { int contentWidth = visibleChildMenu.getOffsetWidth(); // If there's still not enough room, limit height to fit and add // a scroll bar Style style = popup.getElement().getStyle(); style.setHeight(availableHeight, Unit.PX); style.setOverflowY(Overflow.SCROLL); // Make room for the scroll bar by adjusting the width of the // popup style.setWidth(contentWidth + WidgetUtil.getNativeScrollbarSize(), Unit.PX); popup.positionOrSizeUpdated(); } } return top; }
From source file:com.vaadin.client.ui.VWindow.java
License:Apache License
private void fixIE8FocusCaptureIssue() { Element e = DOM.createInputText(); Style elemStyle = e.getStyle(); elemStyle.setPosition(Position.ABSOLUTE); elemStyle.setTop(-10, Unit.PX);/*from w ww . jav a 2 s. c om*/ elemStyle.setWidth(0, Unit.PX); elemStyle.setHeight(0, Unit.PX); contentPanel.getElement().appendChild(e); e.focus(); contentPanel.getElement().removeChild(e); }
From source file:com.vaadin.client.ui.window.WindowConnector.java
License:Apache License
@Override public void layout() { LayoutManager lm = getLayoutManager(); VWindow window = getWidget();//from w w w . j a v a2s . c o m ComponentConnector content = getContent(); boolean hasContent = (content != null); Element contentElement = window.contentPanel.getElement(); Style contentStyle = window.contents.getStyle(); int headerHeight = lm.getOuterHeight(window.header); contentStyle.setPaddingTop(headerHeight, Unit.PX); contentStyle.setMarginTop(-headerHeight, Unit.PX); int footerHeight = lm.getOuterHeight(window.footer); contentStyle.setPaddingBottom(footerHeight, Unit.PX); contentStyle.setMarginBottom(-footerHeight, Unit.PX); int minWidth = lm.getOuterWidth(window.header) - lm.getInnerWidth(window.header); int minHeight = footerHeight + headerHeight; getWidget().getElement().getStyle().setPropertyPx("minWidth", minWidth); getWidget().getElement().getStyle().setPropertyPx("minHeight", minHeight); /* * Must set absolute position if the child has relative height and * there's a chance of horizontal scrolling as some browsers will * otherwise not take the scrollbar into account when calculating the * height. */ if (hasContent) { Element layoutElement = content.getWidget().getElement(); Style childStyle = layoutElement.getStyle(); // IE8 needs some hackery to measure its content correctly WidgetUtil.forceIE8Redraw(layoutElement); if (content.isRelativeHeight() && !BrowserInfo.get().isIE9()) { childStyle.setPosition(Position.ABSOLUTE); Style wrapperStyle = contentElement.getStyle(); if (window.getElement().getStyle().getWidth().length() == 0 && !content.isRelativeWidth()) { /* * Need to lock width to make undefined width work even with * absolute positioning */ int contentWidth = lm.getOuterWidth(layoutElement); wrapperStyle.setWidth(contentWidth, Unit.PX); } else { wrapperStyle.clearWidth(); } } else { childStyle.clearPosition(); } } }
From source file:com.vaadin.client.VUIDLBrowser.java
License:Apache License
static void highlight(ComponentConnector paintable) { if (paintable != null) { Widget w = paintable.getWidget(); Style style = highlight.getStyle(); style.setTop(w.getAbsoluteTop(), Unit.PX); style.setLeft(w.getAbsoluteLeft(), Unit.PX); style.setWidth(w.getOffsetWidth(), Unit.PX); style.setHeight(w.getOffsetHeight(), Unit.PX); RootPanel.getBodyElement().appendChild(highlight); }/*w w w .j a v a 2 s .c om*/ }
From source file:com.vaadin.client.widgets.JsniWorkaround.java
License:Apache License
/** * Creates a new Escalator widget instance. *//*from w w w .j a v a 2 s . co m*/ public Escalator() { detectAndApplyPositionFunction(); getLogger().info("Using " + position.getClass().getSimpleName() + " for position"); final Element root = DOM.createDiv(); setElement(root); setupScrollbars(root); tableWrapper = DivElement.as(DOM.createDiv()); root.appendChild(tableWrapper); final Element table = DOM.createTable(); tableWrapper.appendChild(table); table.appendChild(headElem); table.appendChild(bodyElem); table.appendChild(footElem); Style hCornerStyle = headerDeco.getStyle(); hCornerStyle.setWidth(verticalScrollbar.getScrollbarThickness(), Unit.PX); hCornerStyle.setDisplay(Display.NONE); root.appendChild(headerDeco); Style fCornerStyle = footerDeco.getStyle(); fCornerStyle.setWidth(verticalScrollbar.getScrollbarThickness(), Unit.PX); fCornerStyle.setDisplay(Display.NONE); root.appendChild(footerDeco); Style hWrapperStyle = horizontalScrollbarDeco.getStyle(); hWrapperStyle.setDisplay(Display.NONE); hWrapperStyle.setHeight(horizontalScrollbar.getScrollbarThickness(), Unit.PX); root.appendChild(horizontalScrollbarDeco); setStylePrimaryName("v-escalator"); spacerDecoContainer.setAttribute("aria-hidden", "true"); // init default dimensions setHeight(null); setWidth(null); }
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. j a v a2 s .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.VMenuBar.java
License:Open Source License
private int adjustPopupHeight(int top, final int shadowSpace) { // Check that the popup will fit the screen int availableHeight = RootPanel.getBodyElement().getOffsetHeight() - top - shadowSpace; int missingHeight = popup.getOffsetHeight() - availableHeight; if (missingHeight > 0) { // First move the top of the popup to get more space // Don't move above top of screen, don't move more than needed int moveUpBy = Math.min(top - shadowSpace, missingHeight); // Update state top -= moveUpBy;/*w ww. j a v a 2 s. c o m*/ missingHeight -= moveUpBy; availableHeight += moveUpBy; if (missingHeight > 0) { int contentWidth = visibleChildMenu.getOffsetWidth(); // If there's still not enough room, limit height to fit and add // a scroll bar Style style = popup.getElement().getStyle(); style.setHeight(availableHeight, Unit.PX); style.setOverflowY(Overflow.SCROLL); // Make room for the scroll bar by adjusting the width of the // popup style.setWidth(contentWidth + Util.getNativeScrollbarSize(), Unit.PX); popup.updateShadowSizeAndPosition(); } } return top; }