|
Quick Lists
|
|
Bug ID:
|
4259272
|
|
Votes
|
15
|
|
Synopsis
|
Support Notifications of Clipboard Contents Changes
|
|
Category
|
java:drag&drop
|
|
Reported Against
|
1.1.6
, 1.2.2
, merlin-beta
|
|
Release Fixed
|
1.5(tiger)
|
|
State
|
10-Fix Delivered,
request for enhancement
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
4141702
,
4473507
,
4701990
,
4884951
,
4287795
,
4882934
,
4884956
,
4885687
|
|
Submit Date
|
03-AUG-1999
|
|
Description
|
Most Windows applications, and probably those on other platforms,
typically enable "paste" functionality only when there is valid data
on the clipboard ("valid" meaning of an appropriate flavor).
Implementing this behavior requires a mechanism through which changes
to the clipboard can be detected. That is when the option should be
enabled or disabled -- when the clipboard contents change. The Java
Clipboard API does not currently support this type of notification,
but it could be added trivially.
I suggest that java.awt.Clipboard be extended to support a set of
listeners (PropertyChangeListener would be adequate) who are notified
when the clipboard contents change. This would be entirely backward
compatible with the existing API and would provide very useful
functionality that is not currently available.
(Review ID: 93418)
======================================================================
|
|
Work Around
|
I am not aware of any workaround. I tried a hack using
ClipboardOwnership. The idea was that if I am always the owner
of the clipboard, I will receive a lostOwnership whenever the
contents change. However, it is not generally possible (or good)
to steal ownership when an xxxxx application is using the
clipboard.
======================================================================
|
|
Evaluation
|
Will consider along with other Clipboard RFEs for merlin.
xxxxx@xxxxx 1999-12-14
We didn't have time to get this in for merlin. Will have to wait for tiger.
xxxxx@xxxxx 2000-12-14
Notifications on clipboard contents changes can be
implemented for a local clipboard and the Windows system
clipboard, but not for selections on Solaris/Linux, since
Xlib does not provide any means for doing that.
To determine whether notifications on contents changes are
supported for the clipboard, the method
Clipboard.areContentsChangeNotificationsSupported() has been
added.
In order to be notified on a clipboard contents changes the
ContentsListener should be added to the clipboard by means
of Clipboard.addContentsListener() method. Also public two
methods for managing listeners were added:
Clipboard.getContentsListeners() and
Clipboard.removeContentsListener().
xxxxx@xxxxx 2002-12-11
======================================================================
I should mention that first I have tried to implement
notifications on clipboard contents changes using
PropertyChangeListeners. In that case old and new contents
of a clipboard must be passed to listeners.
It is trivial to implement it for a local clipboard.
As for Windows system clipboard, it could be implemented,
but a great care should be taken to synchronize contents
updates (this is not that problematically), also new
clipboard contents can not be reliably retrieved. If some
application opened the system clipboard and did not close
it, an attempt to fetch clipboard contents would fail, and
the failure would manifest in our code, where it could not
be handled properly.
So the decision not to provide clipboard contents directly
to the listeners and to use a new interface for listeners
(java.awt.datatransfer.ContentsListener) and a new class for
events (java.awt.datatransfer.ContentsEvent) was taken.
xxxxx@xxxxx 2002-12-11
======================================================================
The described above implementation of the feature isn't
really cross-platform: the feature wasn't implemented for
the system clipboard and system selection on X11 platforms.
All that we could do on X11 platforms was polling a
selection, retrieving its contents and comparing that
contents with the previous one. It isn't acceptable since it
is very expensive.
So in order to properly implement this feature on all
supported platforms we decided to redesign the current
implementation. To implement the functionality defined in
the description (enabling/disabling paste option in a Java
application depending on what flavors clipboard data are
available) it's sufficient to track the changes of data
flavors available on the clipboard.
The following new API are to be introduced in the package
java.awt.datatransfer:
a listener interface FlavorListener,
an event FlavorEvent that is delivered to the
FlavorListeners whenever clipboard flavors change,
and the following Clipboard methods:
void Clipboard.addFlavorListener(FlavorListener listener),
void Clipboard.removeFlavorListener(FlavorListener listener),
FlavorListener[] Clipboard.getFlavorListeners().
xxxxx@xxxxx 2003-01-18
======================================================================
|
|
Comments
|
Submitted On 18-JUN-2003
oscarhob
In what release would you anticipate the above API
(FlavorListener, FlavorEvent) being added ?
Submitted On 02-JUL-2003
g_e_r_1
As we can see it on this page:
Release Fixed tiger - JDK 1.5
Submitted On 18-JUL-2003
oscarhob
Yes - though on June 18 it was not listed as such.
Submitted On 19-OCT-2003
metao
By my understanding (from post 2003-01-18) the FlavorEvent
will only fire if the flavour of the clipboard contents changes.
What would then happen if the user copied, say, a HTML
page, and then copied *another* HTML page?
Workaround: Well, I guess we could grab the clipboard
content, convert it to plain text, and throw it back... and
then when the second page is copied, the flavour changes.
Just something to think about...
Submitted On 21-OCT-2003
g_e_r_1
The approach (to notify about changes of data flavors
available on the clipboard) is sufficient to implement the
functionality mentioned in the description (enabling/disabling
paste option in a Java application depending on what flavors
clipboard data are available in). I guess, few applications
really need to be notified about all settings of new clipboard
contents (the only example I know is the Windows clipboard
viewer).
Submitted On 05-NOV-2005
fir99
I plan to implement a small dictionary tool to translate botanic scientific names to native language names. The user may copy names from some application to the system clipboard. The tool observes the clipboard and displays the translation. For this a notification of every clipboard content change would be fine. The system clipboard implementation of Tiger (1.5) doesn't notify FlavorListeners reliable about content changes, see http://forums.java.sun.com/thread.jspa?threadID=679063.
Submitted On 07-NOV-2005
ag1
Sent are notifications about changes of data flavors
available on the clipboard. One should file an RFE if
they want API for notifications about all changes of
clipboard contents (e.g. some text is replaced with
other text). Anyway, one is able to implement the
required functionality now: retrieve text data from
the clipboard on a separate thread frequently.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |