Java Code Examples for com.google.gwt.user.client.ui.UIObject

The following examples show how to use com.google.gwt.user.client.ui.UIObject. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cuba   Source File: VDDHorizontalLayout.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Removes any applies drag and drop style applied by emphasis()
 */
protected void deEmphasis() {
    if (currentlyEmphasised != null) {
        // Universal over style
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER,
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER_SPACED,
                false);

        // Horizontal styles
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-"
                + HorizontalDropLocation.LEFT.toString().toLowerCase(),
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-"
                + HorizontalDropLocation.CENTER.toString().toLowerCase(),
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-"
                + HorizontalDropLocation.RIGHT.toString().toLowerCase(),
                false);

        currentlyEmphasised = null;
    }
}
 
Example 2
Source Project: cuba   Source File: VDDVerticalLayout.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Removes any applies drag and drop style applied by emphasis()
 */
protected void deEmphasis() {
    if (currentlyEmphasised != null) {
        // Universal over style
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER,
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER_SPACED,
                false);

        // Vertical styles
        UIObject.setStyleName(currentlyEmphasised.getElement(),
                OVER + "-"
                        + VerticalDropLocation.TOP.toString().toLowerCase(),
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-"
                + VerticalDropLocation.MIDDLE.toString().toLowerCase(),
                false);
        UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-"
                + VerticalDropLocation.BOTTOM.toString().toLowerCase(),
                false);

        currentlyEmphasised = null;
    }
}
 
Example 3
Source Project: gwt-material   Source File: MaterialWidgetTestCase.java    License: Apache License 2.0 6 votes vote down vote up
protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target, boolean checkElement) {
    final Element element = target.getElement();
    if(checkElement) {
        assertFalse(element.hasClassName(CssName.DISABLED));
        assertFalse(element.hasAttribute(CssName.DISABLED));
    }
    widget.setEnabled(true);
    if(checkElement) {
        assertFalse(element.hasClassName(CssName.DISABLED));
        assertFalse(element.hasAttribute(CssName.DISABLED));
    }
    assertEquals(widget.isEnabled(), true);
    widget.setEnabled(false);
    if(checkElement) {
        assertTrue(element.hasClassName(CssName.DISABLED));
        assertTrue(element.hasAttribute(CssName.DISABLED));
    }
    assertEquals(target.isEnabled(), false);
}
 
Example 4
Source Project: unitime   Source File: FilterBox.java    License: Apache License 2.0 6 votes vote down vote up
private void position(final UIObject relativeObject, int offsetWidth, int offsetHeight) {
	int textBoxOffsetWidth = relativeObject.getOffsetWidth();
	int offsetWidthDiff = offsetWidth - textBoxOffsetWidth;
	int left = relativeObject.getAbsoluteLeft();
	if (offsetWidthDiff > 0) {
		int windowRight = Window.getClientWidth() + Window.getScrollLeft();
		int windowLeft = Window.getScrollLeft();
		int distanceToWindowRight = windowRight - left;
		int distanceFromWindowLeft = left - windowLeft;
		if (distanceToWindowRight < offsetWidth && distanceFromWindowLeft >= offsetWidthDiff) {
			left -= offsetWidthDiff;
		}
	}
	int top = relativeObject.getAbsoluteTop();
	int windowTop = Window.getScrollTop();
	int windowBottom = Window.getScrollTop() + Window.getClientHeight();
	int distanceFromWindowTop = top - windowTop;
	int distanceToWindowBottom = windowBottom - (top + relativeObject.getOffsetHeight());
	if (distanceToWindowBottom < offsetHeight && distanceFromWindowTop >= offsetHeight) {
		top -= offsetHeight;
	} else {
		top += relativeObject.getOffsetHeight();
	}
	setPopupPosition(left, top);
}
 
Example 5
Source Project: gwtbootstrap3-extras   Source File: Animate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Animate any element with specific animation. Animation is done by CSS and runs multiple times.
 *
 * Animation is started when element is appended to the DOM or new (not same) animation is added
 * to already displayed element. Animation runs on hidden elements too and is not paused/stopped
 * when element is set as hidden.
 *
 * @param widget Widget to apply animation to.
 * @param animation Type of animation to apply.
 * @param count Number of animation repeats. 0 disables animation, any negative value set repeats to infinite.
 * @param duration Animation duration in ms. 0 disables animation, any negative value keeps default of original animation.
 * @param delay Delay before starting the animation loop in ms. Value <= 0 means no delay.
 * @param <T> Any object extending UIObject class (typically Widget).
 * @return Animation's CSS class name, which can be removed to stop animation.
 */
public static <T extends UIObject> String animate(final T widget, final Animation animation, final int count, final int duration, final int delay) {

    if (widget != null && animation != null) {
        // on valid input
        if (widget.getStyleName().contains(animation.getCssName())) {
            // animation is present, remove it and run again.
            stopAnimation(widget, animation.getCssName() + " " + getStyleNameFromAnimation(animation.getCssName(),count,duration,delay));
            Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
                @Override
                public boolean execute() {
                    styleElement(widget.getElement(), animation.getCssName(), count, duration, delay);
                    return false;
                }
            }, 200);
            return animation.getCssName() + " " + getStyleNameFromAnimation(animation.getCssName(),count,duration,delay);
        } else {
            // animation was not present, run immediately
            return styleElement(widget.getElement(), animation.getCssName(), count, duration, delay);
        }
    } else {
        return null;
    }

}
 
Example 6
Source Project: gwtbootstrap3-extras   Source File: Animate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Animate any element with specific animation. Animation is done by CSS and runs multiple times.
 *
 * Animation is started when element is appended to the DOM or new (not same) animation is added
 * to already displayed element. Animation runs on hidden elements too and is not paused/stopped
 * when element is set as hidden.
 *
 * @param widget Widget to apply animation to.
 * @param animation Custom CSS class name used as animation.
 * @param count Number of animation repeats. 0 disables animation, any negative value set repeats to infinite.
 * @param duration Animation duration in ms. 0 disables animation, any negative value keeps default of original animation.
 * @param delay Delay before starting the animation loop in ms. Value <= 0 means no delay.
 * @param <T> Any object extending UIObject class (typically Widget).
 * @return Animation's CSS class name, which can be removed to stop animation.
 */
public static <T extends UIObject> String animate(final T widget, final String animation, final int count, final int duration, final int delay) {

    if (widget != null && animation != null) {
        // on valid input
        if (widget.getStyleName().contains(animation)) {
            // animation is present, remove it and run again.
            stopAnimation(widget, animation);
            Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
                @Override
                public boolean execute() {
                    styleElement(widget.getElement(), animation, count, duration, delay);
                    return false;
                }
            }, 200);
            return animation + " " + getStyleNameFromAnimation(animation,count,duration,delay);
        } else {
            // animation was not present, run immediately
            return styleElement(widget.getElement(), animation, count, duration, delay);
        }
    } else {
        return null;
    }

}
 
Example 7
Source Project: cuba   Source File: CubaRichTextToolbarWidget.java    License: Apache License 2.0 5 votes vote down vote up
public void setLocaleMap(Map<String,String> localeMap) {
    Map<String, UIObject> locales = new HashMap<>();
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_BOLD_LABEL, bold);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_ITALIC_LABEL, italic);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_UNDERLINE_LABEL, underline);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_SUBSCRIPT_LABEL, subscript);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_SUPERSCRIPT_LABEL, superscript);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYCENTER_LABEL, justifyCenter);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYRIGHT_LABEL, justifyRight);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYLEFT_LABEL, justifyLeft);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_STRIKETHROUGH_LABEL, strikethrough);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_INDENT_LABEL, indent);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_OUTDENT_LABEL, outdent);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_HR_LABEL, hr);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_OL_LABEL, ol);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_UL_LABEL, ul);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_INSERTIMAGE_LABEL, insertImage);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_CREATELINK_LABEL, createLink);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_REMOVELINK_LABEL, removeLink);
    locales.put(CubaRichTextAreaState.RICH_TEXT_AREA_REMOVEFORMAT_LABEL, removeFormat);

    for (Map.Entry<String, UIObject> entry : locales.entrySet()) {
        entry.getValue().setTitle(localeMap.get(entry.getKey()));
        entry.getValue().getElement().setAttribute("icon-id", entry.getKey());
    }

    setBackgroundColorLocaleMap(localeMap);
    setForegroundColorLocaleMap(localeMap);
    setSizeLocaleMap(localeMap);
    setFontLocaleMap(localeMap);
}
 
Example 8
Source Project: cuba   Source File: SuggestionsContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void clearItems() {
    selectItem(null);

    container.removeAllChildren();

    for (UIObject item : items) {
        item.getElement().setPropertyInt("colSpan", 1);
        ((SuggestionItem) item).setSuggestionsContainer(null);
    }

    items.clear();
}
 
Example 9
Source Project: cuba   Source File: VDDHorizontalLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Empasises the drop location of the component when hovering over a
 * ĆhildComponentContainer. Passing null as the container removes any
 * previous emphasis.
 * 
 * @param container
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void emphasis(Widget container, VDragEvent event) {

    // Remove emphasis from previous hovers
    deEmphasis();

    // validate container
    if (container == null
            || !getElement().isOrHasChild(container.getElement())) {
        return;
    }

    currentlyEmphasised = container;

    HorizontalDropLocation location = null;

    // Add drop location specific style
    if (currentlyEmphasised != this) {
        location = getHorizontalDropLocation(container, event);

    } else {
        location = HorizontalDropLocation.CENTER;
    }

    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true);
    UIObject.setStyleName(currentlyEmphasised.getElement(),
            OVER + "-" + location.toString().toLowerCase(), true);
}
 
Example 10
Source Project: cuba   Source File: VDDVerticalLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Empasises the drop location of the component when hovering over a
 * ĆhildComponentContainer. Passing null as the container removes any
 * previous emphasis.
 * 
 * @param container
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void emphasis(Widget container, VDragEvent event) {

    // Remove emphasis from previous hovers
    deEmphasis();

    // validate container
    if (container == null
            || !getElement().isOrHasChild(container.getElement())) {
        return;
    }

    currentlyEmphasised = container;

    VerticalDropLocation location = null;

    // Add drop location specific style
    if (currentlyEmphasised != this) {
        location = getVerticalDropLocation(currentlyEmphasised, event);

    } else {
        location = VerticalDropLocation.MIDDLE;
    }

    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true);
    UIObject.setStyleName(currentlyEmphasised.getElement(),
            OVER + "-" + location.toString().toLowerCase(), true);
}
 
Example 11
Source Project: gwt-material   Source File: StyleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method for first removing all enum style constants and then adding the single one.
 *
 * @see #removeEnumStyleNames(UIObject, Class)
 * @see #addEnumStyleName(UIObject, Style.HasCssName)
 */
public static <E extends Style.HasCssName, F extends Enum<? extends Style.HasCssName>> void addUniqueEnumStyleName(final UIObject uiObject,
                                                                                                                   final Class<F> enumClass,
                                                                                                                   final E style) {
    removeEnumStyleNames(uiObject, enumClass);
    addEnumStyleName(uiObject, style);
}
 
Example 12
Source Project: gwt-material   Source File: StyleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes all CSS style names specified by an enum that implements {@link Style.HasCssName} from an UIObject.
 *
 * @param uiObject  Object to remove CSS class names from
 * @param enumClass Enum representing CSS class names
 * @param <E>       Enum type implementing {@link Style.HasCssName}
 */
public static <E extends Enum<? extends Style.HasCssName>> void removeEnumStyleNames(final UIObject uiObject,
                                                                                     final Class<E> enumClass) {

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final String cssClass = ((Style.HasCssName) constant).getCssName();

        if (cssClass != null && !cssClass.isEmpty()) {
            uiObject.removeStyleName(cssClass);
        }
    }
}
 
