@Override public TargetDetails convertTargetDetails(com.vaadin.event.dd.TargetDetails targetDetails) { AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) targetDetails; Map<String, Object> dataDetails = new HashMap<>(); dataDetails.put(Constants.DROP_DETAIL_ABSOLUTE_TOP, details.getAbsoluteTop()); dataDetails.put(Constants.DROP_DETAIL_MOUSE_EVENT, details.getData(Constants.DROP_DETAIL_MOUSE_EVENT)); dataDetails.put(Constants.DROP_DETAIL_RELATIVE_LEFT, details.getRelativeLeft()); dataDetails.put(Constants.DROP_DETAIL_RELATIVE_TOP, details.getRelativeTop()); dataDetails.put(Constants.DROP_DETAIL_COMPONENT_HEIGHT, details.getComponentHeight()); dataDetails.put(Constants.DROP_DETAIL_ABSOLUTE_LEFT, details.getAbsoluteLeft()); dataDetails.put(Constants.DROP_DETAIL_COMPONENT_WIDTH, details.getComponentWidth()); return new DDAbsoluteLayoutTargetDetails(this, dataDetails); }
/** * {@inheritDoc} */ public TargetDetails translateDropTargetDetails( Map<String, Object> clientVariables) { return new AbsoluteLayoutTargetDetails(this, clientVariables); }
@Override protected void handleHTML5Drop(DragAndDropEvent event) { AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event .getTargetDetails(); DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget(); int leftPixelPosition = details.getRelativeLeft(); int topPixelPosition = details.getRelativeTop(); layout.addComponent(resolveComponentFromHTML5Drop(event), "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px"); }
/** * The relative left coordinate in pixels measured from the containers left * edge * * @return The amount of pixels from the left edge */ public int getRelativeLeft() { return Integer.valueOf( getData(Constants.DROP_DETAIL_RELATIVE_LEFT).toString()); }
/** * 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); }
/** * The height of the dragged component measured in pixels * * @return The height in pixels */ public int getComponentWidth() { return Integer.valueOf( getData(Constants.DROP_DETAIL_COMPONENT_WIDTH).toString()); }
Component component = transferable.getComponent(); Component source = event.getTransferable().getSourceComponent(); DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget(); int leftPixelPosition = details.getRelativeLeft(); int topPixelPosition = details.getRelativeTop();
/** * The absolute left coordinate in pixels measured from the windows left * edge * * @return The amount of pixels from the left edge */ public int getAbsoluteLeft() { return Integer.valueOf( getData(Constants.DROP_DETAIL_ABSOLUTE_LEFT).toString()); }
/** * The relative top coordinate in pixels measured from the containers top * edge * * @return The amount of pixels from the top edge */ public int getRelativeTop() { return Integer.valueOf( getData(Constants.DROP_DETAIL_RELATIVE_TOP).toString()); }
/** * The width of the dragged component measured in pixels * * @return The width in pixels */ public int getComponentHeight() { return Integer.valueOf( getData(Constants.DROP_DETAIL_COMPONENT_HEIGHT).toString()); }
/** * The absolute top coordinate in pixels measured from the windows top edge * * @return The amount of pixels from the top edge */ public int getAbsoluteTop() { return Integer.valueOf( getData(Constants.DROP_DETAIL_ABSOLUTE_TOP).toString()); }
/** * Some details about the mouse event * * @return details about the actual event that caused the event details. * Practically mouse move or mouse up. */ public MouseEventDetails getMouseEvent() { return MouseEventDetails.deSerialize( (String) getData(Constants.DROP_DETAIL_MOUSE_EVENT)); } }