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

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

Introduction

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

Prototype

public void setPosition(Position value) 

Source Link

Usage

From source file:jetbrains.jetpad.event.dom.ClipboardSupport.java

License:Apache License

private TextArea createClipboardTextArea() {
    final TextArea pasteArea = new TextArea();
    pasteArea.setPixelSize(0, 0);/* w  w  w.  j  a  va2  s .c o  m*/
    Style style = pasteArea.getElement().getStyle();
    style.setPosition(Style.Position.FIXED);
    RootPanel.get().add(pasteArea);
    pasteArea.setFocus(true);
    return pasteArea;
}

From source file:jetbrains.jetpad.projectional.domUtil.DomTextEditor.java

License:Apache License

public DomTextEditor(Element root) {
    myRoot = root;/*from  w ww. j ava 2s. c  o m*/

    Style rootStyle = myRoot.getStyle();
    rootStyle.setPosition(Style.Position.RELATIVE);

    myTextContainer = DOM.createSpan();
    Style textStyle = myTextContainer.getStyle();
    textStyle.setZIndex(2);
    textStyle.setWhiteSpace(Style.WhiteSpace.NOWRAP);
    myRoot.appendChild(myTextContainer);

    Element caretDiv = DOM.createDiv();
    Style caretStyle = caretDiv.getStyle();
    caretStyle.setPosition(Style.Position.ABSOLUTE);
    caretStyle.setZIndex(2);
    myRoot.appendChild(caretDiv);
    myCaretDiv = caretDiv;

    Element selectionDiv = DOM.createDiv();
    Style selectionStyle = selectionDiv.getStyle();
    selectionStyle.setPosition(Style.Position.ABSOLUTE);
    selectionStyle.setZIndex(1);
    myRoot.appendChild(selectionDiv);
    mySelectionDiv = selectionDiv;

    update();
    updateCaretVisibility();
    updateSelectionVisibility();
    updateCaretAndSelection();
}

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  2s .  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);
            }
        }
    }));
}

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

License:Apache License

