Example usage for com.google.gwt.dom.client Style setMargin

List of usage examples for com.google.gwt.dom.client Style setMargin

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Style setMargin.

Prototype

public void setMargin(double value, Unit unit) 

Source Link

Usage

From source file:co.fxl.gui.gwt.GWTFlowPanel.java

License:Open Source License

@Override
public ILineBreak addLineBreak() {
    final ParagraphElement e = Document.get().createPElement();
    Style style = e.getStyle();
    style.setHeight(0, Unit.PX);/*from  w  ww. ja  v  a  2  s.  c  om*/
    style.setMargin(0, Unit.PX);
    container.widget.getElement().appendChild(e);
    return new ILineBreak() {
        @Override
        public void remove() {
            e.removeFromParent();
        }
    };
}

From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java

License:Apache License

private void initCapturingWidget() {
    capturingWidget = new FocusPanel();
    capturingWidget.addMouseMoveHandler(this);
    capturingWidget.addMouseUpHandler(this);
    capturingWidget.addTouchMoveHandler(this);
    capturingWidget.addTouchEndHandler(this);
    capturingWidget.addTouchCancelHandler(this);
    Style style = capturingWidget.getElement().getStyle();
    // workaround for IE8 opacity http://code.google.com/p/google-web-toolkit/issues/detail?id=5538
    style.setProperty("filter", "alpha(opacity=0)");
    style.setOpacity(0);/*from   w w  w.  j  a v  a2  s .co  m*/
    style.setZIndex(1000);
    style.setMargin(0, Style.Unit.PX);
    style.setBorderStyle(BorderStyle.NONE);
    style.setBackgroundColor("blue");
}

From source file:com.bearsoft.gwt.ui.widgets.DecoratorBox.java

public void setWidget(HasValue<T> w) {
    if (decorated != w) {
        if (changeValueHandler != null) {
            changeValueHandler.removeHandler();
        }//  w  w  w . j  ava2s  .com
        if (keyDownHandler != null)
            keyDownHandler.removeHandler();
        if (keyUpHandler != null)
            keyUpHandler.removeHandler();
        if (keyPressHandler != null)
            keyPressHandler.removeHandler();
        if (focusHandler != null)
            focusHandler.removeHandler();
        if (blurHandler != null)
            blurHandler.removeHandler();
        if (decorated instanceof Widget) {
            ((Widget) decorated).removeFromParent();
        }
        decorated = w;
        if (decorated != null) {
            changeValueHandler = decorated.addValueChangeHandler(new ValueChangeHandler<T>() {

                @Override
                public void onValueChange(ValueChangeEvent<T> event) {
                    fireValueChangeEvent();
                }
            });
            if (decorated instanceof Widget) {
                CommonResources.INSTANCE.commons().ensureInjected();
                ((Widget) decorated).getElement()
                        .addClassName(CommonResources.INSTANCE.commons().borderSized());
                Style style = ((Widget) decorated).getElement().getStyle();
                style.setBorderWidth(0, Style.Unit.PX);
                style.setPadding(0, Style.Unit.PX);
                style.setMargin(0, Style.Unit.PX);
                style.setPosition(Style.Position.ABSOLUTE);
                style.setDisplay(Style.Display.INLINE_BLOCK);
                style.setLeft(0, Style.Unit.PX);
                style.setTop(0, Style.Unit.PX);
                style.setHeight(100, Style.Unit.PCT);
                style.setWidth(100, Style.Unit.PCT);
                style.setOutlineStyle(Style.OutlineStyle.NONE);
                style.setBackgroundColor("inherit");
                style.setColor("inherit");
                contentWrapper.setWidget((Widget) decorated);
            }
            if (decorated instanceof HasKeyDownHandlers) {
                keyDownHandler = ((HasKeyDownHandlers) decorated).addKeyDownHandler(new KeyDownHandler() {

                    @Override
                    public void onKeyDown(KeyDownEvent event) {
                        KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
                    }
                });
            }
            if (decorated instanceof HasKeyUpHandlers) {
                keyUpHandler = ((HasKeyUpHandlers) decorated).addKeyUpHandler(new KeyUpHandler() {

                    @Override
                    public void onKeyUp(KeyUpEvent event) {
                        KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
                    }
                });
            }
            if (decorated instanceof HasKeyPressHandlers) {
                keyPressHandler = ((HasKeyPressHandlers) decorated).addKeyPressHandler(new KeyPressHandler() {

                    @Override
                    public void onKeyPress(KeyPressEvent event) {
                        KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
                    }
                });
            }
            if (decorated instanceof HasFocusHandlers) {
                focusHandler = ((HasFocusHandlers) decorated).addFocusHandler(new FocusHandler() {

                    @Override
                    public void onFocus(FocusEvent event) {
                        DecoratorBox.this.getElement().addClassName(DECORATOR_FOCUSED_CLASS_NAME);
                        FocusEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
                    }

                });
            }
            if (decorated instanceof HasBlurHandlers) {
                blurHandler = ((HasBlurHandlers) decorated).addBlurHandler(new BlurHandler() {

                    @Override
                    public void onBlur(BlurEvent event) {
                        DecoratorBox.this.getElement().removeClassName(DECORATOR_FOCUSED_CLASS_NAME);
                        BlurEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
                    }

                });
            }
        }
    }
}

From source file:com.eas.widgets.boxes.DecoratorBox.java

public DecoratorBox(HasValue<T> aDecorated) {
    super();/*from  ww  w  .j a va 2  s .  c  om*/
    decorated = aDecorated;
    if (decorated instanceof HasValue<?>) {
        decorated.addValueChangeHandler(new ValueChangeHandler<T>() {

            @Override
            public void onValueChange(ValueChangeEvent<T> event) {
                setClearButtonVisible(nullable && event.getValue() != null);
            }
        });
    }
    if (decorated instanceof HasDecorations) {
        HasWidgets container = ((HasDecorations) decorated).getContainer();
        ((Widget) container).addStyleName("decorator");
        container.add(selectButton);
        container.add(clearButton);
        initWidget((Widget) decorated);
    } else {
        CommonResources.INSTANCE.commons().ensureInjected();
        ((Widget) decorated).getElement().addClassName(CommonResources.INSTANCE.commons().borderSized());
        Style style = ((Widget) decorated).getElement().getStyle();
        style.setMargin(0, Style.Unit.PX);
        style.setPosition(Style.Position.ABSOLUTE);
        style.setDisplay(Style.Display.INLINE_BLOCK);
        style.setLeft(0, Style.Unit.PX);
        style.setTop(0, Style.Unit.PX);
        style.setHeight(100, Style.Unit.PCT);
        style.setWidth(100, Style.Unit.PCT);
        style.setOutlineStyle(Style.OutlineStyle.NONE);
        FlowPanel panel = new FlowPanel();
        panel.addStyleName("decorator");
        initWidget(panel);
        panel.add((Widget) decorated);
        panel.add(selectButton);
        panel.add(clearButton);
    }

    ((Widget) decorated).addStyleName("decorator-content");

    selectButton.getElement().addClassName("decorator-select");
    selectButton.getElement().getStyle().setDisplay(Style.Display.NONE);
    selectButton.getElement().getStyle().setHeight(100, Style.Unit.PCT);
    selectButton.getElement().getStyle().setPosition(Style.Position.RELATIVE);
    clearButton.getElement().addClassName("decorator-clear");
    clearButton.getElement().getStyle().setDisplay(Style.Display.NONE);
    clearButton.getElement().getStyle().setHeight(100, Style.Unit.PCT);
    clearButton.getElement().getStyle().setPosition(Style.Position.RELATIVE);

    selectButton.addDomHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            selectValue();
        }
    }, ClickEvent.getType());
    clearButton.addDomHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            clearValue();
            setFocus(true);
        }
    }, ClickEvent.getType());
    organizeButtonsContent();

    getElement().<XElement>cast().addResizingTransitionEnd(this);

    if (decorated instanceof HasValue<?>) {
        changeValueHandler = decorated.addValueChangeHandler(new ValueChangeHandler<T>() {

            @Override
            public void onValueChange(ValueChangeEvent<T> event) {
                fireValueChangeEvent();
            }
        });
    }

    if (decorated instanceof HasKeyDownHandlers) {
        keyDownHandler = ((HasKeyDownHandlers) decorated).addKeyDownHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasKeyUpHandlers) {
        keyUpHandler = ((HasKeyUpHandlers) decorated).addKeyUpHandler(new KeyUpHandler() {

            @Override
            public void onKeyUp(KeyUpEvent event) {
                KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasKeyPressHandlers) {
        keyPressHandler = ((HasKeyPressHandlers) decorated).addKeyPressHandler(new KeyPressHandler() {

            @Override
            public void onKeyPress(KeyPressEvent event) {
                KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasFocusHandlers) {
        focusHandler = ((HasFocusHandlers) decorated).addFocusHandler(new FocusHandler() {

            @Override
            public void onFocus(FocusEvent event) {
                FocusEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }

        });
    }
    if (decorated instanceof HasBlurHandlers) {
        blurHandler = ((HasBlurHandlers) decorated).addBlurHandler(new BlurHandler() {

            @Override
            public void onBlur(BlurEvent event) {
                BlurEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }

        });
    }

}

From source file:com.googlecode.gwtquake.client.GwtQuake.java

License:Open Source License

public void onModuleLoad() {
    // Initialize drivers.
    Document doc = Document.get();
    doc.setTitle("GWT Quake II");
    BodyElement body = doc.getBody();//from w w  w  . j a v a  2  s  .  c om
    Style style = body.getStyle();
    style.setPadding(0, Unit.PX);
    style.setMargin(0, Unit.PX);
    style.setBorderWidth(0, Unit.PX);
    style.setProperty("height", "100%");
    style.setBackgroundColor("#000");
    style.setColor("#888");

    //   Window.alert("UA: " + userAgent+ " type: " + browserType);

    boolean wireframe = ("" + Window.Location.getHash()).indexOf("wireframe") != -1;

    canvas = (CanvasElement) doc.createElement("canvas");
    video = doc.createElement("video");

    w = Window.getClientWidth();
    h = Window.getClientHeight();
    canvas.setWidth(w);
    canvas.setHeight(h);
    style = canvas.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");

    style = video.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");
    style.setProperty("display", "none");

    body.appendChild(canvas);
    body.appendChild(video);

    try {
        Globals.autojoin.value = Window.Location.getHash().indexOf("autojoin") != -1 ? 1.0f : 0.0f;
        final Renderer renderer = wireframe ? new GwtWireframeGLRenderer(canvas)
                : new GwtWebGLRenderer(canvas, video);
        Globals.re = renderer;

        ResourceLoader.impl = new GwtResourceLoaderImpl();
        Compatibility.impl = new CompatibilityImpl();

        Sound.impl = new GwtSound();
        NET.socketFactory = new WebSocketFactoryImpl();
        //      Sys.impl = new Sys.SysImpl() {
        //        public void exit(int status) {
        //          Window.alert("Something's rotten in Denmark");
        //          Window.Location.assign("gameover.html");
        //        }
        //      };

        // Flags.
        QuakeCommon.Init(new String[] { "GQuake" });

        // Enable stdout.
        Globals.nostdout = ConsoleVariables.Get("nostdout", "0", 0);

        Window.addResizeHandler(new ResizeHandler() {

            public void onResize(ResizeEvent event) {
                if (Window.getClientWidth() == w && Window.getClientHeight() == h) {
                    return;
                }

                w = Window.getClientWidth();
                h = Window.getClientHeight();

                renderer.GLimp_SetMode(new Dimension(w, h), 0, false);
            }
        });

        //      QuakeServer.main(new String[0], new DummySNetImpl(), false);

        timer = new Timer() {
            double startTime = Duration.currentTimeMillis();

            @Override
            public void run() {
                try {
                    double curTime = Duration.currentTimeMillis();
                    boolean pumping = ResourceLoader.Pump();
                    if (pumping) {
                        Screen.UpdateScreen2();
                    } else {
                        int dt = (int) (curTime - startTime);
                        GwtKBD.Frame(dt);
                        QuakeCommon.Frame(dt);
                    }
                    startTime = curTime;
                    timer.schedule(ResourceLoader.Pump() ? LOADING_DELAY : INTER_FRAME_DELAY);
                } catch (Exception e) {
                    Compatibility.printStackTrace(e);
                }
            }
        };
        timer.schedule(INTER_FRAME_DELAY);
    } catch (Exception e) {
        Compatibility.printStackTrace(e);
        DivElement div = doc.createDivElement();
        div.setInnerHTML(NO_WEBGL_MESSAGE);
        body.appendChild(div);
    }
}

From source file:com.sciencegadgets.client.algebra.EquationWrapper.java

License:Open Source License

private void fillSelectionDetails() {
    LinkedList<Widget> detailsList = new LinkedList<Widget>();

    TypeSGET type = node.getType();/*from   w ww.  j a  v  a2s.c o  m*/
    TypeSGET operationType = null;
    // FitParentHTML typeLabel = new FitParentHTML(type.getIcon());
    HTML typeLabel = new HTML(type.toString());
    detailsList.add(typeLabel);

    switch (type) {
    case Number:
        String fullValue = node.getAttribute(MathAttribute.Value);
        if ("".equals(fullValue)) {
            fullValue = node.getAttribute(MathAttribute.Randomness);
        } else {
            try {
                new BigDecimal(fullValue);
                // FitParentHTML valueHTML = new
                // FitParentHTML(fullValue);
                final TextBox valueHTML = new TextBox();
                valueHTML.setText(fullValue);
                valueHTML.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        valueHTML.selectAll();
                    }
                });
                valueHTML.addStyleName(CSS.SELECTION_DETAILS_Value);
                valueHTML.getElement().getStyle().setProperty("textShadow", "inherit");
                detailsList.add(valueHTML);
            } catch (NumberFormatException ex) {
            }
        }

        UnitAttribute unit = node.getUnitAttribute();
        if (!"".equals(unit.toString())) {
            HTML unitHTML = new HTML();
            unitHTML.getElement().appendChild(UnitHTML.create(unit, false));
            detailsList.add(unitHTML);
        }

        break;
    case Variable:
        UnitAttribute qKind = node.getUnitAttribute();
        if (!"".equals(qKind.toString())) {
            // FitParentHTML qKindHTML = new FitParentHTML();
            HTML qKindHTML = new HTML();
            qKindHTML.getElement().appendChild(UnitHTML.create(qKind, false));
            detailsList.add(qKindHTML);
        }
        break;
    case Operation:
        operationType = node.getParentType();
        String[] parts = { node.getPrevSibling().getType().toString(), node.getSymbol(),
                node.getNextSibling().getType().toString() };

        typeLabel.setHTML("");
        Element typeEl = typeLabel.getElement();
        for (String part : parts) {
            Element partEl = new HTML(part).getElement();
            Style partSt = partEl.getStyle();
            partSt.setMargin(2, Unit.PX);
            partSt.setDisplay(Display.INLINE_BLOCK);
            partSt.setVerticalAlign(VerticalAlign.MIDDLE);
            typeEl.appendChild(partEl);
        }
    default:
        break;
    }

    FlowPanel detailsPanel = new FlowPanel();
    detailsPanel.addStyleName(CSS.SELECTION_DETAILS);
    for (Widget s : detailsList) {
        detailsPanel.add(s);
    }
    algebraActivity.detailsArea.clear();
    algebraActivity.detailsArea.add(detailsPanel);

    Widget typeParent = typeLabel.getParent();
    if (typeParent != null) {
        // typeParent.addStyleName(type.getCSSClassName());
        // typeParent.addStyleName(CSS.PARENT_WRAPPER);
        if (operationType != null) {
            typeParent.addStyleName(operationType.getCSSClassName());
        }
    }
}

From source file:com.vaadin.client.metadata.ConnectorBundleLoader.java

License:Apache License

private void notice(String productName) {
    if (notice == null) {
        notice = new HTML();
        notice.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                notice.removeFromParent();
            }//from   www  .  ja  v a 2s .  com
        });
        notice.addTouchStartHandler(new TouchStartHandler() {
            public void onTouchStart(TouchStartEvent event) {
                notice.removeFromParent();
            }
        });
    }
    String msg = notice.getText().trim();
    msg += msg.isEmpty() ? "Using Evaluation License of: " : ", ";
    notice.setText(msg + productName);
    RootPanel.get().add(notice);

    notice.getElement().setClassName("");
    Style s = notice.getElement().getStyle();

    s.setPosition(Position.FIXED);
    s.setTextAlign(TextAlign.CENTER);
    s.setRight(0, Unit.PX);
    s.setLeft(0, Unit.PX);
    s.setBottom(0, Unit.PX);
    s.setProperty("padding", "0.5em 1em");

    s.setProperty("font-family", "sans-serif");
    s.setFontSize(12, Unit.PX);
    s.setLineHeight(1.1, Unit.EM);

    s.setColor("white");
    s.setBackgroundColor("black");
    s.setOpacity(0.7);

    s.setZIndex(2147483646);
    s.setProperty("top", "auto");
    s.setProperty("width", "auto");
    s.setDisplay(Display.BLOCK);
    s.setWhiteSpace(WhiteSpace.NORMAL);
    s.setVisibility(Visibility.VISIBLE);
    s.setMargin(0, Unit.PX);
}

