org.vectomatic.dnd
Class DataTransferExt

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by com.google.gwt.dom.client.DataTransfer
          extended by org.vectomatic.dnd.DataTransferExt

public class DataTransferExt
extends com.google.gwt.dom.client.DataTransfer

Class to augment the DataTransfer provided by GWT with the methods it needs to support drag and drop of files. On browsers which support file drag and drop, DataTransfer objects can simply be cast to this class.

Author:
laaglu

Constructor Summary
protected DataTransferExt()
          Constructor
 
Method Summary
 void addElement(com.google.gwt.user.client.ui.UIObject uiObject)
          Set the drag source.
 java.lang.String getDropEffect()
          The actual effect that will be used, and should always be one of the possible values of effectAllowed.
 java.lang.String getEffectAllowed()
          Returns the effect allowed for this drag.
 FileList getFiles()
          Returns a list of all the local files available on the data transfer.
 StringList getTypes()
          Returns a list of the format types of the data that is stored for the first item, in the same order the data was added.
 void setDragImage(com.google.gwt.user.client.ui.Image image, int x, int y)
          Set the image to be used for dragging if a custom one is desired.
 void setDropEffect(java.lang.String dropEffect)
          Sets the actual effect that will be used, and should always be one of the possible values of effectAllowed.
 void setEffectAllowed(java.lang.String effectAllowed)
           Specifies the effects that are allowed for this drag.
 
Methods inherited from class com.google.gwt.dom.client.DataTransfer
clearData, clearData, getData, setData, setDragImage
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createFunction, createObject, equals, hashCode, toSource, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataTransferExt

protected DataTransferExt()
Constructor

Method Detail

getDropEffect

public final java.lang.String getDropEffect()

The actual effect that will be used, and should always be one of the possible values of effectAllowed.

For the dragenter and dragover events, the dropEffect will be initialized based on what action the user is requesting. How this is determined is platform specific, but typically the user can press modifier keys to adjust which action is desired. Within an event handler for the dragenter and dragover events, the dropEffect should be modified if the action the user is requesting is not the one that is desired.

For dragstart, drag, and dragleave events, the dropEffect is initialized to "none". Any value assigned to the dropEffect will be set, but the value isn't used for anything.

For the drop and dragend events, the dropEffect will be initialized to the action that was desired, which will be the value that the dropEffect had after the last dragenter or dragover event.

Possible values:

copy:
A copy of the source item is made at the new location.
move:
An item is moved to a new location.
link:
A link is established to the source at the new location.
none:
The item may not be dropped.

Assigning any other value has no effect and retains the old value.

Returns:
The drop effect.

setDropEffect

public final void setDropEffect(java.lang.String dropEffect)

Sets the actual effect that will be used, and should always be one of the possible values of effectAllowed.

Parameters:
dropEffect - The drop effect.

getEffectAllowed

public final java.lang.String getEffectAllowed()
Returns the effect allowed for this drag.

Returns:
the effect allowed for this drag.

setEffectAllowed

public final void setEffectAllowed(java.lang.String effectAllowed)

Specifies the effects that are allowed for this drag. You may set this in the dragstart event to set the desired effects for the source, and within the dragenter and dragover events to set the desired effects for the target. The value is not used for other events.

Possible values:

copy:
A copy of the source item may be made at the new location.
move:
An item may be moved to a new location.
link:
A link may be established to the source at the new location.
copyLink:
A copy or link operation is permitted.
copyMove:
A copy or move operation is permitted.
linkMove:
A link or move operation is permitted.
all:
All operations are permitted.
none:
the item may not be dropped.
uninitialized:
the default value when the effect has not been set, equivalent to all.

Assigning any other value has no effect and retains the old value.

Parameters:
effectAllowed - the effect for this drag

getFiles

public final FileList getFiles()
Returns a list of all the local files available on the data transfer. If the drag operation doesn't involve dragging files, this property is an empty list. An invalid index access on the FileList specified by this property will return null.

Returns:
a list of all the local files available on the data transfer.

getTypes

public final StringList getTypes()
Returns a list of the format types of the data that is stored for the first item, in the same order the data was added. An empty list will be returned if no data was added.

Returns:
a list of the format types of the data that is stored for the first item, in the same order the data was added.

setDragImage

public final void setDragImage(com.google.gwt.user.client.ui.Image image,
                               int x,
                               int y)

Set the image to be used for dragging if a custom one is desired. Most of the time, this would not be set, as a default image is created from the node that was dragged.

If the node is an HTML img element, an HTML canvas element or a XUL image element, the image data is used. Otherwise, image should be a visible node and the drag image will be created from this. If image is null, any custom drag image is cleared and the default is used instead.

The coordinates specify the offset into the image where the mouse cursor should be. To center the image, for instance, use values that are half the width and height of the image.

Parameters:
image - An element to use as the drag feedback image.
x - Horizontal offset within the image.
y - Vertical offset within the image.

addElement

public final void addElement(com.google.gwt.user.client.ui.UIObject uiObject)
Set the drag source. Usually you would not change this, but it will affect which node the drag and dragend events are fired at. The default target is the node that was dragged.

Parameters:
uiObject - The element to add.


Copyright © 2011. All Rights Reserved.