Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 represented
        tokenImage - the image that represents the object
        Throws:
        java.lang.NullPointerException - if the image is null
      • 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 represented
        tokenImage - the image that represents the object
        handleOffsetX - the x-coordinate of the handle, relative to the upper-left corner of the image
        handleOffsetY - the y-coordinate of the handle, relative to the upper-left corner of the image
        Throws:
        java.lang.NullPointerException - if the image is null
    • 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 class java.lang.Object
        Returns:
        a debugging string for the token