com.macmillan.nmeyers
Class XClipboard
java.lang.Object
|
+--com.macmillan.nmeyers.XClipboard
- public class XClipboard
- extends java.lang.Object
Implements some X-specific methods for cut and paste.
The X Window System has several mechanisms to support cut
and paste:
- CLIPBOARD selection
- This is the mechanism used by applications that implement an
explicit cut and paste mechanism. It's used
by the java.awt.datatransfer.Clipboard methods.
- PRIMARY selection
- This is the mechanism used when you simply drag a selection without
cutting or copying. For example, when you drag a selection in one
terminal window and paste it into another with the middle mouse button,
you're using primary selection.
- SECONDARY selection
- An adjunct to the primary selection mechanism.
- CUTBUFFER0
- An outdated way of moving data around. Unlike selection, which
supports moving arbitrary data types through an active transfer
between programs, the cutbuffer statically stores text data in
properties on the root window. Tends to be used only by ancient
X clients.
This class provides some simple methods for extracting
text selection strings. It can be subclassed to support more
generality: the protected readSelection() method can support
arbitrary selection atom names and arbitrary target types.
More information than you could ever want to know about this can
be found in the XConvertSelection() man page and the ICCCM
specifications.
- Author:
- Nathan Meyers
Field Summary |
protected byte[] |
privateXData
Hold platform-specific data here: X window connection and
window ID. |
Constructor Summary |
XClipboard()
The class constructor opens a connection to the X server. |
Method Summary |
protected void |
finalize()
Shut down the X connection at finalization. |
static void |
main(java.lang.String[] argv)
A simple test of the selection mechanisms. |
java.lang.String |
readClipboardSelectionString()
Read the clipboard selection as a string. |
byte[] |
readCutBuffer0()
Read the contents of CutBuffer0. |
java.lang.String |
readPrimarySelectionString()
Read the primary selection as a string. |
java.lang.String |
readSecondarySelectionString()
Read the secondary selection as a string. |
protected java.lang.Object |
readSelection(byte[] dp,
byte[] selection,
byte[] target)
Request and read the current selection. |
Methods inherited from class java.lang.Object |
clone,
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
privateXData
protected byte[] privateXData
- Hold platform-specific data here: X window connection and
window ID.
XClipboard
public XClipboard()
- The class constructor opens a connection to the X server. Since
Java will not share its X connections, XClipboard needs one of
its own.
finalize
protected void finalize()
- Shut down the X connection at finalization.
- Overrides:
- finalize in class java.lang.Object
readCutBuffer0
public byte[] readCutBuffer0()
- Read the contents of CutBuffer0. This is an ancient X cut/paste
mechanism, and of very limited use.
readSelection
protected java.lang.Object readSelection(byte[] dp,
byte[] selection,
byte[] target)
- Request and read the current selection. The entire selection
is read and returned, rather than setting up an InputStream
mechanism to pump the bits as needed (which might be preferable
for big selections).
This protected class is not the primary interface,
but supports adding generality not supported by the various
read* functions.
- Parameters:
dp
- The private X data created by the class constructor.selection
- The selection being requested - name of an X
atom. The usual cut/paste buffer is "PRIMARY". Also of interest:
"SECONDARY" and "CLIPBOARD".target
- The target type - name of an X atom. "STRING" is
the most common.- Returns:
- a byte[], short[], or int[] with the selection value.
The type is determined by the type returned by the selection.
readPrimarySelectionString
public java.lang.String readPrimarySelectionString()
- Read the primary selection as a string.
If an application has some text selected, this will return it.
readSecondarySelectionString
public java.lang.String readSecondarySelectionString()
- Read the secondary selection as a string.
The secondary selection is rarely used.
readClipboardSelectionString
public java.lang.String readClipboardSelectionString()
- Read the clipboard selection as a string.
If an application has cut or copied some text,
this will return it. This duplicates, in a limited way, capabilities
in java.awt.datatransfer.Clipboard.
main
public static void main(java.lang.String[] argv)
- A simple test of the selection mechanisms. Call the four
public read* calls and report any non-null results.