com.inet.html
Class InetHtmlTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by com.inet.html.InetHtmlTransferHandler
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.CaretListener

public class InetHtmlTransferHandler
extends javax.swing.TransferHandler
implements javax.swing.event.CaretListener

This is the transfer handler, which should be used when operating on an InetHtmlDocument editor. It currently supports to paste text/html, text/plain, most of the common image format, file system links and link lists. The behavior of the handler can be modified by setting a custom handler to the current edior as client property PasteFileHandler.PASTE_HANDLER_KEY

See Also:
Serialized Form

Field Summary
static java.util.Set<java.lang.String> HTML_TYPES
           
static java.util.Set<java.lang.String> IMAGE_TYPES
          5 seconds until reset
static java.util.Set<java.lang.String> TEXT_TYPES
           
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
InetHtmlTransferHandler(javax.swing.JEditorPane c)
          Create Transfer Handler for an InetHtmlDocument Editor
 
Method Summary
 boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavors)
          
 void caretUpdate(javax.swing.event.CaretEvent e)
          Will copy the current selection to the system selection clipboard if possible
 int getSourceActions(javax.swing.JComponent component)
          Returns the action code for this component.
 boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable trans)
          
 boolean importFile(java.io.File file, javax.swing.text.Document doc, int start, int end, boolean pasteAlwaysPlain, boolean ignoreHandler)
          Tries to find the file, identify the type and import the data.
 boolean insertDataIntoDocument(java.awt.datatransfer.Transferable data, javax.swing.text.Document doc, int start, int end, boolean pasteAlwaysPlain)
          Imports the given transfer data into an editor, if possible.
 void setModePlain()
          Sets the paste mode to plain.
 void updatePasteFileHandler()
          This will update the PasteFileHandler from the client properties of the editor, this handler is bound to.
 
Methods inherited from class javax.swing.TransferHandler
exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMAGE_TYPES

public static final java.util.Set<java.lang.String> IMAGE_TYPES
5 seconds until reset


HTML_TYPES

public static final java.util.Set<java.lang.String> HTML_TYPES

TEXT_TYPES

public static final java.util.Set<java.lang.String> TEXT_TYPES
Constructor Detail

InetHtmlTransferHandler

public InetHtmlTransferHandler(javax.swing.JEditorPane c)
Create Transfer Handler for an InetHtmlDocument Editor

Parameters:
c - the Component, which will use this handler
Method Detail

updatePasteFileHandler

public void updatePasteFileHandler()
This will update the PasteFileHandler from the client properties of the editor, this handler is bound to.


canImport

public boolean canImport(javax.swing.JComponent comp,
                         java.awt.datatransfer.DataFlavor[] flavors)

Overrides:
canImport in class javax.swing.TransferHandler

importData

public boolean importData(javax.swing.JComponent comp,
                          java.awt.datatransfer.Transferable trans)

Overrides:
importData in class javax.swing.TransferHandler

getSourceActions

public int getSourceActions(javax.swing.JComponent component)
Returns the action code for this component. If it is editable the content may be moved, if not only a copy is possible

Overrides:
getSourceActions in class javax.swing.TransferHandler
Parameters:
component - The Component to fetch the data from
Returns:
if component is editable, COPY_OR_MOVE will be returned, COPY other wise

insertDataIntoDocument

public boolean insertDataIntoDocument(java.awt.datatransfer.Transferable data,
                                      javax.swing.text.Document doc,
                                      int start,
                                      int end,
                                      boolean pasteAlwaysPlain)
Imports the given transfer data into an editor, if possible.

Parameters:
data - The transfer data
doc - The document to insert the data, should be an InetHtmlDocument but is not required to
start - start of the text selection interval
end - end of the text selection interval
pasteAlwaysPlain - set to true, if only plain text is to be inserted
Returns:
true, if at least some content could be inserted

importFile

public boolean importFile(java.io.File file,
                          javax.swing.text.Document doc,
                          int start,
                          int end,
                          boolean pasteAlwaysPlain,
                          boolean ignoreHandler)
Tries to find the file, identify the type and import the data. Images will be inserted as images, html files will be inserted using the parser, textfiles will be inserted using the text2html converter.

Parameters:
file - the location of the file
doc - the document where to insert the data
start - start offset of the selection
end - end offset of the selection
pasteAlwaysPlain - Will insert only textual files without any converter
ignoreHandler - set to true, if this functions call should not invoke the custom handler
Returns:
true, if the file was found and it's content inserted

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent e)
Will copy the current selection to the system selection clipboard if possible

Specified by:
caretUpdate in interface javax.swing.event.CaretListener
Parameters:
e - the caret event, which occured

setModePlain

public void setModePlain()
Sets the paste mode to plain. The paste has to be performed within a timeout defined by PASTE_PLAIN_TIMEOUT, otherwise the content is pasted like normal.