Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Clipboard Change Notification

Reply
Thread Tools

Clipboard Change Notification

 
 
Ian Shef
Guest
Posts: n/a
 
      08-16-2006
Is there a way to be notified about all changes to the system clipboard?
How?

java.awt.datatransfer.Clipboard.addFlavorListener( FlavorListener listener)
only provides reliable notification (at least under Windows XP) if the
available DataFlavors have changed. I want to be notified if the clipboard
contents have been changed, even if the new contents have the same
DataFlavors as the previous contents.

I can force the issue by grabbing ownership of the clipboard via
clipboard.setContents(clipboard.getContents(null), this)
but this seems like an unfriendly act. Besides, if two such applications run
concurrently on the same host, they will grab control back and forth ad
nauseum.

I must be missing 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 *
 
Reply With Quote
 
 
 
 
Ian Shef
Guest
Posts: n/a
 
      08-16-2006
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!

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      08-16-2006
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.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      08-16-2006

"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

 
Reply With Quote
 
Ian Shef
Guest
Posts: n/a
 
      08-16-2006
"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 *
 
Reply With Quote
 
Ian Shef
Guest
Posts: n/a
 
      08-17-2006
Ian Shef <> wrote in
news:Xns9821873EFA5EEvaj4088ianshef@138.125.254.21 0:

> 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!
>


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.



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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cisco Configuration Change Notification cwebb Cisco 0 09-06-2007 01:49 PM
Cisco Configuration Change Notification cwebb Hardware 0 09-04-2007 09:16 PM
Configuration Change Notification and Logging Merv Cisco 0 03-22-2006 04:54 PM
Overwhelming Change Notification =?Utf-8?B?RXJvbiBXcmlnaHQ=?= ASP .Net 0 02-28-2006 04:35 PM
CHANGE OF EMAIL ADDRESS NOTIFICATION tracy Python 0 08-29-2005 11:35 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57