Search in sources :

Example 26 with Style

use of com.google.gwt.dom.client.Style in project gwt-test-utils by gwt-test-utils.

the class StyleTest method properties.

@Test
public void properties() {
    // Given
    Button button = new Button();
    Style style = button.getElement().getStyle();
    // When 1
    style.setBackgroundColor("black");
    style.setBackgroundImage("/img.png");
    style.setBorderColor("blue");
    style.setBorderWidth(1.0, Unit.EM);
    style.setBottom(4.0, Unit.PX);
    style.setColor("red");
    style.setCursor(Style.Cursor.E_RESIZE);
    style.setFloat(Float.LEFT);
    style.setDisplay(Display.INLINE_BLOCK);
    style.setFontSize(10.5, Style.Unit.CM);
    style.setFontStyle(Style.FontStyle.NORMAL);
    style.setFontWeight(Style.FontWeight.BOLD);
    style.setHeight(3.1, Style.Unit.PC);
    style.setLeft(40, Style.Unit.IN);
    style.setListStyleType(ListStyleType.CIRCLE);
    style.setMargin(30.5, Style.Unit.PCT);
    style.setMarginBottom(29, Style.Unit.PT);
    style.setMarginLeft(47, Style.Unit.EX);
    style.setMarginRight(3, Style.Unit.MM);
    style.setMarginTop(10.3, Style.Unit.CM);
    style.setOverflow(Overflow.SCROLL);
    style.setPadding(10, Style.Unit.PX);
    style.setPaddingBottom(11, Style.Unit.PX);
    style.setPaddingLeft(12, Style.Unit.PX);
    style.setPaddingRight(13, Style.Unit.PX);
    style.setPaddingTop(14, Style.Unit.PX);
    style.setPosition(Position.RELATIVE);
    style.setProperty("string", "stringvalue");
    style.setProperty("doubleUnit", 17.2, Style.Unit.CM);
    style.setRight(13.4, Style.Unit.CM);
    style.setTextDecoration(TextDecoration.OVERLINE);
    style.setTop(7.77, Style.Unit.PC);
    style.setVerticalAlign(VerticalAlign.MIDDLE);
    style.setVisibility(Visibility.VISIBLE);
    style.setWidth(3.5, Style.Unit.PX);
    style.setZIndex(1000);
    // Then 1
    assertThat(button.getElement().getAttribute("style")).isEqualTo("background-color: black; background-image: /img.png; border-color: blue; border-bottom-width: 1em; border-left-width: 1em; border-right-width: 1em; border-top-width: 1em; bottom: 4px; color: red; cursor: e-resize; float: left; display: inline-block; font-size: 10.5cm; font-style: normal; font-weight: bold; height: 3.1pc; left: 40in; list-style-type: circle; margin: 30.5%; margin-bottom: 29pt; margin-left: 47ex; margin-right: 3mm; margin-top: 10.3cm; overflow: scroll; padding: 10px; padding-bottom: 11px; padding-left: 12px; padding-right: 13px; padding-top: 14px; position: relative; string: stringvalue; double-unit: 17.2cm; right: 13.4cm; text-decoration: overline; top: 7.77pc; vertical-align: middle; visibility: visible; width: 3.5px; z-index: 1000; ");
    assertThat(style.getBackgroundColor()).isEqualTo("black");
    assertThat(style.getBackgroundImage()).isEqualTo("/img.png");
    assertThat(style.getBorderColor()).isEqualTo("blue");
    assertThat(style.getBorderWidth()).isEqualTo("1em");
    assertThat(style.getBottom()).isEqualTo("4px");
    assertThat(style.getColor()).isEqualTo("red");
    assertThat(style.getCursor()).isEqualTo(Style.Cursor.E_RESIZE.getCssName());
    assertThat(style.getDisplay()).isEqualTo(Display.INLINE_BLOCK.getCssName());
    assertThat(style.getFontSize()).isEqualTo("10.5cm");
    assertThat(style.getFontStyle()).isEqualTo(Style.FontStyle.NORMAL.getCssName());
    assertThat(style.getFontWeight()).isEqualTo(Style.FontWeight.BOLD.getCssName());
    assertThat(style.getHeight()).isEqualTo("3.1pc");
    assertThat(style.getLeft()).isEqualTo("40in");
    assertThat(style.getListStyleType()).isEqualTo(ListStyleType.CIRCLE.getCssName());
    assertThat(style.getMargin()).isEqualTo("30.5%");
    assertThat(style.getMarginBottom()).isEqualTo("29pt");
    assertThat(style.getMarginLeft()).isEqualTo("47ex");
    assertThat(style.getMarginRight()).isEqualTo("3mm");
    assertThat(style.getMarginTop()).isEqualTo("10.3cm");
    assertThat(style.getOverflow()).isEqualTo(Overflow.SCROLL.getCssName());
    assertThat(style.getPadding()).isEqualTo("10px");
    assertThat(style.getPaddingBottom()).isEqualTo("11px");
    assertThat(style.getPaddingLeft()).isEqualTo("12px");
    assertThat(style.getPaddingRight()).isEqualTo("13px");
    assertThat(style.getPaddingTop()).isEqualTo("14px");
    assertThat(style.getPosition()).isEqualTo(Position.RELATIVE.getCssName());
    assertThat(style.getProperty("string")).isEqualTo("stringvalue");
    assertThat(style.getProperty("doubleUnit")).isEqualTo("17.2cm");
    assertThat(style.getRight()).isEqualTo("13.4cm");
    assertThat(style.getTextDecoration()).isEqualTo(TextDecoration.OVERLINE.getCssName());
    assertThat(style.getTop()).isEqualTo("7.77pc");
    assertThat(style.getVerticalAlign()).isEqualTo(VerticalAlign.MIDDLE.getCssName());
    assertThat(style.getVisibility()).isEqualTo(Visibility.VISIBLE.getCssName());
    assertThat(style.getWidth()).isEqualTo("3.5px");
    assertThat(style.getZIndex()).isEqualTo("1000");
    // When2
    style.clearBackgroundColor();
    style.clearBackgroundImage();
    style.clearBorderColor();
    style.clearBorderWidth();
    style.clearBottom();
    style.clearColor();
    style.clearCursor();
    style.clearDisplay();
    style.clearFloat();
    style.clearFontSize();
    style.clearFontStyle();
    style.clearFontWeight();
    style.clearHeight();
    style.clearLeft();
    style.clearListStyleType();
    style.clearMargin();
    style.clearMarginBottom();
    style.clearMarginLeft();
    style.clearMarginRight();
    style.clearMarginTop();
    style.clearOverflow();
    style.clearPadding();
    style.clearPaddingBottom();
    style.clearPaddingLeft();
    style.clearPaddingRight();
    style.clearPaddingTop();
    style.clearPosition();
    style.clearProperty("string");
    style.clearProperty("doubleUnit");
    style.clearRight();
    style.clearTextDecoration();
    style.clearTop();
    style.clearVisibility();
    style.clearWidth();
    style.clearZIndex();
    // Then 2
    // the only style we didn't remove in the test
    assertThat(button.getElement().getAttribute("style")).isEqualTo("vertical-align: middle; ");
    assertThat(style.getBackgroundColor()).isEqualTo("");
    assertThat(style.getBackgroundImage()).isEqualTo("");
    assertThat(style.getBorderColor()).isEqualTo("");
    assertThat(style.getBorderWidth()).isEqualTo("");
    assertThat(style.getBottom()).isEqualTo("");
    assertThat(style.getColor()).isEqualTo("");
    assertThat(style.getCursor()).isEqualTo("");
    assertThat(style.getDisplay()).isEqualTo("");
    assertThat(style.getFontSize()).isEqualTo("");
    assertThat(style.getFontStyle()).isEqualTo("");
    assertThat(style.getFontWeight()).isEqualTo("");
    assertThat(style.getHeight()).isEqualTo("");
    assertThat(style.getLeft()).isEqualTo("");
    assertThat(style.getListStyleType()).isEqualTo("");
    assertThat(style.getMargin()).isEqualTo("");
    assertThat(style.getMarginBottom()).isEqualTo("");
    assertThat(style.getMarginLeft()).isEqualTo("");
    assertThat(style.getMarginRight()).isEqualTo("");
    assertThat(style.getMarginTop()).isEqualTo("");
    assertThat(style.getOverflow()).isEqualTo("");
    assertThat(style.getPadding()).isEqualTo("");
    assertThat(style.getPaddingBottom()).isEqualTo("");
    assertThat(style.getPaddingLeft()).isEqualTo("");
    assertThat(style.getPaddingRight()).isEqualTo("");
    assertThat(style.getPaddingTop()).isEqualTo("");
    assertThat(style.getPosition()).isEqualTo("");
    assertThat(style.getProperty("string")).isEqualTo("");
    assertThat(style.getProperty("doubleUnit")).isEqualTo("");
    assertThat(style.getRight()).isEqualTo("");
    assertThat(style.getTextDecoration()).isEqualTo("");
    assertThat(style.getTop()).isEqualTo("");
    assertThat(style.getVisibility()).isEqualTo("");
    assertThat(style.getWidth()).isEqualTo("");
    assertThat(style.getZIndex()).isEqualTo("");
}
Also used : Button(com.google.gwt.user.client.ui.Button) Style(com.google.gwt.dom.client.Style) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

Example 27 with Style

use of com.google.gwt.dom.client.Style in project gwt-test-utils by gwt-test-utils.

the class StyleTest method style_empty.

@Test
public void style_empty() {
    // Given
    Button button = new Button();
    Style style = button.getElement().getStyle();
    // When
    assertThat(style.getBackgroundColor()).isEqualTo("");
    assertThat(style.getBackgroundImage()).isEqualTo("");
    assertThat(style.getBorderColor()).isEqualTo("");
    assertThat(style.getBorderWidth()).isEqualTo("");
    assertThat(style.getBottom()).isEqualTo("");
    assertThat(style.getColor()).isEqualTo("");
    assertThat(style.getCursor()).isEqualTo("");
    assertThat(style.getDisplay()).isEqualTo("");
    assertThat(style.getFontSize()).isEqualTo("");
    assertThat(style.getFontStyle()).isEqualTo("");
    assertThat(style.getFontWeight()).isEqualTo("");
    assertThat(style.getHeight()).isEqualTo("");
    assertThat(style.getLeft()).isEqualTo("");
    assertThat(style.getListStyleType()).isEqualTo("");
    assertThat(style.getMargin()).isEqualTo("");
    assertThat(style.getMarginBottom()).isEqualTo("");
    assertThat(style.getMarginLeft()).isEqualTo("");
    assertThat(style.getMarginRight()).isEqualTo("");
    assertThat(style.getMarginTop()).isEqualTo("");
    assertThat(style.getOpacity()).isEqualTo("");
    assertThat(style.getOverflow()).isEqualTo("");
    assertThat(style.getPadding()).isEqualTo("");
    assertThat(style.getPaddingBottom()).isEqualTo("");
    assertThat(style.getPaddingLeft()).isEqualTo("");
    assertThat(style.getPaddingRight()).isEqualTo("");
    assertThat(style.getPaddingTop()).isEqualTo("");
    assertThat(style.getPosition()).isEqualTo("");
    assertThat(style.getProperty("empty")).isEqualTo("");
    assertThat(style.getRight()).isEqualTo("");
    assertThat(style.getTextDecoration()).isEqualTo("");
    assertThat(style.getTop()).isEqualTo("");
    assertThat(style.getVerticalAlign()).isEqualTo("");
    assertThat(style.getVisibility()).isEqualTo("");
    assertThat(style.getWidth()).isEqualTo("");
    assertThat(style.getZIndex()).isEqualTo("");
}
Also used : Button(com.google.gwt.user.client.ui.Button) Style(com.google.gwt.dom.client.Style) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

Example 28 with Style

use of com.google.gwt.dom.client.Style in project gwt-test-utils by gwt-test-utils.

the class StyleTest method checkFloat.

@Test
public void checkFloat() {
    // Given
    Button button = new Button();
    Style style = button.getElement().getStyle();
    // When 1
    style.setFloat(Style.Float.RIGHT);
    // Then 1
    assertThat(style.getProperty("float")).isEqualTo(Style.Float.RIGHT.getCssName());
    assertThat(button.getElement().getAttribute("style")).isEqualTo("float: right; ");
    // When 2
    style.clearFloat();
    // Then 2
    assertThat(style.getProperty("float")).isEqualTo("");
    assertThat(button.getElement().getAttribute("style")).isEqualTo("");
}
Also used : Button(com.google.gwt.user.client.ui.Button) Style(com.google.gwt.dom.client.Style) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

Example 29 with Style

use of com.google.gwt.dom.client.Style in project libgdx by libgdx.

the class GwtApplication method getPreloaderCallback.

public PreloaderCallback getPreloaderCallback() {
    final Panel preloaderPanel = new VerticalPanel();
    preloaderPanel.setStyleName("gdx-preloader");
    final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
    logo.setStyleName("logo");
    preloaderPanel.add(logo);
    final Panel meterPanel = new SimplePanel();
    meterPanel.setStyleName("gdx-meter");
    meterPanel.addStyleName("red");
    final InlineHTML meter = new InlineHTML();
    final Style meterStyle = meter.getElement().getStyle();
    meterStyle.setWidth(0, Unit.PCT);
    meterPanel.add(meter);
    preloaderPanel.add(meterPanel);
    getRootPanel().add(preloaderPanel);
    return new PreloaderCallback() {

        @Override
        public void error(String file) {
            System.out.println("error: " + file);
        }

        @Override
        public void update(PreloaderState state) {
            meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
        }
    };
}
Also used : PreloaderCallback(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Panel(com.google.gwt.user.client.ui.Panel) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) RootPanel(com.google.gwt.user.client.ui.RootPanel) PreloaderState(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) InlineHTML(com.google.gwt.user.client.ui.InlineHTML) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) Style(com.google.gwt.dom.client.Style) Image(com.google.gwt.user.client.ui.Image)

