protected AccessibleCheckBox(Element elem) { super(DOM.createSpan()); inputElem = InputElement.as(elem); labelElem = Document.get().createLabelElement(); getElement().appendChild(inputElem); getElement().appendChild(labelElem); String uid = DOM.createUniqueId(); inputElem.setPropertyString("id", uid); labelElem.setHtmlFor(uid); // Accessibility: setting tab index to be 0 by default, ensuring element // appears in tab sequence. FocusWidget's setElement method already // calls setTabIndex, which is overridden below. However, at the time // that this call is made, inputElem has not been created. So, we have // to call setTabIndex again, once inputElem has been created. setTabIndex(0); }
public void setWidget(Widget w, boolean delegateCaptionHandling) { if (w != null) { this.widgetType = VaadinWidgetUtils.getWidgetTypeByWidget(w); this.widgetElement = VaadinWidgetUtils.getElementByVaadinWidget(w, this.widgetType); if (this.widgetType.isAddStyle()) { this.widgetElement.addClassName(this.widgetType.getCssStyle()); } else { this.widgetElement.setClassName(this.widgetType.getCssStyle()); } if (delegateCaptionHandling) { getElement().appendChild(label = DOM.createLabel()); } else { getElement().appendChild(label = DOM.createDiv()); } getElement().appendChild(div); } super.setWidget(w); if (w != null) { getContainerElement().appendChild(small); getContainerElement().appendChild(feedback); } }
@Override protected void init() { clientWidth = DOM.getElementPropertyInt(label.getElement(), "clientHeight"); clientWidth = DOM.getElementPropertyInt(label.getElement(), "clientHeight"); clientHeight = DOM.getElementPropertyInt(label.getElement(), "clientHeight"); offsetWidth = label.getOffsetWidth(); offsetHeight = label.getOffsetHeight(); offsetTop = DOM.getElementPropertyInt(label.getElement(), "offsetTop"); offsetLeft = DOM.getElementPropertyInt(label.getElement(), "offsetLeft"); boder = (offsetHeight - clientHeight) / 2; custom(); this.setPixelSize((int) offsetWidth + offsetLeft * 2, (int) offsetHeight + offsetTop * 2); }
protected int getContainerOffsetLeft() { if (containerOffsetLeft < 0 || !sync) { int scrollLeft = 0; Element parent = DOM.getParent(getWidget().getElement()); while (parent != null) { if (getScrollLeft(parent) > 0) { scrollLeft += getScrollLeft(parent); GWT.log("Scroll left detected : " + scrollLeft); } if (containerFinder.isContainer(parent)) { containerOffsetLeft = DOM.getAbsoluteLeft(parent) - scrollLeft; } parent = DOM.getParent(parent); } } return containerOffsetLeft; }
public void onBrowserEvent(final Event event) { Element td = getEventTargetCell(event); if (td==null) return; final Element tr = DOM.getParent(td); int col = DOM.getChildIndex(tr, td); Element body = DOM.getParent(tr); int row = DOM.getChildIndex(body, tr); Widget widget = getWidget(row, col); if (widget != null && widget instanceof UniTimeHeaderPanel) { super.onBrowserEvent(event); return; } switch (DOM.eventGetType(event)) { case Event.ONMOUSEOVER: getRowFormatter().addStyleName(row, "hover"); break; case Event.ONMOUSEOUT: getRowFormatter().removeStyleName(row, "hover"); break; } super.onBrowserEvent(event); }
/** * Sets the font typeface for the given widget. * * @param widget widget to change font typeface for * @param typeface "0" for normal, "1" for sans serif, "2" for serif and * "3" for monospace */ static void setWidgetFontTypeface(Widget widget, String typeface) { switch (Integer.parseInt(typeface)) { default: // This should never happen throw new IllegalArgumentException("Typeface:" + typeface); case 0: case 1: typeface = "sans-serif"; break; case 2: typeface = "serif"; break; case 3: typeface = "monospace"; break; } DOM.setStyleAttribute(widget.getElement(), "fontFamily", typeface); }
@Override public void onBrowserEvent(Event event) { if (!isEnabled()) return; super.onBrowserEvent(event); if ((event.getTypeInt() & Event.KEYEVENTS) != 0) { int type = DOM.eventGetType(event); char keyCode = (char) event.getKeyCode(); switch (type) { case Event.ONKEYDOWN: if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') { if (iDown != null) setResource(iDown); } break; case Event.ONKEYUP: if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') { setResource(iUp); onClick(); } break; } } }
/** * Sets the text alignment for the given widget. * * @param widget widget to change text alignment for * @param align one of "0" for left, "1" for center or "2" for right */ static void setWidgetTextAlign(Widget widget, String align) { switch (Integer.parseInt(align)) { default: // This should never happen throw new IllegalArgumentException("align:" + align); case 0: align = "left"; break; case 1: align = "center"; break; case 2: align = "right"; break; } DOM.setStyleAttribute(widget.getElement(), "textAlign", align); }
public int getCellForWidget(Widget w) { for (Element e = w.getElement(); e != null; e = DOM.getParent(e)) { if (e.getPropertyString("tagName").equalsIgnoreCase("span")) { if (DOM.getParent(e) == getElement()) return DOM.getChildIndex(getElement(), e); } if (e == getElement()) { return -1; } } return -1; }
public int addRow(Widget header, Widget widget, int colSpan) { header.addStyleName("label-cell"); int row = getRowCount(); setWidget(row, 0, header); getCellFormatter().setStyleName(row, 0, "label-td"); if (widget instanceof HasMobileScroll) { ScrollPanel scroll = new ScrollPanel(widget); scroll.addStyleName("table-cell"); setWidget(row, 1, scroll); getCellFormatter().setStyleName(row, 1, "table-td"); } else { widget.addStyleName("widget-cell"); setWidget(row, 1, widget); getCellFormatter().setStyleName(row, 1, "widget-td"); } if (colSpan != 1) getFlexCellFormatter().setColSpan(row, 1, colSpan); if (header.getElement().getId() == null || header.getElement().getId().isEmpty()) header.getElement().setId(DOM.createUniqueId()); if (widget instanceof UniTimeWidget) Roles.getTextboxRole().setAriaLabelledbyProperty(((UniTimeWidget)widget).getWidget().getElement(), Id.of(header.getElement())); else Roles.getTextboxRole().setAriaLabelledbyProperty(widget.getElement(), Id.of(header.getElement())); return row; }
public void onBrowserEvent(Event event) { int x = 10 + event.getClientX() + getElement().getOwnerDocument().getScrollLeft(); int y = 10 + event.getClientY() + getElement().getOwnerDocument().getScrollTop(); switch (DOM.eventGetType(event)) { case Event.ONMOUSEMOVE: if (iHint.isShowing()) { iHint.setPopupPosition(x, y); } else { iShowHint.cancel(); iHint.setPopupPosition(x, y); iShowHint.schedule(1000); } break; case Event.ONMOUSEOUT: iShowHint.cancel(); if (iHint.isShowing()) iHideHint.schedule(1000); break; } }
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: SelectionMode mode = null; for (SelectionMode m: SelectionMode.values()) if (hasUnselectedDays(m)) { mode = m; break; } if (mode != null) setAllSelected(true, mode); else setAllSelected(false, SelectionMode.All); if (iCursor != null) iPanel.getWidget().setCursor(iCursor); event.preventDefault(); break; } super.onBrowserEvent(event); }
private void setImageProperty(String text) { imagePropValue = text; String url = convertImagePropertyValueToUrl(text); if (url == null) { hasImage = false; url = ""; setBackgroundColorProperty(backgroundColor); setShapeProperty(Integer.toString(shape)); } else { hasImage = true; // Android Buttons do not show a background color if they have an image. // The container's background color shows through any transparent // portions of the Image, an effect we can get in the browser by // setting the widget's background color to COLOR_NONE. MockComponentsUtil.setWidgetBackgroundColor(buttonWidget, "&H" + COLOR_NONE); DOM.setStyleAttribute(buttonWidget.getElement(), "borderRadius", "0px"); } MockComponentsUtil.setWidgetBackgroundImage(buttonWidget, url); image.setUrl(url); }
public void onBrowserEvent(Event event) { if (iHint.getText().isEmpty()) return; iX = 10 + event.getClientX() + getElement().getOwnerDocument().getScrollLeft(); iY = 10 + event.getClientY() + getElement().getOwnerDocument().getScrollTop(); switch (DOM.eventGetType(event)) { case Event.ONMOUSEMOVE: if (iInfoPanel.isShowing()) { int maxX = Window.getScrollLeft() + Window.getClientWidth() - iInfoPanel.getOffsetWidth() - 10; iInfoPanel.setPopupPosition(Math.min(iX, maxX), iY); } else if (iInfo.getRowCount() > 0) { iShowInfo.cancel(); iShowInfo.schedule(1000); } break; case Event.ONMOUSEOUT: iShowInfo.cancel(); if (iInfoPanel.isShowing()) iHideInfo.schedule(1000); break; } }
private SubmitCompleteHandler getSubmitCompleteHandler() { return new SubmitCompleteHandler() { public void onSubmitComplete(final SubmitCompleteEvent event) { final Element label = DOM.createLabel(); label.setInnerHTML(event.getResults()); final String csvData = label.getInnerText(); if (hasError(csvData)) { showAlert("Error: " + csvData); } else { parseCsvData(csvData); autoMessageBox.hide(); } } private boolean hasError(final String contentFile) { return contentFile.startsWith("413") || contentFile.startsWith("500"); } }; }
/** * Checks if the location is a valid drop location * * @param elementOver * The element to check * @return */ private boolean isLocationValid(Element elementOver) { Element weekGridElement = calendarConnector.getWidget().getWeekGrid() .getElement(); Element timeBarElement = calendarConnector.getWidget().getWeekGrid() .getTimeBar().getElement(); Element todayBarElement = null; if (calendarConnector.getWidget().getWeekGrid().hasToday()) { todayBarElement = calendarConnector.getWidget().getWeekGrid() .getDateCellOfToday().getTodaybarElement(); } // drops are not allowed in: // - weekday header // - allday event list // - todaybar // - timebar // - items return DOM.isOrHasChild(weekGridElement, elementOver) && !DOM.isOrHasChild(timeBarElement, elementOver) && todayBarElement != elementOver && (WidgetUtil.findWidget(elementOver, DateCellDayItem.class) == null); }
public void setToday(Date today, int width) { this.today = today; addStyleDependentName("today"); Element lastChild = (Element) getElement().getLastChild(); if (lastChild.getClassName().equals("v-calendar-current-time")) { todaybar = lastChild; } else { todaybar = DOM.createDiv(); todaybar.setClassName("v-calendar-current-time"); getElement().appendChild(todaybar); } if (width != -1) { todaybar.getStyle().setWidth(width, Unit.PX); } // position is calculated later, when we know the cell heights }
/** * Sets the canvas's BackgroundImage property to a new value. */ private void setBackgroundImageProperty(String text) { String url = convertImagePropertyValueToUrl(text); // We tell the layout (which is a MockCanvasLayout) that there is (or is not) a background // image so it can adjust the "layout width/height". The "layout width/height" is used when the // preferred width/height of a MockContainer is requested. See MockContainer.getPreferredWidth // and getPreferredHeight, as well as MockLayout.getPreferredWidth and getPreferredHeight. if (url == null) { // text was not recognized as an asset. ((MockCanvasLayout) layout).setBackgroundImageUrl(""); url = "images/canvas.png"; // We set the background image of the canvasWidget so it displays the image. We do it inside // the if because we need to override the background-size property only for this case MockComponentsUtil.setWidgetBackgroundImage(this, canvasWidget, url); DOM.setStyleAttribute(canvasWidget.getElement(), "backgroundSize", ""); } else { ((MockCanvasLayout) layout).setBackgroundImageUrl(url); // We set the background image of the canvasWidget so it displays the image. MockComponentsUtil.setWidgetBackgroundImage(this, canvasWidget, url); } }
/** * Overridden to send ValueChangeEvents only when appropriate. */ @Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEUP: case Event.ONBLUR: case Event.ONKEYDOWN: // Note the old value for onValueChange purposes (in ONCLICK case) oldValue = getValue(); break; case Event.ONCLICK: EventTarget target = event.getEventTarget(); if (Element.is(target) && labelElem.isOrHasChild(Element.as(target))) { // They clicked the label. Note our pre-click value, and // short circuit event routing so that other click handlers // don't hear about it oldValue = getValue(); return; } // It's not the label. Let our handlers hear about the // click... super.onBrowserEvent(event); // ...and now maybe tell them about the change ValueChangeEvent.fireIfNotEqual(AccessibleRadioButton.this, oldValue, getValue()); return; } super.onBrowserEvent(event); }
/** * Sets the font size for the given widget. * * @param widget widget to change font size for * @param size new font size (in scaled px) */ static void setWidgetFontSize(Widget widget, String size) { // Fonts on Android are in scaled pixels... try { DOM.setStyleAttribute(widget.getElement(), "fontSize", (int)(Float.parseFloat(size) * 0.9) + "px"); } catch (NumberFormatException e) { // Ignore this. If we throw an exception here, the project is unrecoverable. } }
public void onBrowserEvent(Event event) { Element td = getEventTargetCell(event); if (td==null) return; Element tr = DOM.getParent(td); Element body = DOM.getParent(tr); final int row = DOM.getChildIndex(body, tr); final ChainedCommand command = iRowClicks.get(row); switch (DOM.eventGetType(event)) { case Event.ONMOUSEOVER: getRowFormatter().setStyleName(row, "unitime-TableRowHover"); if (command == null) getRowFormatter().getElement(row).getStyle().setCursor(Cursor.AUTO); break; case Event.ONMOUSEOUT: getRowFormatter().setStyleName(row, null); break; case Event.ONCLICK: if (command == null) break; if (command.getLoadingMessage() != null) LoadingWidget.getInstance().show(command.getLoadingMessage()); getRowFormatter().setStyleName(row, "unitime-TableRowSelected"); iSelectedRow = row; command.execute(new ConditionalCommand() { @Override public void executeOnSuccess() { //getRowFormatter().setStyleName(row, null); if (command.getLoadingMessage() != null) LoadingWidget.getInstance().hide(); } @Override public void executeOnFailure() { getRowFormatter().setStyleName(row, "unitime-TableRowHover"); if (command.getLoadingMessage() != null) LoadingWidget.getInstance().hide(); } }); break; } }
public AriaCheckBox(Element elem) { super(elem); iAriaLabel = DOM.createLabel(); iAriaLabel.setId(DOM.createUniqueId()); iAriaLabel.setClassName("unitime-AriaLabel"); DOM.appendChild(getElement(), iAriaLabel); Roles.getCheckboxRole().setAriaLabelledbyProperty(elem, Id.of(iAriaLabel)); }
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if ((event.getTypeInt() & Event.KEYEVENTS) != 0) { int type = DOM.eventGetType(event); char keyCode = (char) event.getKeyCode(); switch (type) { case Event.ONKEYUP: if (keyCode == ' ' || keyCode == '\n' || keyCode == '\r') onClick(); break; } } }
private void ensureDividerInited() { if (dividerElement == null) { dividerElement = DOM.createDiv(); DOM.setStyleAttribute(dividerElement, "backgroundColor", DIVIDER_COLOR); setDividerVisible(false); DOM.appendChild(container.getRootPanel().getElement(), dividerElement); } }
@Override protected void insertTabWidget(Widget widget, int beforeIndex) { super.insertTabWidget(widget, beforeIndex); Roles.getTabRole().setAriaSelectedState(getTabElement(beforeIndex), SelectedValue.FALSE); getTabElement(beforeIndex).setId(DOM.createUniqueId()); Id ids[] = new Id[getTabCount()]; for (int i = 0; i < getTabCount(); i++) { Roles.getTabRole().setAriaLabelProperty(getTabElement(i), ARIA.tabNotSelected(1 + i, getTabCount(), getTabLabel(i))); ids[i] = Id.of(getTabElement(i)); } Roles.getTablistRole().setAriaOwnsProperty(getElement(), ids); }
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: MouseDownEvent.fireNativeEvent(event, this); event.stopPropagation(); event.preventDefault(); break; } }
private void setDividerBoundsAndShow(int x, int y, int width, int height) { DOM.setStyleAttribute(dividerElement, "position", "absolute"); DOM.setStyleAttribute(dividerElement, "left", x + "px"); DOM.setStyleAttribute(dividerElement, "top", y + "px"); DOM.setStyleAttribute(dividerElement, "width", width + "px"); DOM.setStyleAttribute(dividerElement, "height", height + "px"); setDividerVisible(true); }
protected void print() { final DataTable table = new DataTable(iLastResponse); Element headerRow = table.getRowFormatter().getElement(0); Element tableElement = table.getElement(); Element thead = DOM.createTHead(); tableElement.insertFirst(thead); headerRow.getParentElement().removeChild(headerRow); thead.appendChild(headerRow); Page page = new Page() { @Override public String getName() { return MESSAGES.sectAssignedClasses(); } @Override public String getUser() { return ""; } @Override public String getSession() { return ""; } @Override public Element getBody() { return table.getElement(); } }; ToolBox.print(page); }
private void swapRows(int r0, int r1) { if (r0 == r1) return; if (r0 > r1) { swapRows(r1, r0); } else { // r0 < r1 Element body = getBodyElement(); Element a = DOM.getChild(body, r0); Element b = DOM.getChild(body, r1); body.removeChild(a); body.removeChild(b); DOM.insertChild(body, b, r0); DOM.insertChild(body, a, r1); } }
public int getRowForWidget(Widget w) { for (Element td = w.getElement(); td != null; td = DOM.getParent(td)) { if (td.getPropertyString("tagName").equalsIgnoreCase("td")) { Element tr = DOM.getParent(td); Element body = DOM.getParent(tr); if (body == getBodyElement()) return DOM.getChildIndex(body, tr); } if (td == getBodyElement()) { return -1; } } return -1; }
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONBLUR: BlurEvent.fireNativeEvent(event, this); break; case Event.ONFOCUS: FocusEvent.fireNativeEvent(event, this); break; } super.onBrowserEvent(event); }
public RoomsOrInstructors(List<String> list, String delimiter) { super("itemize"); if (list != null) for (Iterator<String> i = list.iterator(); i.hasNext(); ) { P p = new P(DOM.createSpan(), "item"); p.setText(i.next() + (i.hasNext() ? delimiter : "")); add(p); } }
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONKEYPRESS: MenuItem item = iAccessKeys.get(Character.toLowerCase((char)event.getCharCode())); if (item != null) { event.stopPropagation(); event.preventDefault(); item.getScheduledCommand().execute(); } } super.onBrowserEvent(event); }
@Override public void setAriaLabel(String text) { if (iWidget instanceof HasAriaLabel) { ((HasAriaLabel)iWidget).setAriaLabel(text); } else { if (iAriaLabel == null) { iAriaLabel = DOM.createLabel(); iAriaLabel.setId(DOM.createUniqueId()); iAriaLabel.setClassName("hidden-label"); DOM.appendChild(getElement(), iAriaLabel); Roles.getCheckboxRole().setAriaLabelledbyProperty(iWidget.getElement(), Id.of(iAriaLabel)); } iAriaLabel.setInnerText(text); } }
static void restoreSizeStyle(Widget w, String[] style) { Element element = w.getElement(); if (style[0] != null) { DOM.setStyleAttribute(element, "width", style[0]); } if (style[1] != null) { DOM.setStyleAttribute(element, "height", style[1]); } }
public void onBrowserEvent(Event event) { Element td = getEventTargetCell(event); if (td==null) return; Element tr = DOM.getParent(td); Element body = DOM.getParent(tr); int row = DOM.getChildIndex(body, tr); int col = DOM.getChildIndex(tr, td); if (row == 0 || col ==0) return; processMouseEvent(DOM.eventGetType(event), row - 1, col - 1); }
@Override public void onBrowserEvent(Event event) { Element target = DOM.eventGetTarget(event); switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: boolean open = iFilterOpen.getElement().equals(target); boolean close = iFilterClose.getElement().equals(target); boolean clear = iFilterClear.getElement().equals(target); boolean filter = iFilter.getElement().equals(target); if (isFilterPopupShowing() || close) { hideFilterPopup(); } else if (open) { hideSuggestions(); showFilterPopup(); } if (clear) { iFilter.setText(""); removeAllChips(); setAriaLabel(toAriaString()); ValueChangeEvent.fire(FilterBox.this, getValue()); } if (!filter) { event.stopPropagation(); event.preventDefault(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { iFilter.setFocus(true); } }); } break; } }
static String[] clearSizeStyle(Widget w) { Element element = w.getElement(); String widthStyle = DOM.getStyleAttribute(element, "width"); String heightStyle = DOM.getStyleAttribute(element, "height"); if (widthStyle != null) { DOM.setStyleAttribute(element, "width", null); } if (heightStyle != null) { DOM.setStyleAttribute(element, "height", null); } return new String[] { widthStyle, heightStyle }; }