DESY ACOP Beans Home

com.cosylab.gui.components.util
Class CosyTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by com.cosylab.gui.components.util.CosyTransferHandler
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.awt.event.MouseMotionListener, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
AbstractDisplayerParametersTransferHandler, DisplayerParametersTransferHandler

public abstract class CosyTransferHandler
extends javax.swing.TransferHandler
implements java.awt.event.MouseMotionListener, java.awt.datatransfer.Transferable

CosyTransferHandler is a common TransferHandler for cosy displyers.

Author:
Jaka Bobnar, Cosylab
See Also:
Serialized Form

Nested Class Summary
static interface CosyTransferHandler.MouseFilter
          MouseFilter can notify if certain MouseEvent can trigger the DnD event.
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
 
Field Summary
protected  boolean isDragging
           
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
CosyTransferHandler(boolean receiveEnabled, boolean exportEnabled)
          Creates new instance of CosyTransferHandler.
 
Method Summary
 void addMouseFilter(CosyTransferHandler.MouseFilter f)
          Adds a mouse filter to this handler.
protected  boolean canDrag(javax.swing.JComponent comp)
          Return true if this component can start drag gesture for provided component.
 boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] transferFlavors)
           
protected  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
          Yop may override this method to implement own transferable or override just methods, which are perscribed by transferable.
protected  void exportDone(javax.swing.JComponent source, java.awt.datatransfer.Transferable data, int action)
           
 CosyTransferHandler.MouseFilter[] getMouseFilters()
          Returns all mouse filters assigned to this handler
 int getSourceActions(javax.swing.JComponent c)
           
abstract  java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
           
abstract  java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 void hookTransferHandler(javax.swing.JComponent comp)
          Hooks transfer handler to the given component, using the exising import/export enables flags.
 void hookTransferHandler(javax.swing.JComponent comp, boolean canReceive, boolean canExport)
          Hooks transfer handler to the given component.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
           
 boolean isExportEnabled()
          Returns true if drag is enabled.
protected  boolean isMouseDragGesture(java.awt.event.MouseEvent e)
           
 boolean isReceiveEnabled()
          Returns true if drop is enabled.
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
static void registerTransferHandler(javax.swing.JComponent parent, javax.swing.TransferHandler newT, javax.swing.JComponent... comps)
           
 void removeMouseFilter(CosyTransferHandler.MouseFilter f)
          Removes a mouse filter from this handler.
 void setExportEnabled(boolean exportEnabled, javax.swing.JComponent comp)
          Enables/disables the drag.
 void setReceiveEnabled(boolean receiveEnabled, javax.swing.JComponent comp)
          Enables/disables the drop on the given component
 void unhookTransferHandler(javax.swing.JComponent comp)
          Unhook transfer handler from the given component.
 
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation, importData, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isDragging

protected boolean isDragging
Constructor Detail

CosyTransferHandler

public CosyTransferHandler(boolean receiveEnabled,
                           boolean exportEnabled)
Creates new instance of CosyTransferHandler.

Parameters:
property -
reciveEnabled -
exportEnabled -
Method Detail

registerTransferHandler

public static final void registerTransferHandler(javax.swing.JComponent parent,
                                                 javax.swing.TransferHandler newT,
                                                 javax.swing.JComponent... comps)

hookTransferHandler

public void hookTransferHandler(javax.swing.JComponent comp)
Hooks transfer handler to the given component, using the exising import/export enables flags.

Parameters:
comp -

unhookTransferHandler

public void unhookTransferHandler(javax.swing.JComponent comp)
Unhook transfer handler from the given component.

Parameters:
comp -

hookTransferHandler

public void hookTransferHandler(javax.swing.JComponent comp,
                                boolean canReceive,
                                boolean canExport)
Hooks transfer handler to the given component. TransferHandler will handler only the specified action.

Parameters:
comp - component to hook
canReceive - true if drop should be enabled
canExport - true if drag should be enabled

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
Yop may override this method to implement own transferable or override just methods, which are perscribed by transferable.

Overrides:
createTransferable in class javax.swing.TransferHandler

getTransferData

public abstract java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                          throws java.awt.datatransfer.UnsupportedFlavorException,
                                                 java.io.IOException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

getTransferDataFlavors

public abstract java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

canImport

public boolean canImport(javax.swing.JComponent comp,
                         java.awt.datatransfer.DataFlavor[] transferFlavors)
Overrides:
canImport in class javax.swing.TransferHandler

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
Overrides:
getSourceActions in class javax.swing.TransferHandler

isMouseDragGesture

protected boolean isMouseDragGesture(java.awt.event.MouseEvent e)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

exportDone

protected void exportDone(javax.swing.JComponent source,
                          java.awt.datatransfer.Transferable data,
                          int action)
Overrides:
exportDone in class javax.swing.TransferHandler

canDrag

protected boolean canDrag(javax.swing.JComponent comp)
Return true if this component can start drag gesture for provided component. Default value is same as dragEnabled;

Parameters:
comp -
Returns:
true if this component can start drag gesture

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

isExportEnabled

public boolean isExportEnabled()
Returns true if drag is enabled.

Returns:
the exportEnabled.

isReceiveEnabled

public boolean isReceiveEnabled()
Returns true if drop is enabled.

Returns:
the reciveEnabled.

setExportEnabled

public void setExportEnabled(boolean exportEnabled,
                             javax.swing.JComponent comp)
Enables/disables the drag.

Parameters:
exportEnabled - true if drag is enabled
comp - component on which the drag should be enabled/disabled

setReceiveEnabled

public void setReceiveEnabled(boolean receiveEnabled,
                              javax.swing.JComponent comp)
Enables/disables the drop on the given component

Parameters:
reciveEnabled - true if drop should be enabled
comp - component on which the drop should be enabled/disabled

addMouseFilter

public void addMouseFilter(CosyTransferHandler.MouseFilter f)
Adds a mouse filter to this handler.

Parameters:
f -

removeMouseFilter

public void removeMouseFilter(CosyTransferHandler.MouseFilter f)
Removes a mouse filter from this handler.

Parameters:
f -

getMouseFilters

public CosyTransferHandler.MouseFilter[] getMouseFilters()
Returns all mouse filters assigned to this handler

Returns:


Copyright © 2010. All Rights Reserved.