Example usage for com.google.gwt.dom.client Element getOffsetTop

List of usage examples for com.google.gwt.dom.client Element getOffsetTop

Introduction

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

Prototype

@Override
    public int getOffsetTop() 

Source Link

Usage

From source file:com.alkacon.acacia.client.AttributeHandler.java

License:Open Source License

/**
 * Moves the reference value down in the value list.<p>
 * /*from  www  .j  a  va2 s. c om*/
 * @param reference the reference value
 */
public void moveAttributeValueDown(final AttributeValueView reference) {

    final int index = reference.getValueIndex();
    if (index >= (m_entity.getAttribute(m_attributeName).getValueCount() - 1)) {
        return;
    }
    reference.hideAllButtons();
    Element parent = reference.getElement().getParentElement();
    parent.getStyle().setPosition(Position.RELATIVE);
    final Element placeHolder = reference.getPlaceholder(null);
    int top = reference.getElement().getOffsetTop();
    int left = reference.getElement().getOffsetLeft();
    int width = reference.getOffsetWidth();
    reference.getElement().getStyle().setPosition(Position.ABSOLUTE);
    reference.getElement().getStyle().setZIndex(5);
    parent.insertAfter(placeHolder, reference.getElement().getNextSibling());
    reference.getElement().getStyle().setTop(top, Unit.PX);
    reference.getElement().getStyle().setLeft(left, Unit.PX);
    reference.getElement().getStyle().setWidth(width, Unit.PX);
    new MoveAnimation(reference.getElement(), top, left, placeHolder.getOffsetTop(), left, new Command() {

        public void execute() {

            clearMoveAnimationStyles(placeHolder, reference);
            moveAttributeValue(reference, index, index + 1);

        }
    }).run(200);
    UndoRedoHandler handler = UndoRedoHandler.getInstance();
    if (handler.isIntitalized()) {
        handler.addChange(m_entity.getId(), m_attributeName, 0, ChangeType.sort);
    }
}

From source file:com.alkacon.acacia.client.AttributeHandler.java

License:Open Source License

/**
 * Moves the reference value up in the value list.<p>
 * //from  www.  j  ava2s. co m
 * @param reference the reference value
 */
