"Oliver Wong" <> wrote in news:iyMEg.6198$395.4269
@edtnps90:
>
> "Steve W. Jackson" <> wrote in message
> news:stevewjackson-...
>> In article <Xns9821873EFA5EEvaj4088ianshef@138.125.254.210> ,
>> Ian Shef <> wrote:
>>
>>> Ian Shef <> wrote in
>>> news:Xns98218643A5269vaj4088ianshef@138.125.254.21 0:
>>>
>>> > 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!
>>
>> 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.
>
> 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
>
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.
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
|