Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.gui.main.chat
Class ChatTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by net.java.sip.communicator.util.swing.ExtendedTransferHandler
          extended by net.java.sip.communicator.impl.gui.main.chat.ChatTransferHandler
All Implemented Interfaces:
Serializable

public class ChatTransferHandler
extends ExtendedTransferHandler

A TransferHandler that we use to handle copying, pasting and DnD operations in our ChatPanel. 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
 
Nested classes/interfaces inherited from class net.java.sip.communicator.util.swing.ExtendedTransferHandler
ExtendedTransferHandler.SelectedTextTransferable
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
 
Field Summary
protected static DataFlavor uiContactDataFlavor
          The data flavor used when transferring UIContacts.
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
ChatTransferHandler(ChatPanel chatPanel)
          Constructs the ChatTransferHandler by specifying the ChatPanel we're currently dealing with.
 
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.
 boolean importData(JComponent comp, Transferable t)
          Handles transfers to the chat panel from the clip board or a DND drop operation.
 
Methods inherited from class net.java.sip.communicator.util.swing.ExtendedTransferHandler
createTransferable, exportAsDrag, exportToClipboard, getSourceActions, getVisualRepresentation
 
Methods inherited from class javax.swing.TransferHandler
canImport, exportDone, getCopyAction, getCutAction, getPasteAction, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uiContactDataFlavor

protected static final DataFlavor uiContactDataFlavor
The data flavor used when transferring UIContacts.

Constructor Detail

ChatTransferHandler

public ChatTransferHandler(ChatPanel chatPanel)
Constructs the ChatTransferHandler by specifying the ChatPanel we're currently dealing with.

Parameters:
chatPanel - the ChatPanel we're currently dealing with
Method Detail

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 ExtendedTransferHandler
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

importData

public boolean importData(JComponent comp,
                          Transferable t)
Handles transfers to the chat panel from the clip board or a DND drop operation. The Transferable parameter contains the data that needs to be imported.

Overrides:
importData in class TransferHandler
Parameters:
comp - the component to receive the transfer;
t - the data to import
Returns:
true if the data was inserted into the component and false otherwise

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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