public interface ActiveEditorDrop
private class MyDrop extends StringSelection implements ActiveEditorDrop { public MyDrop(String text){ super(text); //NOI18N } public boolean isDataFlavorSupported(DataFlavor f) { return super.isDataFlavorSupported(f) || ActiveEditorDrop.FLAVOR == f; } public final DataFlavor[] getTransferDataFlavors() { DataFlavor delegatorFlavor[] = super.getTransferDataFlavors(); int delegatorFlavorLength = delegatorFlavor.length; DataFlavor newArray[] = new DataFlavor[delegatorFlavorLength + 1]; System.arraycopy(delegatorFlavor, 0, newArray, 0, delegatorFlavorLength); newArray[delegatorFlavorLength] = ActiveEditorDrop.FLAVOR; return newArray; } public final Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor == ActiveEditorDrop.FLAVOR) { return this; } return super.getTransferData(flavor); } public boolean handleTransfer(JTextComponent targetComponent) { // your implementation } }or simplified solution:
private class MyDrop implements ActiveEditorDrop, Transferable { public MyDrop(){ } public boolean isDataFlavorSupported(DataFlavor f) { return ActiveEditorDrop.FLAVOR == f; } public final DataFlavor[] getTransferDataFlavors() { DataFlavor delegatorFlavor[] = new DataFlavor[1]; delegatorFlavor[0] = ActiveEditorDrop.FLAVOR; return delegatorFlavor; } public final Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { return (flavor == ActiveEditorDrop.FLAVOR) ? this : null; } public boolean handleTransfer(JTextComponent targetComponent) { //your implementation } }
Modifier and Type | Field and Description |
---|---|
static DataFlavor |
FLAVOR
Active editor DataFlavor used for communication between DragSource and DragTarget.
|
Modifier and Type | Method and Description |
---|---|
boolean |
handleTransfer(JTextComponent targetComponent)
A method called from the drop target that supports the artificial DataFlavor.
|
static final DataFlavor FLAVOR
boolean handleTransfer(JTextComponent targetComponent)
targetComponent
- a Component where drop operation occured.