Example usage for com.vaadin.server Sizeable UNITS_PIXELS

List of usage examples for com.vaadin.server Sizeable UNITS_PIXELS

Introduction

In this page you can find the example usage for com.vaadin.server Sizeable UNITS_PIXELS.

Prototype

Unit UNITS_PIXELS

To view the source code for com.vaadin.server Sizeable UNITS_PIXELS.

Click Source Link

Usage

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler.java

License:Apache License

/**
 * Handles a drop by a component which has an absolute layout as parent. In
 * this case the component is moved./*w w w  .  ja  va  2 s .c o  m*/
 * 
 * @param event
 *            The drag and drop event
 */
protected void handleDropFromAbsoluteParentLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    TargetDetails details = event.getTargetDetails();
    MouseEventDetails mouseDown = transferable.getMouseDownEvent();
    MouseEventDetails mouseUp = MouseEventDetails
            .deSerialize((String) details.getData(Constants.DROP_DETAIL_MOUSE_EVENT));
    int movex = mouseUp.getClientX() - mouseDown.getClientX();
    int movey = mouseUp.getClientY() - mouseDown.getClientY();
    Component comp = transferable.getComponent();

    DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
    ComponentPosition position = parent.getPosition(comp);

    if (position.getLeftValue() != null) {
        float x = position.getLeftValue() + movex;
        position.setLeft(x, Sizeable.UNITS_PIXELS);
    }

    if (position.getRightValue() != null) {
        float x = position.getRightValue() - movex;
        position.setRight(x, Sizeable.UNITS_PIXELS);
    }

    if (position.getTopValue() != null) {
        float y = position.getTopValue() + movey;
        position.setTop(y, Sizeable.UNITS_PIXELS);
    }

    if (position.getBottomValue() != null) {
        float y = position.getBottomValue() - movey;
        position.setBottom(y, Sizeable.UNITS_PIXELS);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAbsoluteLayoutDropHandler.java

License:Apache License

/**
 * Called when a component changed location within the layout
 * //from  ww w  .ja  va 2 s.  c o  m
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();

    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    ComponentPosition position = layout.getPosition(component);

    position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
    position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultGridLayoutDropHandler.java

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    Component comp = transferable.getComponent();

    if (comp == layout) {
        // Dropping myself on myself, if parent is absolute layout then
        // move/*from ww w.  j  a  v a 2s.  c  o m*/
        if (comp.getParent() instanceof DDAbsoluteLayout) {
            MouseEventDetails mouseDown = transferable.getMouseDownEvent();
            MouseEventDetails mouseUp = details.getMouseEvent();
            int movex = mouseUp.getClientX() - mouseDown.getClientX();
            int movey = mouseUp.getClientY() - mouseDown.getClientY();

            DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
            ComponentPosition position = parent.getPosition(comp);

            float x = position.getLeftValue() + movex;
            float y = position.getTopValue() + movey;
            position.setLeft(x, Sizeable.UNITS_PIXELS);
            position.setTop(y, Sizeable.UNITS_PIXELS);

            return;
        }

    } else {

        // Check that we are not dragging an outer layout into an inner
        // layout
        Component parent = layout.getParent();
        while (parent != null) {
            if (parent == comp) {
                return;
            }
            parent = parent.getParent();
        }

        // Detach from old source
        if (source instanceof ComponentContainer) {
            ((ComponentContainer) source).removeComponent(comp);
        } else if (source instanceof SingleComponentContainer) {
            ((SingleComponentContainer) source).setContent(null);
        }
    }

    int row = details.getOverRow();
    int column = details.getOverColumn();
    addComponent(event, comp, column, row);
}