Example 30 with Style

use of com.google.gwt.dom.client.Style in project rstudio by rstudio.

the class ShadowBorder method addPanel.

private DivElement addPanel(String styleName, int halign, int valign) {
    DivElement div = Document.get().createDivElement();
    div.setClassName(styleName);
    Style style = div.getStyle();
    style.setPosition(Style.Position.ABSOLUTE);
    switch(halign) {
        case LEFT:
            style.setPropertyPx("left", 0);
            style.setPropertyPx("width", 10);
            break;
        case CENTER:
            style.setPropertyPx("left", 10);
            style.setPropertyPx("right", 10);
            break;
        case RIGHT:
            style.setPropertyPx("right", 0);
            style.setPropertyPx("width", 10);
            break;
    }
    switch(valign) {
        case TOP:
            style.setPropertyPx("top", 0);
            style.setPropertyPx("height", 26);
            break;
        case MIDDLE:
            style.setPropertyPx("top", 26);
            style.setPropertyPx("bottom", 26);
            break;
        case BOTTOM:
            style.setPropertyPx("bottom", 0);
            style.setPropertyPx("height", 26);
    }
    layout_.getElement().appendChild(div);
    return div;
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) Style(com.google.gwt.dom.client.Style)

Aggregations

Style (com.google.gwt.dom.client.Style)46 Test (org.junit.Test)6 Element (com.google.gwt.dom.client.Element)5 Button (com.google.gwt.user.client.ui.Button)4 Image (com.google.gwt.user.client.ui.Image)4 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)4 ImageElementEx (org.rstudio.core.client.dom.ImageElementEx)3 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Command (com.google.gwt.user.client.Command)2 Element (com.google.gwt.user.client.Element)2 Timer (com.google.gwt.user.client.Timer)2 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 HTMLPanel (com.google.gwt.user.client.ui.HTMLPanel)2 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 MultiLineLabel (org.rstudio.core.client.widget.MultiLineLabel)2 MessageDialogImages (org.rstudio.core.client.widget.images.MessageDialogImages)2 PreloaderCallback (com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback)1