@Override
protected void registerSynchronizers(SynchronizersConfiguration conf) {
    final DomTextEditor editor = new DomTextEditor(getTarget());
    Style style = getTarget().getStyle();
    style.setPosition(Style.Position.ABSOLUTE);
    style.setDisplay(Style.Display.BLOCK);

    super.registerSynchronizers(conf);

    conf.add(Synchronizers.forPropsOneWay(getSource().selectionVisible(), new WritableProperty<Boolean>() {
        @Override/*from  w w w .j  ava  2  s .  c  om*/
        public void set(Boolean value) {
            editor.setSelectionVisible(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().selectionStart(), new WritableProperty<Integer>() {
        @Override
        public void set(Integer value) {
            editor.setSelectionStart(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().text(), new WritableProperty<String>() {
        @Override
        public void set(String value) {
            editor.setText(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().textColor(), new WritableProperty<Color>() {
        @Override
        public void set(Color value) {
            editor.setTextColor(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().caretVisible(), new WritableProperty<Boolean>() {
        @Override
        public void set(Boolean value) {
            editor.setCaretVisible(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().caretPosition(), new WritableProperty<Integer>() {
        @Override
        public void set(Integer value) {
            editor.setCaretPosition(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().bold(), new WritableProperty<Boolean>() {
        @Override
        public void set(Boolean value) {
            editor.setBold(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().italic(), new WritableProperty<Boolean>() {
        @Override
        public void set(Boolean value) {
            editor.setItalic(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().fontFamily(), new WritableProperty<FontFamily>() {
        @Override
        public void set(FontFamily value) {
            editor.setFontFamily(value);
        }
    }));
    conf.add(Synchronizers.forPropsOneWay(getSource().fontSize(), new WritableProperty<Integer>() {
        @Override
        public void set(Integer value) {
            editor.setFontSize(value);
        }
    }));
}

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

License:Apache License

public ViewContainerToElementMapper(ViewContainer source, Element target, final boolean eventsDisabled) {
    super(source, target);

    myCtx = new ViewToDomContext() {
        @Override//from  w w w.j ava  2s  .  com
        public ReadableProperty<Rectangle> visibleArea() {
            return myVisibleArea;
        }

        @Override
        public MapperFactory<View, Element> getFactory() {
            return ViewMapperFactory.factory(this);
        }

        @Override
        public Boolean areEventsDisabled() {
            return eventsDisabled;
        }
    };

    disablePopup(myRootDiv);
    target.appendChild(myRootDiv);
    myRootDiv.setTabIndex(0);

    final Style rootDivStyle = myRootDiv.getStyle();
    rootDivStyle.setPosition(Style.Position.RELATIVE);
    rootDivStyle.setPadding(0, Style.Unit.PX);
    rootDivStyle.setOverflow(Style.Overflow.VISIBLE);
    rootDivStyle.setOutlineStyle(Style.OutlineStyle.NONE);
}

From source file:mx.org.pescadormvp.core.client.internallinks.InternalCheckableItemLink.java

License:Open Source License

public InternalCheckableItemLink() {
    initWidget(uiBinder.createAndBindUi(this));

    // some style elements are set programatically here:
    Style itemContainerStyle = itemContainer.getStyle();
    itemContainerStyle.setPosition(Position.RELATIVE);
    itemContainerStyle.setPadding(ITEM_CONTAINER_PADDING, Unit.PX);

    Style textAreaStyle = textArea.getStyle();
    textAreaStyle.setPosition(Position.ABSOLUTE);
    textAreaStyle.setLeft(itemResources.checkmarkImage().getWidth() + (IMAGE_PADDING * 2), Unit.PX);

    setImageStyle();/*from   w w  w  .  ja  va2 s .com*/

    completeSetup();
}

From source file:mx.org.pescadormvp.core.client.internallinks.InternalCheckableItemLink.java

License:Open Source License

private void setImageStyle() {
    Style imageStyle = image.getElement().getStyle();
    imageStyle.setPosition(Position.ABSOLUTE);
    imageStyle.setPadding(IMAGE_PADDING, Unit.PX);
}

From source file:next.i.controller.Utils.java

License:Apache License

static void fillParent(Element elem) {
    Style style = elem.getStyle();
    style.setPosition(Position.ABSOLUTE);
    style.setLeft(0, PX);//from  w ww.j  a v a 2s .  com
    style.setTop(0, PX);
    style.setRight(0, PX);
    style.setBottom(0, PX);
    style.setWidth(100, Unit.PCT);
    style.setHeight(100, Unit.PCT);
}

From source file:org.anstis.client.grid.widget.dom.BaseDOMElement.java

License:Apache License

public BaseDOMElement(final GridLayer gridLayer, final BaseGridWidget<?, ?> gridWidget,
        final IDOMElementFactory<T, ?> factory, final AbsolutePanel domElementContainer) {
    this.gridLayer = gridLayer;
    this.gridWidget = gridWidget;
    this.factory = factory;
    this.domElementContainer = domElementContainer;

    final Style style = container.getElement().getStyle();
    style.setPosition(Style.Position.ABSOLUTE);

    //MouseEvents over absolutely positioned elements do not bubble through the DOM.
    //Consequentially Event Handlers on GridLayer do not receive notification of MouseMove
    //Events used during column resizing. Therefore we manually bubble events to GridLayer.
    container.addDomHandler(new MouseDownHandler() {
        @Override//w ww  . j  av  a2  s  . com
        public void onMouseDown(final MouseDownEvent event) {
            gridLayer.onNodeMouseDown(new NodeMouseDownEvent(event) {

                @Override
                public int getX() {
                    //Adjust the x-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getX() + container.getElement().getOffsetLeft();
                }

                @Override
                public int getY() {
                    //Adjust the y-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getY() + container.getElement().getOffsetTop();
                }

            });
        }
    }, MouseDownEvent.getType());
    container.addDomHandler(new MouseMoveHandler() {
        @Override
        public void onMouseMove(final MouseMoveEvent event) {
            //The DOM Element changes the Cursor, so set to the state determined by the MouseEvent Handlers on GridLayer
            style.setCursor(gridLayer.getGridWidgetHandlersState().getCursor());

            gridLayer.onNodeMouseMove(new NodeMouseMoveEvent(event) {

                @Override
                public int getX() {
                    //Adjust the x-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getX() + container.getElement().getOffsetLeft();
                }

                @Override
                public int getY() {
                    //Adjust the y-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getY() + container.getElement().getOffsetTop();
                }

            });
        }
    }, MouseMoveEvent.getType());
    container.addDomHandler(new MouseUpHandler() {
        @Override
        public void onMouseUp(final MouseUpEvent event) {
            gridLayer.onNodeMouseUp(new NodeMouseUpEvent(event) {

                @Override
                public int getX() {
                    //Adjust the x-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getX() + container.getElement().getOffsetLeft();
                }

                @Override
                public int getY() {
                    //Adjust the y-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getY() + container.getElement().getOffsetTop();
                }

            });
        }
    }, MouseUpEvent.getType());
    container.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            gridWidget.onNodeMouseClick(new NodeMouseClickEvent(event) {

                @Override
                public int getX() {
                    //Adjust the x-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getX() + container.getElement().getOffsetLeft();
                }

                @Override
                public int getY() {
                    //Adjust the y-coordinate (relative to the DOM Element) to be relative to the GridCanvas.
                    return super.getY() + container.getElement().getOffsetTop();
                }

            });
        }
    }, ClickEvent.getType());
}

From source file:org.anstis.client.grid.widget.dom.BaseDOMElement.java

License:Apache License

/**
 * Attach the DOMElement to the GWT container, if not already attached.
 *//* ww w .  j a  va  2 s  .  com*/
public void attach() {
    final Iterator<Widget> itr = domElementContainer.iterator();
    while (itr.hasNext()) {
        if (itr.next().equals(container)) {
            return;
        }
    }
    //When an Element is detached it's Position configuration is cleared, so reset it
    final Style style = container.getElement().getStyle();
    style.setPosition(Style.Position.ABSOLUTE);

    domElementContainer.add(container);
}