jigcell.compare.impl
Class ClipboardDataSource

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by jigcell.compare.impl.Transferer
          extended by jigcell.compare.impl.DataSource
              extended by jigcell.compare.impl.OwnedDataSource
                  extended by jigcell.compare.impl.ClipboardDataSource
All Implemented Interfaces:
java.awt.datatransfer.ClipboardOwner, java.awt.datatransfer.Transferable, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, IDataSource, IReadableDataSource, IWriteableDataSource

public final class ClipboardDataSource
extends OwnedDataSource
implements java.awt.datatransfer.ClipboardOwner, IReadableDataSource, IWriteableDataSource

A generic transfer agent for a source of data that supports reading and writing to a clipboard.

This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.

Author:
Nicholas Allen
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface jigcell.compare.IDataSource
IDataSource.Option
 
Nested classes/interfaces inherited from interface jigcell.compare.IDataSource
IDataSource.Option
 
Field Summary
private static java.lang.String DESCRIPTION_READ
          Read operation description
private static java.lang.String DESCRIPTION_WRITE
          Write operation description
private static java.lang.String MESSAGE_NOCLIPBOARDERROR
          Error message when no clipboard is provided
private static java.lang.String MESSAGE_NOFLAVORERROR
          Error message when no transfer flavors are provided
private static java.lang.String OPTION_CLIPBOARD
          Clipboard to use
private static java.lang.String OPTION_CLIPCONTENTS
          Owned clipboard contents
static java.lang.String OPTION_FLAVORS
          Flavors to request data in
 
Fields inherited from class jigcell.compare.impl.OwnedDataSource
MESSAGE_PACKERROR, MESSAGE_PROXYERROR, OPTION_OWNER, OPTION_TRANSFERCLASS, SIGNATURE_TRANSFER
 
Fields inherited from class jigcell.compare.impl.DataSource
OPTIONS_LOCK, SEPARATOR_PAIR, SEPARATOR_PART, SEPARATORS
 
Fields inherited from class jigcell.compare.impl.Transferer
CSV_FOOTER, CSV_LINEPOSTPEND, CSV_LINEPREPEND, CSV_LINESEPARATOR, HTML_FOOTER, HTML_HEADPOSTPEND, HTML_HEADPREPEND, HTML_HEADSEPARATOR, HTML_LINEPOSTPEND, HTML_LINEPREPEND, HTML_LINESEPARATOR
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Fields inherited from interface jigcell.compare.IReadableDataSource
OPTION_READDESCRIPTION, OPTION_READICON
 
Fields inherited from interface jigcell.compare.IDataSource
OPTION_NAME
 
Fields inherited from interface jigcell.compare.IWriteableDataSource
OPTION_WRITEDESCRIPTION, OPTION_WRITEICON
 
Fields inherited from interface jigcell.compare.IDataSource
OPTION_NAME
 
Constructor Summary
ClipboardDataSource()
          Creates a new data source that represents a clipboard.
ClipboardDataSource(java.awt.datatransfer.Clipboard clipboard)
          Creates a new data source that represents a file.
 
Method Summary
private  void addToClipboardContents(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable contents)
          Adds a transferable to the clipboard contents option.
private  java.util.Map getClipboardContentsOption()
          The clipboard contents option.
private  java.awt.datatransfer.Clipboard getClipboardOption()
          The clipboard option.
 java.util.List getFlavorsOption()
          The clipboard flavors option.
 java.lang.Class getPredictedContents()
          A prediction on the type of data this source contains.
protected  void initializeSource()
          Performs any initialization work for the view that must be duplicated for each new instance.
 void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable transferable)
           
 java.lang.Object read()
          The contents of this data source or the first available content if multiple objects are supported.
private  boolean removeFromClipboardContents(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable contents)
          Removes a transferable from the clipboard contents option.
private  void setClipboardContentsOption(java.util.Map contents)
          Sets the clipboard contents option.
private  void setClipboardOption(java.awt.datatransfer.Clipboard clipboard)
          Sets the clipboard option.
 void setFlavorsOption(java.util.List flavors)
          Sets the clipboard flavors option.
 void write(java.lang.Object data)
          Writes data to the source destroying the previous contents if multiple objects are not supported.
 
Methods inherited from class jigcell.compare.impl.OwnedDataSource
encode, getOwnerOption, getPredictedCompatibility, getPredictedCompatibility, getTransferClassOption, setOwnerOption, setTransferClassOption
 
Methods inherited from class jigcell.compare.impl.DataSource
addOption, addPropertyChangeListener, addPropertyChangeListener, clone, configure, getName, getOption, getOptions, getOptionType, getPropertyChangeListeners, getPropertyChangeListeners, getReadDescriptionOption, getReadIconOption, getState, getWriteDescriptionOption, getWriteIconOption, persistSource, propertyChange, removePropertyChangeListener, removePropertyChangeListener, setName, setOption, setOptions, setOptionType, setReadDescriptionOption, setReadIconOption, setState, setWriteDescriptionOption, setWriteIconOption, toString, unpersistSource
 
