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

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

Introduction

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

Prototype

public void clearOutlineStyle() 

Source Link

Usage

From source file:jetbrains.jetpad.projectional.view.toGwt.BaseViewMapper.java

License:Apache License

@Override
protected void registerSynchronizers(SynchronizersConfiguration conf) {
    super.registerSynchronizers(conf);

    Style targetStyle = getTarget().getStyle();

    if (!isDomPosition()) {
        targetStyle.setPosition(Style.Position.ABSOLUTE);
    } else {//  w  w  w  . j  av  a  2 s.  c om
        targetStyle.setPosition(Style.Position.RELATIVE);
    }

    if (!isDomPosition() || !isDomLayout()) {
        final ReadableProperty<Rectangle> positionInParent;
        if (getParent() instanceof BaseViewMapper) {
            final BaseViewMapper<?, ?> parent = (BaseViewMapper<?, ?>) getParent();
            positionInParent = new DerivedProperty<Rectangle>(getSource().bounds(),
                    parent.getSource().bounds()) {
                @Override
                public Rectangle doGet() {
                    Rectangle sourceBounds = getSource().bounds().get();
                    Rectangle parentSourceBounds = parent.getSource().bounds().get();
                    return sourceBounds.sub(parentSourceBounds.origin);
                }
            };
        } else {
            positionInParent = getSource().bounds();
        }

        final Value<Boolean> valid = new Value<>(false);

        conf.add(Synchronizers.forEventSource(EventSources.composite(positionInParent, getSource().border()),
                new Runnable() {
                    @Override
                    public void run() {
                        valid.set(false);
                        whenValid(new Runnable() {
                            @Override
                            public void run() {
                                if (valid.get())
                                    return;
                                final Rectangle value = positionInParent.get();
                                Style style = getTarget().getStyle();

                                if (!isDomPosition()) {
                                    style.setLeft(value.origin.x, Style.Unit.PX);
                                    style.setTop(value.origin.y, Style.Unit.PX);
                                }

                                if (!isDomLayout()) {
                                    int width = value.dimension.x;
                                    int height = value.dimension.y;

                                    style.setWidth(width, Style.Unit.PX);
                                    style.setHeight(height, Style.Unit.PX);
                                }
                                valid.set(true);
                            }
                        });
                    }
                }));
    }

    if (!isCustomBackgroundSync()) {
        conf.add(Synchronizers.forPropsOneWay(getSource().background(), new WritableProperty<Color>() {
            @Override
            public void set(Color value) {
                Style style = getTarget().getStyle();
                if (value == null) {
                    style.setBackgroundColor(null);
                } else {
                    style.setBackgroundColor(value.toCssColor());
                }
            }
        }));
    }

    conf.add(Synchronizers.forPropsOneWay(getSource().border(), new WritableProperty<Color>() {
        @Override
        public void set(Color value) {
            Style style = getTarget().getStyle();
            if (value != null) {
                style.setOutlineColor(value.toCssColor());
                style.setOutlineWidth(1, Style.Unit.PX);
                style.setOutlineStyle(Style.OutlineStyle.SOLID);
            } else {
                style.clearOutlineStyle();
                style.clearOutlineColor();
                style.clearBorderWidth();
            }
        }
    }));

    conf.add(Synchronizers.forPropsOneWay(getSource().visible(), new WritableProperty<Boolean>() {
        @Override
        public void set(final Boolean value) {
            whenValid(new Runnable() {
                @Override
                public void run() {
                    getTarget().getStyle().setDisplay(value ? Style.Display.BLOCK : Style.Display.NONE);
                }
            });
        }
    }));

    conf.add(Synchronizers.forPropsOneWay(getSource().hasShadow(), new WritableProperty<Boolean>() {
        @Override
        public void set(Boolean value) {
            if (value) {
                getTarget().getStyle().setProperty("boxShadow", "2px 2px 4px black");
            } else {
                getTarget().getStyle().setProperty("boxShadow", null);
            }
        }
    }));
}