Search in sources :

Example 1 with ComponentPosition

use of com.vaadin.ui.AbsoluteLayout.ComponentPosition in project ANNIS by korpling.

the class TigerQueryBuilderCanvas method updateLinesAndEdgePositions.

public void updateLinesAndEdgePositions() {
    canvas.getLines().clear();
    for (EdgeWindow e : edges) {
        GripDragComponent w1 = nodes.get(e.getSource());
        GripDragComponent w2 = nodes.get(e.getTarget());
        ComponentPosition p1 = area.getPosition(w1);
        ComponentPosition p2 = area.getPosition(w2);
        float x1 = p1.getLeftValue() + (w1.getWidth() / 2);
        float y1 = p1.getTopValue() + (w1.getHeight() / 2);
        float x2 = p2.getLeftValue() + (w2.getWidth() / 2);
        float y2 = p2.getTopValue() + (w2.getHeight() / 2);
        float v_x = x2 - x1;
        float v_y = y2 - y1;
        // add line
        canvas.getLines().add(new Line2D.Float(x1, y1, x2, y2));
        // set position on half of the line for the edge window
        ComponentPosition posEdge = area.getPosition(e);
        float vectorLength = (float) Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
        float xM = x1 + (vectorLength / 2.0f) * ((x2 - x1) / vectorLength);
        float yM = y1 + (vectorLength / 2.0f) * ((y2 - y1) / vectorLength);
        double normV_x = v_x / vectorLength;
        double normV_y = v_y / vectorLength;
        double pos1_x = (2.1 * vectorLength / 3) * normV_x + x1;
        double pos1_y = (2.1 * vectorLength / 3) * normV_y + y1;
        double origDir = Math.atan2(normV_y, normV_x);
        double pos2_x = ((1 * vectorLength) / 3) * normV_x + x1;
        double pos2_y = ((1 * vectorLength) / 3) * normV_y + y1;
        canvas.getLines().addAll(createArrow(pos1_x, pos1_y, origDir, 20.0));
        canvas.getLines().addAll(createArrow(pos2_x, pos2_y, origDir, 20.0));
        posEdge.setLeftValue(xM - e.getWidth() / 2.0f);
        posEdge.setTopValue(yM - e.getHeight() / 2.0f);
    }
    canvas.markAsDirty();
}
Also used : GripDragComponent(annis.gui.widgets.GripDragComponent) ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) Line2D(java.awt.geom.Line2D)

Example 2 with ComponentPosition

use of com.vaadin.ui.AbsoluteLayout.ComponentPosition in project cuba by cuba-platform.

the class AbstractDefaultLayoutDropHandler method handleDropFromAbsoluteParentLayout.

/**
 * Handles a drop by a component which has an absolute layout as parent. In
 * this case the component is moved.
 *
 * @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);
    }
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) MouseEventDetails(com.vaadin.shared.MouseEventDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) TargetDetails(com.vaadin.event.dd.TargetDetails) Component(com.vaadin.ui.Component)

Example 3 with ComponentPosition

use of com.vaadin.ui.AbsoluteLayout.ComponentPosition in project cuba by cuba-platform.

the class DefaultAbsoluteLayoutDropHandler method handleComponentReordering.

/**
 * Called when a component changed location within the layout
 *
 * @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);
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) AbsoluteLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) Component(com.vaadin.ui.Component)

Example 4 with ComponentPosition

use of com.vaadin.ui.AbsoluteLayout.ComponentPosition in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler method handleDropFromLayout.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
     * #handleDropFromLayout(com.vaadin.event.dd.DragAndDropEvent)
     */
@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) {
        // move
        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);
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) DDGridLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout) MouseEventDetails(com.vaadin.shared.MouseEventDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails) Component(com.vaadin.ui.Component)

Aggregations

ComponentPosition (com.vaadin.ui.AbsoluteLayout.ComponentPosition)4 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)3 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)3 Component (com.vaadin.ui.Component)3 MouseEventDetails (com.vaadin.shared.MouseEventDetails)2 GripDragComponent (annis.gui.widgets.GripDragComponent)1 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)1 GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)1 AbsoluteLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails)1 TargetDetails (com.vaadin.event.dd.TargetDetails)1 ComponentContainer (com.vaadin.ui.ComponentContainer)1 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)1 Line2D (java.awt.geom.Line2D)1