Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.util.swing
Class ExtendedTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by net.java.sip.communicator.util.swing.ExtendedTransferHandler
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CallTransferHandler, ChatTransferHandler, ContactListTransferHandler, InviteContactTransferHandler

public class ExtendedTransferHandler
extends TransferHandler

A TransferHandler that we use to handle copying, pasting and DnD operations. The string handler is heavily inspired by Sun's DefaultTransferHandler with the main difference being that we only accept pasting of plain text. We do this in order to avoid HTML support problems that appear when pasting formatted text into our editable area.

Author:
Emil Ivov, Yana Stamcheva
See Also:
Serialized Form

Nested Class Summary
 class ExtendedTransferHandler.SelectedTextTransferable
          Transferable for text pane components that enables drag and drop of text.
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
 
Field Summary
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
ExtendedTransferHandler()
           
 
Method Summary
 boolean canImport(JComponent comp, DataFlavor[] flavor)
          Indicates whether a component will accept an import of the given set of data flavors prior to actually attempting to import it.
protected  Transferable createTransferable(JComponent component)
          Creates a transferable for text pane components in order to enable drag and drop of text.
 void exportAsDrag(JComponent comp, InputEvent e, int action)
          Overrides TransferHandler.exportAsDrag method in order to call our own SwingDragGestureRecognizer, which takes care of the visual representation icon.
 void exportToClipboard(JComponent comp, Clipboard clipboard, int action)
          Handles transport (cut and copy) from the chat panel to clipboard.
 int getSourceActions(JComponent c)
          Returns the type of transfer actions supported by the source; any bitwise-OR combination of COPY, MOVE and LINK.
 Icon getVisualRepresentation(Transferable t)
          Overrides TransferHandler.getVisualRepresentation(Transferable t) in order to return a custom drag icon.
 
Methods inherited from class javax.swing.TransferHandler
canImport, exportDone, getCopyAction, getCutAction, getPasteAction, importData, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendedTransferHandler

public ExtendedTransferHandler()
Method Detail

getSourceActions

public int getSourceActions(JComponent c)
Returns the type of transfer actions supported by the source; any bitwise-OR combination of COPY, MOVE and LINK.

Some models are not mutable, so a transfer operation of MOVE should not be advertised in that case. Returning NONE disables transfers from the component.

Overrides:
getSourceActions in class TransferHandler
Parameters:
c - the component holding the data to be transferred; provided to enable sharing of TransferHandlers
Returns:
COPY if the transfer property can be found, otherwise returns NONE

canImport

public boolean canImport(JComponent comp,
                         DataFlavor[] flavor)
Indicates whether a component will accept an import of the given set of data flavors prior to actually attempting to import it. We return true to indicate that the transfer with at least one of the given flavors would work and false to reject the transfer.

Overrides:
canImport in class TransferHandler
Parameters:
comp - component
flavor - the data formats available
Returns:
true if the data can be inserted into the component, false otherwise
Throws:
NullPointerException - if support is null

createTransferable

protected Transferable createTransferable(JComponent component)
Creates a transferable for text pane components in order to enable drag and drop of text.

Overrides:
createTransferable in class TransferHandler
Parameters:
component - the component for which to create a Transferable
Returns:
the created Transferable

exportToClipboard

public void exportToClipboard(JComponent comp,
                              Clipboard clipboard,
                              int action)
                       throws IllegalStateException
Handles transport (cut and copy) from the chat panel to clipboard. This method will only transfer plain text and would explicitly ignore any formatting.

Overrides:
exportToClipboard in class TransferHandler
Parameters:
comp - the component holding the data to be transferred; provided to enable sharing of TransferHandlers
clipboard - the clipboard to transfer the data into
action - the transfer action requested; this should be a value of either COPY or MOVE; the operation performed is the intersection of the transfer capabilities given by getSourceActions and the requested action; the intersection may result in an action of NONE if the requested action isn't supported
Throws:
IllegalStateException - if the clipboard is currently unavailable
See Also:
Clipboard.setContents(Transferable, ClipboardOwner)

getVisualRepresentation

public Icon getVisualRepresentation(Transferable t)
Overrides TransferHandler.getVisualRepresentation(Transferable t) in order to return a custom drag icon.

The default parent implementation of this method returns null.

Overrides:
getVisualRepresentation in class TransferHandler
Parameters:
t - the data to be transferred; this value is expected to have been created by the createTransferable method
Returns:
the icon to show when dragging

exportAsDrag

public void exportAsDrag(JComponent comp,
                         InputEvent e,
                         int action)
Overrides TransferHandler.exportAsDrag method in order to call our own SwingDragGestureRecognizer, which takes care of the visual representation icon.

Overrides:
exportAsDrag in class TransferHandler
Parameters:
comp - the component holding the data to be transferred; this argument is provided to enable sharing of TransferHandlers by multiple components
e - the event that triggered the transfer
action - the transfer action initially requested; this should be a value of either COPY or MOVE; the value may be changed during the course of the drag operation

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.