From source file:com.vaadin.client.ui.VCustomLayout.java

License:Apache License

public VCustomLayout() {
    setElement(DOM.createDiv());/* w  ww.  j  av a2s  .  co  m*/
    // Clear any unwanted styling
    Style style = getElement().getStyle();
    style.setBorderStyle(BorderStyle.NONE);
    style.setMargin(0, Unit.PX);
    style.setPadding(0, Unit.PX);

    if (BrowserInfo.get().isIE()) {
        style.setPosition(Position.RELATIVE);
    }

    setStyleName(CLASSNAME);
}

From source file:de.bonprix.gridstacklayout.client.GridStackLayoutWidget.java

License:Open Source License

public GridStackLayoutWidget() {
    this.gridstackId = DOM.createUniqueId();

    this.gridstackDiv = DOM.createDiv();
    this.gridstackDiv.addClassName("grid-stack");
    this.gridstackDiv.setId(this.gridstackId);
    setElement(this.gridstackDiv);

    // Clear any unwanted styling
    final Style style = getElement().getStyle();
    style.setBorderStyle(BorderStyle.NONE);
    style.setMargin(0, Unit.PX);
    style.setPadding(0, Unit.PX);/*from ww w.j av a  2s  .c  om*/

    if (BrowserInfo.get().isIE()) {
        style.setPosition(Position.RELATIVE);
    }

    setStyleName(CLASSNAME);

    addAttachHandler(new Handler() {
        @Override
        public void onAttachOrDetach(final AttachEvent event) {
            checkInit();
        }
    });

    setStackedModeWidth(60 * DEFAULT_COLUMNS);
}

From source file:jake2.gwt.client.GwtQuake.java

License:Open Source License

public void onModuleLoad() {
    // Initialize drivers.
    Document doc = Document.get();
    doc.setTitle("GWT Quake II");
    BodyElement body = doc.getBody();//from w  ww .  j  a v  a 2s  .c o  m
    Style style = body.getStyle();
    style.setPadding(0, Unit.PX);
    style.setMargin(0, Unit.PX);
    style.setBorderWidth(0, Unit.PX);
    style.setProperty("height", "100%");
    style.setBackgroundColor("#000");
    style.setColor("#888");

    boolean wireframe = ("" + Window.Location.getHash()).indexOf("wireframe") != -1;

    canvas = (CanvasElement) doc.createElement("canvas");
    video = doc.createElement("video");

    w = Window.getClientWidth();
    h = Window.getClientHeight();
    canvas.setWidth(w);
    canvas.setHeight(h);
    style = canvas.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");

    style = video.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");
    style.setProperty("display", "none");

    body.appendChild(canvas);
    body.appendChild(video);

    try {
        final refexport_t renderer = wireframe ? new GwtWireframeGLRenderer(canvas)
                : new GwtWebGLRenderer(canvas, video);
        Globals.re = renderer;

        ResourceLoader.impl = new GwtResourceLoaderImpl();
        Compatibility.impl = new CompatibilityImpl();

        S.impl = new GwtSound();
        NET.socketFactory = new WebSocketFactoryImpl();
        //      Sys.impl = new Sys.SysImpl() {
        //        public void exit(int status) {
        //          Window.alert("Something's rotten in Denmark");
        //          Window.Location.assign("gameover.html");
        //        }
        //      };

        // Flags.
        Qcommon.Init(new String[] { "GQuake" });

        // Enable stdout.
        Globals.nostdout = Cvar.Get("nostdout", "0", 0);

        Window.addResizeHandler(new ResizeHandler() {

            public void onResize(ResizeEvent event) {
                if (Window.getClientWidth() == w && Window.getClientHeight() == h) {
                    return;
                }

                w = Window.getClientWidth();
                h = Window.getClientHeight();

                renderer.GLimp_SetMode(new Dimension(w, h), 0, false);
            }
        });

        //      QuakeServer.main(new String[0], new DummySNetImpl(), false);

        timer = new Timer() {
            double startTime = Duration.currentTimeMillis();

            @Override
            public void run() {
                try {
                    double curTime = Duration.currentTimeMillis();
                    boolean pumping = ResourceLoader.Pump();
                    if (pumping) {
                        SCR.UpdateScreen2();
                    } else {
                        int dt = (int) (curTime - startTime);
                        GwtKBD.Frame(dt);
                        Qcommon.Frame(dt);
                    }
                    startTime = curTime;
                    timer.schedule(ResourceLoader.Pump() ? LOADING_DELAY : INTER_FRAME_DELAY);
                } catch (Exception e) {
                    Compatibility.printStackTrace(e);
                }
            }
        };
        timer.schedule(INTER_FRAME_DELAY);
    } catch (Exception e) {
        Compatibility.printStackTrace(e);
        body.setInnerHTML(NO_WEBGL_MESSAGE);
    }
}