public void moveAttributeValueUp(final AttributeValueView reference) {

    final int index = reference.getValueIndex();
    if (index == 0) {
        return;
    }
    reference.hideAllButtons();
    Element parent = reference.getElement().getParentElement();
    parent.getStyle().setPosition(Position.RELATIVE);
    final Element placeHolder = reference.getPlaceholder(null);
    int top = reference.getElement().getOffsetTop();
    int left = reference.getElement().getOffsetLeft();
    int width = reference.getOffsetWidth();
    reference.getElement().getStyle().setPosition(Position.ABSOLUTE);
    reference.getElement().getStyle().setZIndex(5);
    parent.insertBefore(placeHolder, reference.getElement().getPreviousSibling());
    reference.getElement().getStyle().setTop(top, Unit.PX);
    reference.getElement().getStyle().setLeft(left, Unit.PX);
    reference.getElement().getStyle().setWidth(width, Unit.PX);
    new MoveAnimation(reference.getElement(), top, left, placeHolder.getOffsetTop(), left, new Command() {

        public void execute() {

            clearMoveAnimationStyles(placeHolder, reference);
            moveAttributeValue(reference, index, index - 1);

        }
    }).run(200);
    UndoRedoHandler handler = UndoRedoHandler.getInstance();
    if (handler.isIntitalized()) {
        handler.addChange(m_entity.getId(), m_attributeName, 0, ChangeType.sort);
    }
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Ensures that the given element is visible.<p>
 * //from  w ww. ja v  a 2s.co  m
 * Assuming the scrollbars are on the container element, and that the element is a child of the container element.<p>
 * 
 * @param containerElement the container element, has to be parent of the element
 * @param element the element to be seen
 * @param animationTime the animation time for scrolling, use zero for no animation
 */
public static void ensureVisible(final Element containerElement, Element element, int animationTime) {

    Element item = element;
    int realOffset = 0;
    while ((item != null) && (item != containerElement)) {
        realOffset += element.getOffsetTop();
        item = item.getOffsetParent();
    }
    final int endScrollTop = realOffset - (containerElement.getOffsetHeight() / 2);

    if (animationTime <= 0) {
        // no animation
        containerElement.setScrollTop(endScrollTop);
        return;
    }
    final int startScrollTop = containerElement.getScrollTop();
    (new Animation() {

        /**
         * @see com.google.gwt.animation.client.Animation#onUpdate(double)
         */
        @Override
        protected void onUpdate(double progress) {

            containerElement.setScrollTop(startScrollTop + (int) ((endScrollTop - startScrollTop) * progress));
        }
    }).run(animationTime);
}

From source file:com.ephesoft.gxt.core.client.ui.widget.DetailGrid.java

License:Open Source License

private void setEditing() {
    editingGrid = new GridInlineEditing<DetailsDTO>(this) {

        @SuppressWarnings("rawtypes")
        @Override//from www.j  a  v a 2 s  .co m
        protected <N, O> void doStartEditing(final com.sencha.gxt.widget.core.client.grid.Grid.GridCell cell) {
            super.doStartEditing(cell);
            final ColumnModel<DetailsDTO> columnModel = cm;
            setEditorDimension(cell, columnModel);
        }

        private void setEditorDimension(final com.sencha.gxt.widget.core.client.grid.Grid.GridCell cell,
                final ColumnModel<DetailsDTO> columnModel) {
            if (null != columnModel) {
                final ColumnConfig<DetailsDTO, ?> columnConfig = columnModel.getColumn(cell.getCol());
                if (null != columnConfig) {
                    final IsField editor = getEditor(columnConfig);
                    final Element cellElement = getView().getCell(cell.getRow(), cell.getCol());
                    if (editor instanceof Component) {
                        final Component field = (Component) editor;
                        final int client_y = cellElement.getOffsetTop();
                        final int client_x = cellElement.getOffsetLeft();
                        final int margin = Math.abs(cellElement.getAbsoluteLeft() - client_x) / 2;
                        final int width = cellElement.getAbsoluteRight() - client_x - margin;
                        field.setWidth(250);
                        field.setPosition(client_x, client_y);
                    }
                }
            }
        }

    };
}

From source file:com.ephesoft.gxt.core.client.ui.widget.Grid.java

License:Open Source License

private GridInlineEditing<T> getGridEditing() {
    return new GridInlineEditing<T>(this) {

        @Override//w  w w .  ja v  a 2s .c  o  m
        protected <N, O> void doStartEditing(com.sencha.gxt.widget.core.client.grid.Grid.GridCell cell) {
            super.doStartEditing(cell);
            ColumnModel<T> columnModel = getColumnModel();
            if (null != columnModel) {
                ColumnConfig<T, ?> columnConfig = columnModel.getColumn(cell.getCol());
                if (null != columnConfig) {
                    IsField<T> editor = getEditor(columnConfig);
                    Element cellElement = Grid.this.getView().getCell(cell.getRow(), cell.getCol());
                    if (editor instanceof Field) {
                        Field<T> field = (Field<T>) editor;
                        Widget editorWidget = editor.asWidget();
                        int client_y = cellElement.getOffsetTop();
                        int client_x = cellElement.getOffsetLeft();
                        int width = cellElement.getAbsoluteRight() - cellElement.getAbsoluteLeft();
                        int height = cellElement.getAbsoluteBottom() - cellElement.getAbsoluteTop() + 3;
                        field.setPixelSize(width, height);
                        editorWidget.getElement().getStyle().setTop(client_y, Unit.PX);
                        editorWidget.getElement().getStyle().setLeft(client_x, Unit.PX);
                    }
                }
            }
        }
    };
}

From source file:com.ephesoft.gxt.rv.client.widget.DataTableGrid.java

License:Open Source License

private void setEditable() {
    editingGrid = new GridInlineEditing<Row>(this) {

        @Override//from   w ww.j a v  a2 s  .  co  m
        protected <N, O> void doStartEditing(final com.sencha.gxt.widget.core.client.grid.Grid.GridCell cell) {
            super.doStartEditing(cell);
            final ColumnModel<Row> columnModel = getColumnModel();
            if (null != columnModel) {
                final ColumnConfig<Row, ?> columnConfig = columnModel.getColumn(cell.getCol());
                if (null != columnConfig) {
                    final IsField editor = getEditor(columnConfig);
                    final Element cellElement = DataTableGrid.this.getView().getCell(cell.getRow(),
                            cell.getCol());
                    if (editor instanceof Field) {
                        final Field field = (Field) editor;
                        final int client_y = cellElement.getOffsetTop();
                        final int client_x = cellElement.getOffsetLeft();
                        final int margin = Math.abs(cellElement.getAbsoluteLeft() - client_x) / 2;
                        final int width = cellElement.getAbsoluteRight() - client_x - margin;
                        field.setWidth(width);
                        field.setPosition(client_x, client_y);
                        if (field instanceof ColumnSuggestionBox) {
                            ColumnSuggestionBox columnSuggestionBox = (ColumnSuggestionBox) field;
                            addAlternateValue(columnSuggestionBox, cell);
                        }
                    }
                }
            }
        }
    };
    this.setEditors();
}

From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java

License:sencha.com license

/**
 * Ensured the current row and column is visible.
 * /*from www.jav a 2  s .  com*/
 * @param row the row index
 * @param col the column index
 * @param hscroll true to scroll horizontally if needed
 * @return the calculated point
 */
public Point ensureVisible(int row, int col, boolean hscroll) {
    if (grid == null || !grid.isViewReady() || row < 0 || row > ds.getCount()) {
        return null;
    }

    if (col == -1) {
        col = 0;
    }

    Element rowEl = getRow(row);
    Element cellEl = null;
    if (!(!hscroll && col == 0)) {
        while (cm.isHidden(col)) {
            col++;
        }
        cellEl = getCell(row, col);

    }

    if (rowEl == null) {
        return null;
    }

    Element c = scroller.dom;

    int ctop = 0;
    Element p = rowEl, stope = el.dom;
    while (p != null && p != stope) {
        ctop += p.getOffsetTop();
        p = p.getOffsetParent().cast();
    }
    ctop -= mainHd.dom.getOffsetHeight();

    int cbot = ctop + rowEl.getOffsetHeight();

    int ch = c.getOffsetHeight();
    int stop = c.getScrollTop();
    int sbot = stop + ch;

    if (ctop < stop) {
        c.setScrollTop(ctop);
    } else if (cbot > sbot) {
        if (hscroll && (cm.getTotalWidth() > scroller.getWidth() - scrollOffset)) {
            cbot += scrollOffset;
        }
        c.setScrollTop(cbot -= ch);
    }

    if (hscroll && cellEl != null) {
        int cleft = cellEl.getOffsetLeft();
        int cright = cleft + cellEl.getOffsetWidth();
        int sleft = c.getScrollLeft();
        int sright = sleft + c.getOffsetWidth();
        if (cleft < sleft) {
            c.setScrollLeft(cleft);
        } else if (cright > sright) {
            c.setScrollLeft(cright - scroller.getStyleWidth());
        }
    }

    return cellEl != null ? fly(cellEl).getXY() : new Point(c.getScrollLeft(), fly(rowEl).getY());
}

From source file:com.fullmetalgalaxy.client.game.board.WgtBoardBase.java

License:Open Source License

@Override
public void onTouchEnd(TouchEndEvent p_event) {
    if (!m_hasTouchMoved) {
        p_event.preventDefault();/* ww  w  .  j a  v a  2  s.com*/
        Touch touch = p_event.getChangedTouches().get(0);
        Element current = getElement();
        Element parent = current.getParentElement();
        int x = touch.getPageX() - current.getOffsetLeft() - parent.getOffsetLeft();
        int y = touch.getPageY() - current.getOffsetTop() - parent.getOffsetTop();
        onUp(UserAction.Touch, x, y);
    }
}

From source file:com.google.speedtracer.client.visualizations.view.EventWaterfallRowDetails.java

License:Apache License

private Tree createEventTrace(Container parent, final int pieChartHeight) {
    Widget header = new Widget(parent.getDocument().createHElement(2), parent) {
    };/*w ww. j  av a2s  .c om*/
    header.setStyleName(getCss().eventBreakdownHeader());
    header.getElement().setInnerText("Event Trace");

    final LazyEventTree tree = new LazyEventTree(parent, eventWaterfall.getPresenter(),
            getParentRow().getEvent(), getParentRow().getEventBreakdown(), resources);

    // Hook listeners to tree list to monitor selection changes and
    // expansion changes.
    tree.addSelectionChangeListener(new SelectionChangeListener() {
        Element offsetParent = getParentRow().getElement();

        public void onSelectionChange(ArrayList<Item> selected) {
            // Wipe the old table
            detailsTable.destroy();

            // Sort the nodes by start time.
            Collections.sort(selected, new Comparator<Item>() {

                public int compare(Item node1, Item node2) {
                    UiEvent e1 = (UiEvent) node1.getItemTarget();
                    UiEvent e2 = (UiEvent) node2.getItemTarget();

                    return Double.compare(e1.getTime(), e2.getTime());
                }
            });

            Item newSelection = selected.get(selected.size() - 1);
            // Find how far to move table down to current selection.
            // We have to recursively walk up to compute the correct offset top.
            // We will encounter the UI padding two extra times along the way
            // crossing the tree boundary and crossing the details div boundary,
            // totally 3 encounters with padding we have to account for.
            int minTableOffset = Math.max(pieChartHeight,
                    recursiveGetOffsetTop(newSelection.getElement()) - (3 * getCss().uiPadding()));

            if (selected.size() == 1) {
                // We have a single selection. Simply display the details for the
                // single node.
                detailsTable = createDetailsTable(detailsTableContainer, minTableOffset,
                        (UiEvent) newSelection.getItemTarget());

            } else {
                // Display aggregate information over the range of nodes.
                detailsTable = createMultiNodeDetailsTable(detailsTableContainer, minTableOffset, selected);
            }

            fixHeightOfParentRow();
        }

        private int recursiveGetOffsetTop(Element node) {
            if (node == null || node.getOffsetParent() == null || node.equals(offsetParent)) {
                return 0;
            } else {
                return node.getOffsetTop() + recursiveGetOffsetTop(node.getOffsetParent());
            }
        }

    });

    tree.addExpansionChangeListener(new ExpansionChangeListener() {

        public void onExpansionChange(Item changedItem) {
            fixHeightOfParentRow();
        }

    });

    // We make sure to have the tree cleaned up when we clean up ourselves.
    manageEventListener(tree.getRemover());

    return tree;
}

From source file:com.preferanser.client.application.layout.PanelLayout.java

License:Open Source License

protected void positionWidget(CardWidget cardWidget, int x, int y, int z) {
    Element element = cardWidget.getElement();
    int currentX = element.getOffsetLeft();
    int currentY = element.getOffsetTop();
    element.getStyle().setZIndex(z);/*w  ww  . j ava  2  s.  c  om*/
    if (currentX != x || currentY != y) {
        CardAnimation animation = new CardAnimation(element);
        animation.moveTo(x, y, ANIMATION_DURATION_MILLIS);
    }
}