Example 13
Source Project: gwt-material   Source File: StyleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds enum value style name to UIObject unless style is {@code null}.
 *
 * @param uiObject Object to add style to
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void addEnumStyleName(final UIObject uiObject,
                                                                 final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.addStyleName(style.getCssName());
    }
}
 
Example 14
Source Project: gwt-material   Source File: StyleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes enum value style name from UIObject unless style is {@code null}.
 *
 * @param uiObject Object to remove style from
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void removeEnumStyleName(final UIObject uiObject,
                                                                    final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.removeStyleName(style.getCssName());
    }
}
 
Example 15
Source Project: gwt-material   Source File: StyleHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Toggles a style name on a ui object
 *
 * @param uiObject    Object to toggle style on
 * @param toggleStyle whether or not to toggle the style name on the object
 * @param styleName   Style name
 */
public static void toggleStyleName(final UIObject uiObject,
                                   final boolean toggleStyle,
                                   final String styleName) {
    if (toggleStyle) {
        uiObject.addStyleName(styleName);
    } else {
        uiObject.removeStyleName(styleName);
    }
}
 
Example 16
Source Project: gwt-material   Source File: EnabledMixin.java    License: Apache License 2.0 5 votes vote down vote up
private void applyEnabled(boolean enabled, UIObject obj) {
    if (enabled) {
        obj.removeStyleName(CssName.DISABLED);
        obj.getElement().removeAttribute(DISABLED);
    } else {
        obj.addStyleName(CssName.DISABLED);
        obj.getElement().setAttribute(DISABLED, "");
    }

    updateWaves(enabled, obj);
}
 
Example 17
Source Project: gwt-material   Source File: EnabledMixin.java    License: Apache License 2.0 5 votes vote down vote up
public void updateWaves(boolean enabled, UIObject obj) {
    if (obj instanceof MaterialWidget) {
        MaterialWidget widget = (MaterialWidget) obj;
        if (enabled) {
            if (widget.getWaves() != null) {
                widget.getElement().addClassName(CssName.WAVES_EFFECT);
            }
        } else {
            widget.getElement().removeClassName(CssName.WAVES_EFFECT);
        }
    }
}
 
Example 18
Source Project: gwt-material   Source File: MaterialWidgetTest.java    License: Apache License 2.0 5 votes vote down vote up
protected <W extends UIObject & HasReadOnly> void checkReadOnly(W widget, UIObject target, boolean checkElement) {
    // given
    Element widgetElement = widget.getElement();
    Element targetElement = target.getElement();

    // when / then
    widget.setReadOnly(true);
    if (checkElement) {
        assertTrue(targetElement.hasAttribute("disabled"));
        assertTrue(widgetElement.hasClassName(CssName.READ_ONLY));
    }
    assertTrue(widget.isReadOnly());
    widget.setReadOnly(false);
    if (checkElement) {
        assertFalse(targetElement.hasAttribute("disabled"));
        assertFalse(widgetElement.hasClassName(CssName.READ_ONLY));
    }
    assertFalse(widget.isReadOnly());

    widget.setToggleReadOnly(true);
    if (checkElement) {
        assertTrue(widgetElement.hasClassName(CssName.READ_ONLY_TOGGLE));
    }
    assertTrue(widget.isToggleReadOnly());
    widget.setToggleReadOnly(false);
    if (checkElement) {
        assertFalse(widgetElement.hasClassName(CssName.READ_ONLY_TOGGLE));
    }
    assertFalse(widget.isToggleReadOnly());
}
 
Example 19
Source Project: gwt-material   Source File: AbstractButtonTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target) {
    super.checkEnabled(widget, target);

    widget.setEnabled(false);
    assertTrue(target.getElement().hasAttribute("onclick"));
    assertEquals("return false", target.getElement().getAttribute("onclick"));

    widget.setEnabled(true);
    assertFalse(target.getElement().hasAttribute("onclick"));
}
 
