public class Draggable extends Object implements DragStartEvent.HasDragStartHandlers, DragEndEvent.HasDragEndHandlers, DragMoveEvent.HasDragMoveHandlers, DragCancelEvent.HasDragCancelHandlers, DragHandler.HasDragHandlers
Adds drag behavior to any widget. Drag operations can be initiated from the widget itself, or another widget, such as the header in a dialog.
It is possible to specify event targets that will be ignored. If the target
element has the CommonStyles.Styles.nodrag()
style (as returned by
CommonStyles.get()
) it will not trigger a drag operation.
Modifier and Type | Class and Description |
---|---|
static interface |
Draggable.DraggableAppearance |
Modifier and Type | Field and Description |
---|---|
protected int |
conHeight |
protected int |
conWidth |
protected int |
conX |
protected int |
conY |
protected DragGestureRecognizer |
dragGestureRecognizer |
protected int |
dragStartX |
protected int |
dragStartY |
protected int |
lastX |
protected int |
lastY |
protected XElement |
proxyEl |
protected Rectangle |
startBounds |
Constructor and Description |
---|
Draggable(Widget dragWidget)
Creates a new draggable instance.
|
Draggable(Widget dragWidget,
Draggable.DraggableAppearance appearance)
Creates a new draggable instance.
|
Draggable(Widget dragWidget,
Widget handleWidget)
Create a new draggable instance.
|
Draggable(Widget dragWidget,
Widget handleWidget,
Draggable.DraggableAppearance appearance)
Create a new draggable instance.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addDragCancelHandler(DragCancelEvent.DragCancelHandler handler)
Adds a
DragCancelEvent.DragCancelHandler handler for DragCancelEvent events. |
HandlerRegistration |
addDragEndHandler(DragEndEvent.DragEndHandler handler)
Adds a
DragEndEvent.DragEndHandler handler for DragEndEvent events. |
HandlerRegistration |
addDragHandler(DragHandler handler)
Adds a
DragHandler handler for DragStartEvent ,
DragEndEvent , DragCancelEvent , DragMoveEvent
events. |
HandlerRegistration |
addDragMoveHandler(DragMoveEvent.DragMoveHandler handler)
Adds a
DragMoveEvent.DragMoveHandler handler for DragMoveEvent
events. |
HandlerRegistration |
addDragStartHandler(DragStartEvent.DragStartHandler handler)
Adds a
DragStartEvent.DragStartHandler handler for DragStartEvent events. |
protected void |
afterDrag() |
void |
cancelDrag()
Cancels the drag if running.
|
protected XElement |
createProxy() |
Widget |
getContainer()
Returns the drag container.
|
protected DragGestureRecognizer |
getDragGestureRecognizer()
Crates the drag gesture recognizer and passes along the touch events to Draggable.
|
Widget |
getDragHandle()
Returns the drag handleWidget.
|
Widget |
getDragWidget()
Returns the widget being dragged.
|
int |
getStartDragDistance()
Returns the number of pixels the cursor must move before dragging begins.
|
protected void |
handleMove(int x,
int y,
Event event) |
protected void |
handleStart(int x,
int y,
Event event,
Element target) |
boolean |
isConstrainClient()
Returns true if drag is constrained to the viewport.
|
boolean |
isConstrainHorizontal()
Returns true if horizontal movement is constrained.
|
boolean |
isConstrainVertical()
Returns true if vertical movement is constrained.
|
boolean |
isDragging()
Returns
true if a drag is in progress. |
boolean |
isEnabled()
Returns
true if enabled. |
boolean |
isMoveAfterProxyDrag()
Returns true if the drag widget is moved after a proxy drag.
|
boolean |
isSizeProxyToSource()
Returns true if the proxy element is sized to match the drag widget.
|
boolean |
isUpdateZIndex()
Returns true if the z-index is updated after a drag.
|
boolean |
isUseProxy()
Returns true if proxy element is enabled.
|
protected void |
onMouseDown(MouseDownEvent e) |
protected void |
onMouseMove(Event event) |
protected void |
onTouchEnd(List<TouchData> touches) |
protected void |
onTouchMove(List<TouchData> touches) |
protected boolean |
onTouchStart(TouchData startedTouch) |
void |
release()
Removes the drag handles.
|
void |
setConstrainClient(boolean constrainClient)
True to set constrain movement to the viewport (defaults to true).
|
void |
setConstrainHorizontal(boolean constrainHorizontal)
True to stop horizontal movement (defaults to false).
|
void |
setConstrainVertical(boolean constrainVertical)
True to stop vertical movement (defaults to false).
|
void |
setContainer(Widget container)
Specifies a container to which the drag widget is constrained.
|
void |
setEnabled(boolean enabled)
Enables dragging if the argument is
true , and disables it
otherwise. |
void |
setMoveAfterProxyDrag(boolean moveAfterProxyDrag)
True to move source widget after a proxy drag (defaults to true).
|
void |
setProxy(XElement element)
Sets the proxy element.
|
void |
setProxyStyle(String proxyClass) |
void |
setSizeProxyToSource(boolean sizeProxyToSource)
True to set proxy dimensions the same as the drag widget (defaults to
true).
|
void |
setStartDragDistance(int startDragDistance)
Specifies how far the cursor must move after mousedown to start dragging
(defaults to 2).
|
void |
setUpdateZIndex(boolean updateZIndex)
True if the CSS z-index should be updated on the widget being dragged.
|
void |
setUseProxy(boolean useProxy)
True to use a proxy widget during drag operation (defaults to true).
|
void |
setXConstraint(int left,
int right)
Constrains the horizontal travel.
|
void |
setYConstraint(int top,
int bottom)
Constrains the vertical travel.
|
protected void |
startDrag(Event event) |
protected void |
stopDrag(Event event) |
protected int conX
protected int conY
protected int conWidth
protected int conHeight
protected int dragStartX
protected int dragStartY
protected int lastX
protected int lastY
protected XElement proxyEl
protected Rectangle startBounds
protected DragGestureRecognizer dragGestureRecognizer
public Draggable(Widget dragWidget)
dragWidget
- the widget to be draggedpublic Draggable(Widget dragWidget, Draggable.DraggableAppearance appearance)
dragWidget
- the widget to be draggedappearance
- the appearance with which to render the componentpublic Draggable(Widget dragWidget, Widget handleWidget)
dragWidget
- the widget to be draggedhandleWidget
- the widget drags will be initiated frompublic Draggable(Widget dragWidget, Widget handleWidget, Draggable.DraggableAppearance appearance)
dragWidget
- the widget to be draggedhandleWidget
- the widget drags will be initiated fromappearance
- the appearance with which to render the componentprotected DragGestureRecognizer getDragGestureRecognizer()
protected boolean onTouchStart(TouchData startedTouch)
public HandlerRegistration addDragCancelHandler(DragCancelEvent.DragCancelHandler handler)
DragCancelEvent.HasDragCancelHandlers
DragCancelEvent.DragCancelHandler
handler for DragCancelEvent
events.addDragCancelHandler
in interface DragCancelEvent.HasDragCancelHandlers
handler
- the handlerpublic HandlerRegistration addDragEndHandler(DragEndEvent.DragEndHandler handler)
DragEndEvent.HasDragEndHandlers
DragEndEvent.DragEndHandler
handler for DragEndEvent
events.addDragEndHandler
in interface DragEndEvent.HasDragEndHandlers
handler
- the handlerpublic HandlerRegistration addDragHandler(DragHandler handler)
DragHandler.HasDragHandlers
DragHandler
handler for DragStartEvent
,
DragEndEvent
, DragCancelEvent
, DragMoveEvent
events.addDragHandler
in interface DragHandler.HasDragHandlers
handler
- the handlerpublic HandlerRegistration addDragMoveHandler(DragMoveEvent.DragMoveHandler handler)
DragMoveEvent.HasDragMoveHandlers
DragMoveEvent.DragMoveHandler
handler for DragMoveEvent
events.addDragMoveHandler
in interface DragMoveEvent.HasDragMoveHandlers
handler
- the handlerpublic HandlerRegistration addDragStartHandler(DragStartEvent.DragStartHandler handler)
DragStartEvent.HasDragStartHandlers
DragStartEvent.DragStartHandler
handler for DragStartEvent
events.addDragStartHandler
in interface DragStartEvent.HasDragStartHandlers
handler
- the handlerpublic void cancelDrag()
public Widget getContainer()
public void setContainer(Widget container)
container
- the containerpublic Widget getDragHandle()
public Widget getDragWidget()
public int getStartDragDistance()
public void setStartDragDistance(int startDragDistance)
startDragDistance
- the start distance in pixelspublic boolean isConstrainClient()
public void setConstrainClient(boolean constrainClient)
constrainClient
- true to constrain to viewportpublic boolean isConstrainHorizontal()
public void setConstrainHorizontal(boolean constrainHorizontal)
constrainHorizontal
- true to stop horizontal movementpublic boolean isConstrainVertical()
public void setConstrainVertical(boolean constrainVertical)
constrainVertical
- true to stop vertical movementpublic boolean isDragging()
true
if a drag is in progress.public boolean isEnabled()
true
if enabled.public void setEnabled(boolean enabled)
true
, and disables it
otherwise.enabled
- the new enabled statepublic boolean isMoveAfterProxyDrag()
public void setMoveAfterProxyDrag(boolean moveAfterProxyDrag)
moveAfterProxyDrag
- true to move after a proxy dragpublic boolean isSizeProxyToSource()
public void setSizeProxyToSource(boolean sizeProxyToSource)
sizeProxyToSource
- true to update proxy sizepublic boolean isUpdateZIndex()
public void setUpdateZIndex(boolean updateZIndex)
true
will ensure that the dragged
element is always displayed over all other widgets (defaults to true).updateZIndex
- true update the z-indexpublic boolean isUseProxy()
public void setUseProxy(boolean useProxy)
useProxy
- true use a proxypublic void release()
public void setProxy(XElement element)
element
- the proxy elementpublic void setProxyStyle(String proxyClass)
public void setXConstraint(int left, int right)
left
- the number of pixels the element can move to the leftright
- the number of pixels the element can move to the rightpublic void setYConstraint(int top, int bottom)
top
- the number of pixels the element can move to the upbottom
- the number of pixels the element can move to the downprotected void afterDrag()
protected XElement createProxy()
protected void handleStart(int x, int y, Event event, Element target)
protected void onMouseDown(MouseDownEvent e)
protected void handleMove(int x, int y, Event event)
protected void onMouseMove(Event event)
protected void startDrag(Event event)
protected void stopDrag(Event event)
Copyright © 2018. All rights reserved.