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
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
// final because this list is used in a anonymous inner class.
final List<DataFlavor> availableFlavorList = new LinkedList<DataFlavor>();
// Main loop.
while (true) {
////////////////////////////////////////////////////////////////////////////////////////////////
// Look for available clipboard content based on the flavors were are expecting.
// synchronized because this list is used in a anonymous inner class.
synchronized (availableFlavorList) {
availableFlavorList.clear();
for (Flavor flavor : expectedFlavors) {
if (clipbard.isDataFlavorAvailable(flavor)) {
availableFlavorList.add(flavor);
}
}
}
//////////////////////////////////////////////////////////////
// Clipboard has content, we fire an event in the EDT.
if (availableFlavorList.size() > 0) {
SwingUtilities.invokeLater(new Runnable() {
/** @inheritDoc
*/
public void run() {
// synchronized because this list is used in the main loop.
synchronized (availableFlavorList) {
// Fire event here.
// the clipboard has some content we're interrested in.
...
}
});
}
///////////////////////////
// Sleep for some time.
t.sleep(...);
} |
Partager