Package org.fife.ui.rtextarea
Class RTATextTransferHandler
java.lang.Object
javax.swing.TransferHandler
org.fife.ui.rtextarea.RTATextTransferHandler
- All Implemented Interfaces:
Serializable
Handles the transfer of data to/from an
RTextArea
via
drag-and-drop. This class is pretty much ripped off from a subclass of
BasicTextUI
. In the future, it will include the ability to
drag-and-drop files into RTextArea
s (i.e., the text will be
inserted into the text area).The main reason this class is kept around is so we can subclass it.
- Version:
- 0.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
A possible implementation of the Transferable interface for RTextAreas.Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JTextComponent
private int
private int
private boolean
private boolean
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canImport
(JComponent comp, DataFlavor[] flavors) This method indicates if a component would accept an import of the given set of data flavors prior to actually attempting to import it.protected Transferable
createTransferable
(JComponent comp) Create a Transferable to use as the source for a data transfer.protected void
exportDone
(JComponent source, Transferable data, int action) This method is called after data has been exported.protected DataFlavor
getImportFlavor
(DataFlavor[] flavors, JTextComponent c) Try to find a flavor that can be used to import a Transferable to a specified text component.int
This is the type of transfer actions supported by the source.protected void
Import the given stream data into the text component.boolean
importData
(JComponent comp, Transferable t) This method causes a transfer to a component from a clipboard or a DND drop operation.Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
-
Field Details
-
exportComp
-
shouldRemove
private boolean shouldRemove -
p0
private int p0 -
p1
private int p1 -
withinSameComponent
private boolean withinSameComponent
-
-
Constructor Details
-
RTATextTransferHandler
public RTATextTransferHandler()
-
-
Method Details
-
getImportFlavor
Try to find a flavor that can be used to import a Transferable to a specified text component. The set of usable flavors are tried in the following order:- First, an attempt is made to find a flavor matching the content type of the EditorKit for the component.
- Second, an attempt to find a text/plain flavor is made.
- Third, an attempt to find a flavor representing a String reference in the same VM is made.
- Lastly, DataFlavor.stringFlavor is searched for.
- Parameters:
flavors
- The flavors to check if c will accept them.c
- The text component to see whether it will accept any of the specified data flavors as input.
-
handleReaderImport
Import the given stream data into the text component.- Throws:
IOException
-
getSourceActions
This is the type of transfer actions supported by the source. Some models are not mutable, so a transfer operation of COPY only should be advertised in that case.- Overrides:
getSourceActions
in classTransferHandler
- Parameters:
c
- The component holding the data to be transferred. This argument is provided to enable sharing of TransferHandlers by multiple components.- Returns:
- If the text component is editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.
-
createTransferable
Create a Transferable to use as the source for a data transfer.- Overrides:
createTransferable
in classTransferHandler
- Parameters:
comp
- The component holding the data to be transferred. This argument is provided to enable sharing of TransferHandlers by multiple components.- Returns:
- The representation of the data to be transferred.
-
exportDone
This method is called after data has been exported. This method should remove the data that was transferred if the action was MOVE.- Overrides:
exportDone
in classTransferHandler
- Parameters:
source
- The component that was the source of the data.data
- The data that was transferred or possibly null if the action isNONE
.action
- The actual action that was performed.
-
importData
This method causes a transfer to a component from a clipboard or a DND drop operation. The Transferable represents the data to be imported into the component.- Overrides:
importData
in classTransferHandler
- Parameters:
comp
- The component to receive the transfer. This argument is provided to enable sharing of TransferHandlers by multiple components.t
- The data to import- Returns:
true
iff the data was inserted into the component.
-
canImport
This method indicates if a component would accept an import of the given set of data flavors prior to actually attempting to import it.- Overrides:
canImport
in classTransferHandler
- Parameters:
comp
- The component to receive the transfer. This argument is provided to enable sharing of TransferHandlers by multiple components.flavors
- The data formats available.- Returns:
true
iff the data can be inserted.
-