org.rosuda.JGR.toolkit
Class TextTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by org.rosuda.JGR.toolkit.TextTransferHandler
All Implemented Interfaces:
java.io.Serializable, javax.swing.plaf.UIResource

public class TextTransferHandler
extends javax.swing.TransferHandler
implements javax.swing.plaf.UIResource

TextTransferHandler - copied out of the Java sources, because i need it as accessible class. RoSuDa 2003 - 2005

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
 
Field Summary
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
TextTransferHandler()
           
 
Method Summary
 boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.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  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
          Create a Transferable to use as the source for a data transfer.
protected  void exportDone(javax.swing.JComponent source, java.awt.datatransfer.Transferable data, int action)
          This method is called after data has been exported.
protected  java.awt.datatransfer.DataFlavor getImportFlavor(java.awt.datatransfer.DataFlavor[] flavors, javax.swing.text.JTextComponent c)
          Try to find a flavor that can be used to import a Transferable.
 int getSourceActions(javax.swing.JComponent c)
          This is the type of transfer actions supported by the source.
protected  void handleReaderImport(java.io.Reader in, javax.swing.text.JTextComponent c, boolean useRead)
          Import the given stream data into the text component.
 boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.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, getPasteAction, getVisualRepresentation, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextTransferHandler

public TextTransferHandler()
Method Detail

getImportFlavor

protected java.awt.datatransfer.DataFlavor getImportFlavor(java.awt.datatransfer.DataFlavor[] flavors,
                                                           javax.swing.text.JTextComponent c)
Try to find a flavor that can be used to import a Transferable. The set of usable flavors are tried in the following order:
  1. First, an attempt is made to find a flavor matching the content type of the EditorKit for the component.
  2. Second, an attempt to find a text/plain flavor is made.
  3. Third, an attempt to find a flavor representing a String reference in the same VM is made.
  4. Lastly, DataFlavor.stringFlavor is searched for.


handleReaderImport

protected void handleReaderImport(java.io.Reader in,
                                  javax.swing.text.JTextComponent c,
                                  boolean useRead)
                           throws javax.swing.text.BadLocationException,
                                  java.io.IOException
Import the given stream data into the text component.

Throws:
javax.swing.text.BadLocationException
java.io.IOException

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
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 class javax.swing.TransferHandler
Parameters:
c - The component holding the data to be transfered. This argument is provided to enable sharing of TransferHandlers by multiple components.
Returns:
This is implemented to return NONE if the component is a JPasswordField since exporting data via user gestures is not allowed. If the text component is editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
Create a Transferable to use as the source for a data transfer.

Overrides:
createTransferable in class javax.swing.TransferHandler
Parameters:
comp - The component holding the data to be transfered. This argument is provided to enable sharing of TransferHandlers by multiple components.
Returns:
The representation of the data to be transfered.

exportDone

protected void exportDone(javax.swing.JComponent source,
                          java.awt.datatransfer.Transferable data,
                          int action)
This method is called after data has been exported. This method should remove the data that was transfered if the action was MOVE.

Overrides:
exportDone in class javax.swing.TransferHandler
Parameters:
source - The component that was the source of the data.
data - The data that was transferred or possibly null if the action is NONE.
action - The actual action that was performed.

importData

public boolean importData(javax.swing.JComponent comp,
                          java.awt.datatransfer.Transferable t)
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 class javax.swing.TransferHandler
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 if the data was inserted into the component, false otherwise.

canImport

public boolean canImport(javax.swing.JComponent comp,
                         java.awt.datatransfer.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.

Overrides:
canImport in class javax.swing.TransferHandler
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 if the data can be inserted into the component, false otherwise.