Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Clipboard Change Notification

Thread view: 
Ian Shef - 16 Aug 2006 21:11 GMT
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.

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 - 16 Aug 2006 21:17 GMT
> 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    *



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.