Methods inherited from class jigcell.compare.impl.Transferer
addExtension, addFlavor, createCSVTable, createFormattedTable, createHTMLTable, getExceptionRecorder, getExpectedClasses, getExpectedClasses, getExpectedClasses, getFlavors, getFlavors, getPreferredExtensions, getPreferredExtensions, getTransferClass, getTransferData, getTransferDataFlavors, getTransferFlavor, isDataFlavorSupported, transfer
 
Methods inherited from class javax.swing.TransferHandler
canImport, createTransferable, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getSourceActions, getVisualRepresentation, importData
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jigcell.compare.IReadableDataSource
getReadDescriptionOption, getReadIconOption, setReadDescriptionOption, setReadIconOption
 
Methods inherited from interface jigcell.compare.IDataSource
addOption, clone, configure, getName, getOption, getState, setOption, setState
 
Methods inherited from interface jigcell.compare.IWriteableDataSource
getPredictedCompatibility, getPredictedCompatibility, getWriteDescriptionOption, getWriteIconOption, setWriteDescriptionOption, setWriteIconOption
 
Methods inherited from interface jigcell.compare.IDataSource
addOption, clone, configure, getName, getOption, getState, setOption, setState
 

Field Detail

OPTION_FLAVORS

public static final java.lang.String OPTION_FLAVORS
Flavors to request data in

See Also:
Constant Field Values

DESCRIPTION_READ

private static final java.lang.String DESCRIPTION_READ
Read operation description

See Also:
Constant Field Values

DESCRIPTION_WRITE

private static final java.lang.String DESCRIPTION_WRITE
Write operation description

See Also:
Constant Field Values

MESSAGE_NOCLIPBOARDERROR

private static final java.lang.String MESSAGE_NOCLIPBOARDERROR
Error message when no clipboard is provided

See Also:
Constant Field Values

MESSAGE_NOFLAVORERROR

private static final java.lang.String MESSAGE_NOFLAVORERROR
Error message when no transfer flavors are provided

See Also:
Constant Field Values

OPTION_CLIPBOARD

private static final java.lang.String OPTION_CLIPBOARD
Clipboard to use

See Also:
Constant Field Values

OPTION_CLIPCONTENTS

private static final java.lang.String OPTION_CLIPCONTENTS
Owned clipboard contents

See Also:
Constant Field Values
Constructor Detail

ClipboardDataSource

public ClipboardDataSource()
Creates a new data source that represents a clipboard.


ClipboardDataSource

public ClipboardDataSource(java.awt.datatransfer.Clipboard clipboard)
Creates a new data source that represents a file.

Parameters:
clipboard - Underlying clipboard
Method Detail

getFlavorsOption

public java.util.List getFlavorsOption()
The clipboard flavors option.


getPredictedContents

public java.lang.Class getPredictedContents()
A prediction on the type of data this source contains.

Specified by:
getPredictedContents in interface IReadableDataSource

lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard clipboard,
                          java.awt.datatransfer.Transferable transferable)
Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner

read

public java.lang.Object read()
                      throws java.lang.Exception
The contents of this data source or the first available content if multiple objects are supported.

Specified by:
read in interface IReadableDataSource
Throws:
java.lang.Exception

setFlavorsOption

public void setFlavorsOption(java.util.List flavors)
Sets the clipboard flavors option.

Parameters:
flavors - Flavors

write

public void write(java.lang.Object data)
           throws java.lang.Exception
Writes data to the source destroying the previous contents if multiple objects are not supported.

Specified by:
write in interface IWriteableDataSource
Parameters:
data - Data
Throws:
java.lang.Exception

initializeSource

protected void initializeSource()
Performs any initialization work for the view that must be duplicated for each new instance. This method is called exactly once and only during object construction.

Overrides:
initializeSource in class DataSource

addToClipboardContents

private void addToClipboardContents(java.awt.datatransfer.Clipboard clipboard,
                                    java.awt.datatransfer.Transferable contents)
Adds a transferable to the clipboard contents option.

Parameters:
clipboard - Containing clipboard
contents - Clipboard contents

getClipboardContentsOption

private java.util.Map getClipboardContentsOption()
The clipboard contents option.


getClipboardOption

private java.awt.datatransfer.Clipboard getClipboardOption()
The clipboard option.


removeFromClipboardContents

private boolean removeFromClipboardContents(java.awt.datatransfer.Clipboard clipboard,
                                            java.awt.datatransfer.Transferable contents)
Removes a transferable from the clipboard contents option. Returns whether an item was removed.

Parameters:
clipboard - Containing clipboard
contents - Clipboard contents

setClipboardContentsOption

private void setClipboardContentsOption(java.util.Map contents)
Sets the clipboard contents option.

Parameters:
contents - Clipboard contents

setClipboardOption

private void setClipboardOption(java.awt.datatransfer.Clipboard clipboard)
Sets the clipboard option.

Parameters:
clipboard - Clipboard