Example 20
Source Project: gwt-material   Source File: MaterialWidgetTestCase.java    License: Apache License 2.0 5 votes vote down vote up
public static <H extends UIObject & HasColors> void checkColor(H hasColors) {
    final Element element = hasColors.getElement();
    hasColors.setTextColor(Color.WHITE);
    assertTrue(element.hasClassName(Color.WHITE.getCssName() + "-text"));
    hasColors.setBackgroundColor(Color.BLACK);
    assertTrue(element.hasClassName(Color.BLACK.getCssName()));
}
 
Example 21
/**
 * Ignore any elements to be swipeable
 */
public void ignore(UIObject object, UIObject... objects) {
    object.addStyleName(AddinsCssName.IGNORED);

    if (objects != null) {
        for (UIObject obj : objects) {
            obj.addStyleName(AddinsCssName.IGNORED);
        }
    }
}
 
Example 22
/**
 * Remove Ignore property to any ignored elements
 */
public void removeIgnore(UIObject object, UIObject... objects) {
    object.removeStyleName(AddinsCssName.IGNORED);

    if (objects != null) {
        for (UIObject obj : objects) {
            obj.removeStyleName(AddinsCssName.IGNORED);
        }
    }
}
 
Example 23
Source Project: gwt-material-addins   Source File: MaterialWindow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the area for the drag and drop, can be an {@link Element}
 * or a {@link String} selector.
 */
public void setDndArea(Object dndArea) {
    if (dndArea instanceof UIObject) {
        dndArea = ((UIObject) dndArea).getElement();
    }
    if (dnd != null) {
        dnd.draggable(JsDragOptions.create(new Restriction(dndArea, true, 0, 0, 1.2, 1)));
    }
}
 
Example 24
Source Project: unitime   Source File: WebTable.java    License: Apache License 2.0 5 votes vote down vote up
public void setStyleName(String styleName) {
	super.setStyleName(styleName);
	for (UIObject c: iContent) {
		c.setStyleName(styleName);
		c.getElement().getStyle().setBorderWidth(0, Unit.PX);
	}
}
 
Example 25
Source Project: swellrt   Source File: WebClient.java    License: Apache License 2.0 5 votes vote down vote up
private void setupWavePanel() {
  // Hide the frame until waves start getting opened.
  UIObject.setVisible(waveFrame.getElement(), false);

  Document.get().getElementById("signout").setInnerText(messages.signout());

  // Handles opening waves.
  ClientEvents.get().addWaveSelectionEventHandler(new WaveSelectionEventHandler() {
    @Override
    public void onSelection(WaveRef waveRef) {
      openWave(waveRef, false, null);
    }
  });
}
 
Example 26
Source Project: incubator-retired-wave   Source File: WebClient.java    License: Apache License 2.0 5 votes vote down vote up
private void setupWavePanel() {
  // Hide the frame until waves start getting opened.
  UIObject.setVisible(waveFrame.getElement(), false);

  Document.get().getElementById("signout").setInnerText(messages.signout());

  // Handles opening waves.
  ClientEvents.get().addWaveSelectionEventHandler(new WaveSelectionEventHandler() {
    @Override
    public void onSelection(WaveRef waveRef) {
      openWave(waveRef, false, null);
    }
  });
}
 
Example 27
@Override
public void reset(UIObject obj) {
	reset();
}
 
Example 28
Source Project: gwt-material   Source File: AbstractValueWidget.java    License: Apache License 2.0 4 votes vote down vote up
protected RequiredFieldMixin<AbstractValueWidget, UIObject> getRequiredFieldMixin() {
    if (requiredFieldMixin == null) {
        requiredFieldMixin = new RequiredFieldMixin<>(this, getStatusTextMixin().getPlaceholder());
    }
    return requiredFieldMixin;
}
 
Example 29
Source Project: gwt-material   Source File: CssTypeMixin.java    License: Apache License 2.0 4 votes vote down vote up
public CssTypeMixin(final H widget, UIObject target) {
    super(widget);
    this.target = target;
}
 
Example 30
Source Project: gwt-material   Source File: StatusTextMixin.java    License: Apache License 2.0 4 votes vote down vote up
public StatusTextMixin(final T widget, final H textObject, UIObject target) {
    super(widget);

    this.textObject = textObject;
    this.target = target;
}