
Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
> Is there a way to be notified about all changes to the system clipboard?
> How?
<deleted explanation of
java.awt.datatransfer.Clipboard.addFlavorListener
and of
clipboard.setContents(clipboard.getContents(null), this) >
Before anybody suggests it, I think that polling the system clipboard and
comparing the current contents with the previous contents is also a poor
solution. There ought to be a better way!

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Steve W. Jackson - 16 Aug 2006 21:39 GMT
> > Is there a way to be notified about all changes to the system clipboard?
> > How?
[quoted text clipped - 6 lines]
> comparing the current contents with the previous contents is also a poor
> solution. There ought to be a better way!
Seems to me that the ClipboardOwner interface should provide hat you
want. Unless I'm missing something.
Per the Javadocs, an instance of the interface becomes the owner of a
clipboard's contents if it's passed as an argument to a clipboard's
setContents. Then its lostOwnership method will serve as a listener in
the event that any other owner (within the same app or externally) puts
data there and thus becomes the clipboard's owner.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Oliver Wong - 16 Aug 2006 22:58 GMT
>> > Is there a way to be notified about all changes to the system
>> > clipboard?
[quoted text clipped - 16 lines]
> the event that any other owner (within the same app or externally) puts
> data there and thus becomes the clipboard's owner.
What if the app doesn't currently own the clipboard, but wants to
monitor it? If the clipboard changes, since the current app is not the
owner, it will not be notified of lost of ownership.
- Oliver
Ian Shef - 17 Aug 2006 00:49 GMT
"Oliver Wong" <owong@castortech.com> wrote in news:iyMEg.6198$395.4269
@edtnps90:
>>> > Is there a way to be notified about all changes to the system
>>> > clipboard?
[quoted text clipped - 22 lines]
>
> - Oliver
Exactly -- lostOwnership() is what I was talking about when I discussed
avoiding
clipboard.setContents(clipboard.getContents(null), this)
"this" (or whatever object is used for this parameter) must implement
ClipboardOwner and becomes the owner of the clipboard. However, this feels
unfriendly, it is wasteful (because becoming clipboard owner while
maintaining the contents of the clipboard requires getting the current
contents and putting them back), and because it can cause conflicts with
other tasks that do the same thing. Thanks, Steve, for the suggestion, but
I already experimented with that approach.
In line with Oliver's comments, I am hoping for something better. I want
to monitor what _other_ applications put onto the clipboard but I only want
to affect the clipboard when I recognize that particular new content has
been provided.
There ought to be a better way.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Ian Shef - 17 Aug 2006 02:07 GMT
>> Is there a way to be notified about all changes to the system clipboard?
>> How?
[quoted text clipped - 6 lines]
> comparing the current contents with the previous contents is also a poor
> solution. There ought to be a better way!
A followup to my own article...
It appears that Sun Developer Network Bug ID # 4259272 explains why this is
the way that it is: (1) notifying listeners about changes to DataFlavors
allows them to enable/disable their paste menu items. (2) Content change
notifications are available on some platforms but not others (e.g. not on
X11). It was deemed too expensive for Java to internally perform the polling
and comparison needed on these platforms, and the option to have an API to
ask whether contents change notifications are supported was dropped due to
insufficient demand.
Looks like I will have to perform my own polling. Sigh.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *