Class RearrangingTransferHandler<T extends Component,V>
java.lang.Object
javax.swing.TransferHandler
com.illumon.iris.gui.widget.dragndrop.RearrangingTransferHandler<T,V>
- Type Parameters:
T
- The component type for the instanceV
- The Value type that is being transferred
- All Implemented Interfaces:
Serializable
public abstract class RearrangingTransferHandler<T extends Component,V> extends TransferHandler
A generalized
TransferHandler
that supports moving data to itself as well as another indexable
component.- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
-
Field Summary
Fields Modifier and Type Field Description protected static javax.activation.ActivationDataFlavor
DATA_FLAVOR
protected com.fishlib.io.logger.Logger
log
protected T
myself
A reference to the component this transfer handler is attached to. -
Constructor Summary
Constructors Constructor Description RearrangingTransferHandler(T myself, IntFunction<V[]> arrayFactory, com.fishlib.io.logger.Logger log)
Create a RearangingTransferHandler. -
Method Summary
Modifier and Type Method Description protected abstract void
addItem(V o, int i)
Add an item to the backing collection.boolean
canImport(TransferHandler.TransferSupport support)
protected void
doRearrange(SourceAndIndices data, TransferHandler.TransferSupport support)
If the source and target for the DnD operation is the same object we will do the entire rearrange operation in one go, and forego the cleanup step.protected void
exportDone(JComponent source, Transferable data, int action)
protected abstract int
getDropLocation(TransferHandler.TransferSupport support)
Get an integer index for the drop location of the backing collection given the support object.protected abstract int
getItemCount()
Get the count of items contained within the collection being transferred to.protected abstract V
getValueAt(int index)
Get the value at the specified index in the backing collection.boolean
importData(TransferHandler.TransferSupport support)
protected abstract void
removeItem(int index)
Remove the item from the backing collection at the specified index.Methods inherited from class javax.swing.TransferHandler
canImport, createTransferable, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getSourceActions, getVisualRepresentation, importData, setDragImage, setDragImageOffset
-
Field Details
-
DATA_FLAVOR
protected static final javax.activation.ActivationDataFlavor DATA_FLAVOR -
myself
A reference to the component this transfer handler is attached to. -
log
protected final com.fishlib.io.logger.Logger log
-
-
Constructor Details
-
RearrangingTransferHandler
public RearrangingTransferHandler(T myself, IntFunction<V[]> arrayFactory, com.fishlib.io.logger.Logger log)Create a RearangingTransferHandler.- Parameters:
myself
- The Component that this transfer handler will be attached toarrayFactory
- a factory method for creating arrays of the underlying typelog
- a logger
-
-
Method Details
-
importData
- Overrides:
importData
in classTransferHandler
-
canImport
- Overrides:
canImport
in classTransferHandler
-
doRearrange
If the source and target for the DnD operation is the same object we will do the entire rearrange operation in one go, and forego the cleanup step.- Parameters:
data
- the data to importsupport
- the support object3
-
exportDone
- Overrides:
exportDone
in classTransferHandler
-
addItem
Add an item to the backing collection.- Parameters:
o
- the item to addi
- the index to add it at
-
removeItem
protected abstract void removeItem(int index)Remove the item from the backing collection at the specified index.- Parameters:
index
- the index to remove
-
getValueAt
Get the value at the specified index in the backing collection.- Parameters:
index
- the index- Returns:
- the value at 'index'
-
getDropLocation
Get an integer index for the drop location of the backing collection given the support object.- Parameters:
support
- the support object- Returns:
- the drop location in the backing collection
-
getItemCount
protected abstract int getItemCount()Get the count of items contained within the collection being transferred to.- Returns:
- the number of items in the collection being transferred to
-