ch.epfl.craft.magmap
Class MagnetTransferHandler

java.lang.Object
  extended byjavax.swing.TransferHandler
      extended bych.epfl.craft.magmap.MagnetTransferHandler
All Implemented Interfaces:
java.io.Serializable

public class MagnetTransferHandler
extends javax.swing.TransferHandler

Drag & Drop support for magnets. This TransferHandler use the id of the node in the model as identifier. It is then easy to get a reference on the MagnetNode.

Version:
1.0
Author:
Jerome Caffaro
See Also:
Serialized Form

Nested Class Summary
 class MagnetTransferHandler.IndexTransferable
          Custom class that encapsulate a number == index of the magnet in the model.
 
Field Summary
 java.awt.datatransfer.DataFlavor localArrayListFlavor
           
 java.lang.String localArrayListType
           
static java.awt.datatransfer.DataFlavor localIndexFlavor
           
static java.lang.String localIndexType
           
 java.awt.datatransfer.DataFlavor serialArrayListFlavor
           
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
MagnetTransferHandler()
          Creates a new MagnetTransferHandler instance.
 
Method Summary
 boolean canImport(javax.swing.JComponent c, java.awt.datatransfer.DataFlavor[] flavors)
          Returns true if this c can import the kind of flavors, else returns false
protected  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
          Create the instance that will be transeferred to the source from c component.
protected  void exportDone(javax.swing.JComponent c, java.awt.datatransfer.Transferable data, int action)
          Called on the source when the dragged has finished.
 int getSourceActions(javax.swing.JComponent c)
          Returns the kind of action supported by this source.
 boolean importData(javax.swing.JComponent c, java.awt.datatransfer.Transferable t)
          Import the data t in c.
 
Methods inherited from class javax.swing.TransferHandler
exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localArrayListFlavor

public java.awt.datatransfer.DataFlavor localArrayListFlavor

serialArrayListFlavor

public java.awt.datatransfer.DataFlavor serialArrayListFlavor

localArrayListType

public java.lang.String localArrayListType

localIndexType

public static java.lang.String localIndexType

localIndexFlavor

public static java.awt.datatransfer.DataFlavor localIndexFlavor
Constructor Detail

MagnetTransferHandler

public MagnetTransferHandler()
Creates a new MagnetTransferHandler instance.

Method Detail

importData

public boolean importData(javax.swing.JComponent c,
                          java.awt.datatransfer.Transferable t)
Import the data t in c.

Parameters:
t - the transferred data
c - the target component

exportDone

protected void exportDone(javax.swing.JComponent c,
                          java.awt.datatransfer.Transferable data,
                          int action)
Called on the source when the dragged has finished.

Parameters:
c - the component on which dragged occured
data - the data that was transfered
action - the kind of action that was done (COPY or MOVE)

canImport

public boolean canImport(javax.swing.JComponent c,
                         java.awt.datatransfer.DataFlavor[] flavors)
Returns true if this c can import the kind of flavors, else returns false

Parameters:
c - the component destination to test
flavors - the list of flavors
Returns:
a boolean indicating if the flavors can be imported

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
Create the instance that will be transeferred to the source from c component. We simply create some class of transferrable number that contains the index in the JList (==Model too) of the selected (== dragged) magnet.

Parameters:
c - the component from which the data is transferred (source)
Returns:
the transferrable object that contains the index of the dragged magnet

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
Returns the kind of action supported by this source. This handler supports only COPY.

Returns:
COPY


Copyright © CRAFT EPFL. All Rights Reserved.