org.openbp.jaspira.gui.clipboard
Class ClipboardMgr

java.lang.Object
  extended by org.openbp.jaspira.gui.clipboard.ClipboardMgr
All Implemented Interfaces:
java.awt.datatransfer.ClipboardOwner

public final class ClipboardMgr
extends java.lang.Object
implements java.awt.datatransfer.ClipboardOwner

The clipboard manager handles all clipboard activity of a Jaspira application. It supports a multi-entry clipboard that can be connected to a clipboard toolbox for easy access.

Author:
Stephan Moritz

Field Summary
static int DEFAULT_CAPACITY
          Number of clipboard entries.
 
Method Summary
 void addClipboardListener(javax.swing.event.ChangeListener listener)
          Adds a property change listener to the listener list.
 void addEntry(java.awt.datatransfer.Transferable entry)
          Adds an entry to the clipboard.
protected  void fireClipboardChanged()
          Fires a 'clipboard change' event to all registered clipboard change listeners.
 int getCapacity()
          Returns the current capacity of the clipboard.
 java.awt.datatransfer.Transferable getCurrentEntry()
          Returns the current entry of the clipboard.
 java.util.List getEntries()
          Returns all current entries.
 java.awt.datatransfer.Transferable getEntryAt(int index)
          Returns the entry with the given index.
static ClipboardMgr getInstance()
          Returns the singleton instance of the clipboard manager.
 int getNumberOfEntries()
          Returns the number of entries currently in the clipboard.
 void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable contents)
          Is called when the clipboard manager is no longer owner of the content of the system clipboard.
 void removeClipboardListener(javax.swing.event.ChangeListener listener)
          Removes a property change listener from the listener list.
 void setCapacity(int capacity)
          Sets the capacity of the clipboard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
Number of clipboard entries. Currently, we don't support more than one clipboard entry in order not to preven gc.

See Also:
Constant Field Values
Method Detail

getInstance

public static ClipboardMgr getInstance()
Returns the singleton instance of the clipboard manager.


getNumberOfEntries

public int getNumberOfEntries()
Returns the number of entries currently in the clipboard.


addEntry

public void addEntry(java.awt.datatransfer.Transferable entry)
Adds an entry to the clipboard. If the clipboard is already full, the last entry is removed.

Parameters:
entry - The entry to add

getCapacity

public int getCapacity()
Returns the current capacity of the clipboard.


setCapacity

public void setCapacity(int capacity)
Sets the capacity of the clipboard. If capacity is less than the current number of elements, the last elements are discarded in order to match the new capacity.


getCurrentEntry

public java.awt.datatransfer.Transferable getCurrentEntry()
Returns the current entry of the clipboard. This the first entry in the list. If there currently are no entries in the board, returns null.


getEntryAt

public java.awt.datatransfer.Transferable getEntryAt(int index)
Returns the entry with the given index.


getEntries

public java.util.List getEntries()
Returns all current entries.


fireClipboardChanged

protected void fireClipboardChanged()
Fires a 'clipboard change' event to all registered clipboard change listeners.


addClipboardListener

public void addClipboardListener(javax.swing.event.ChangeListener listener)
Adds a property change listener to the listener list. A ChangeEvent will get fired in response to setting a bound property. The listener is registered for all properties as a WEAK listener, i. e. it may be garbage-collected if not referenced otherwise.
ATTENTION: Never add an automatic class (i. e new ChangeListener () { ... }) or an inner class that is not referenced otherwise as a weak listener to the list. These objects will be cleared by the garbage collector during the next gc run!

Parameters:
listener - The listener to be added

removeClipboardListener

public void removeClipboardListener(javax.swing.event.ChangeListener listener)
Removes a property change listener from the listener list.

Parameters:
listener - The listener to be removed

lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard clipboard,
                          java.awt.datatransfer.Transferable contents)
Is called when the clipboard manager is no longer owner of the content of the system clipboard. This happens when an external application enters content into the clipboard.

Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner
See Also:
ClipboardOwner.lostOwnership(java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable)


Copyright © 2011. All Rights Reserved.