Package ca.cgjennings.ui.dnd
Class DragToken<T>
- java.lang.Object
-
- ca.cgjennings.ui.dnd.DragToken<T>
-
public class DragToken<T> extends java.lang.Object
A drag token combines an object with a visual representation which can be dragged around the display by the user. It is part of a simple framework for creating drag-and-drop interfaces that bypasses AWT/Swing drag-and-drop, and thus is more consistent across platforms.- Since:
- 3.0
- Author:
- Chris Jennings
- See Also:
DragManager
-
-
Constructor Summary
Constructors Constructor Description DragToken(T tokenObject, java.awt.Image tokenImage)
Creates a new token that represents the specified object with the given image.DragToken(T tokenObject, java.awt.Image tokenImage, int handleOffsetX, int handleOffsetY)
Creates a new token that represents the specified object with the given image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getHandleOffsetX()
Returns the X coordinate of the image at which the cursor should be attached while dragging.int
getHandleOffsetY()
Returns the Y coordinate of the image at which the cursor should be attached while dragging.java.awt.image.BufferedImage
getImage()
Returns the token image.T
getObject()
Returns the token object.java.lang.String
toString()
Returns a string string description of the token.
-
-
-
Constructor Detail
-
DragToken
public DragToken(T tokenObject, java.awt.Image tokenImage)
Creates a new token that represents the specified object with the given image. The token's handle (the point by which it is dragged; typically, the point at which the cursor attaches to the image) will be located at the center of the image.- Parameters:
tokenObject
- the object to be representedtokenImage
- the image that represents the object- Throws:
java.lang.NullPointerException
- if the image isnull
-
DragToken
public DragToken(T tokenObject, java.awt.Image tokenImage, int handleOffsetX, int handleOffsetY)
Creates a new token that represents the specified object with the given image. The token's handle (the point by which it is dragged; typically, the point at which the cursor attaches to the image) will be located at the specified offset.- Parameters:
tokenObject
- the object to be representedtokenImage
- the image that represents the objecthandleOffsetX
- the x-coordinate of the handle, relative to the upper-left corner of the imagehandleOffsetY
- the y-coordinate of the handle, relative to the upper-left corner of the image- Throws:
java.lang.NullPointerException
- if the image isnull
-
-
Method Detail
-
getObject
public T getObject()
Returns the token object.- Returns:
- the object whose representation is being dragged
-
getImage
public java.awt.image.BufferedImage getImage()
Returns the token image. This may return a different image from the one used to create the token.- Returns:
- the image used to represent the dragged object
-
getHandleOffsetX
public int getHandleOffsetX()
Returns the X coordinate of the image at which the cursor should be attached while dragging.- Returns:
- the X-coordinate of the handle, relative to the upper-left corner of the image
-
getHandleOffsetY
public int getHandleOffsetY()
Returns the Y coordinate of the image at which the cursor should be attached while dragging.- Returns:
- the Y-coordinate of the handle, relative to the upper-left corner of the image
-
toString
public java.lang.String toString()
Returns a string string description of the token. The description will include the string value of the represented object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a debugging string for the token
-
-