9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.X11;
27
28 import java.awt.datatransfer.Transferable;
29 import java.util.SortedMap;
30 import java.io.IOException;
31 import java.security.AccessController;
32 import java.util.HashMap;
33 import java.util.Map;
34 import sun.awt.UNIXToolkit;
35 import sun.awt.datatransfer.DataTransferer;
36 import sun.awt.datatransfer.SunClipboard;
37 import sun.awt.datatransfer.ClipboardTransferable;
38 import sun.security.action.GetIntegerAction;
39
40 /**
41 * A class which interfaces with the X11 selection service in order to support
42 * data transfer via Clipboard operations.
43 */
44 public final class XClipboard extends SunClipboard implements OwnershipListener
45 {
46 private final XSelection selection;
47 // Time of calling XConvertSelection().
48 private long convertSelectionTime;
66 */
67 public XClipboard(String name, String selectionName) {
68 super(name);
69 selection = new XSelection(XAtom.get(selectionName));
70 selection.registerOwershipListener(this);
71 }
72
73 /*
74 * NOTE: This method may be called by privileged threads.
75 * DO NOT INVOKE CLIENT CODE ON THIS THREAD!
76 */
77 public void ownershipChanged(final boolean isOwner) {
78 if (isOwner) {
79 checkChangeHere(contents);
80 } else {
81 lostOwnershipImpl();
82 }
83 }
84
85 protected synchronized void setContentsNative(Transferable contents) {
86 SortedMap formatMap = DataTransferer.getInstance().getFormatsForTransferable
87 (contents, DataTransferer.adaptFlavorMap(flavorMap));
88 long[] formats = DataTransferer.keysToLongArray(formatMap);
89
90 if (!selection.setOwner(contents, formatMap, formats,
91 XToolkit.getCurrentServerTime())) {
92 this.owner = null;
93 this.contents = null;
94 }
95 }
96
97 public long getID() {
98 return selection.getSelectionAtom().getAtom();
99 }
100
101 @Override
102 public synchronized Transferable getContents(Object requestor) {
103 if (contents != null) {
104 return contents;
105 }
106 return new ClipboardTransferable(this);
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.X11;
27
28 import java.awt.datatransfer.Transferable;
29 import java.awt.datatransfer.DataFlavor;
30 import java.util.SortedMap;
31 import java.io.IOException;
32 import java.security.AccessController;
33 import java.util.HashMap;
34 import java.util.Map;
35 import sun.awt.UNIXToolkit;
36 import sun.awt.datatransfer.DataTransferer;
37 import sun.awt.datatransfer.SunClipboard;
38 import sun.awt.datatransfer.ClipboardTransferable;
39 import sun.security.action.GetIntegerAction;
40
41 /**
42 * A class which interfaces with the X11 selection service in order to support
43 * data transfer via Clipboard operations.
44 */
45 public final class XClipboard extends SunClipboard implements OwnershipListener
46 {
47 private final XSelection selection;
48 // Time of calling XConvertSelection().
49 private long convertSelectionTime;
67 */
68 public XClipboard(String name, String selectionName) {
69 super(name);
70 selection = new XSelection(XAtom.get(selectionName));
71 selection.registerOwershipListener(this);
72 }
73
74 /*
75 * NOTE: This method may be called by privileged threads.
76 * DO NOT INVOKE CLIENT CODE ON THIS THREAD!
77 */
78 public void ownershipChanged(final boolean isOwner) {
79 if (isOwner) {
80 checkChangeHere(contents);
81 } else {
82 lostOwnershipImpl();
83 }
84 }
85
86 protected synchronized void setContentsNative(Transferable contents) {
87 SortedMap<Long,DataFlavor> formatMap =
88 DataTransferer.getInstance().getFormatsForTransferable
89 (contents, DataTransferer.adaptFlavorMap(flavorMap));
90 long[] formats = DataTransferer.keysToLongArray(formatMap);
91
92 if (!selection.setOwner(contents, formatMap, formats,
93 XToolkit.getCurrentServerTime())) {
94 this.owner = null;
95 this.contents = null;
96 }
97 }
98
99 public long getID() {
100 return selection.getSelectionAtom().getAtom();
101 }
102
103 @Override
104 public synchronized Transferable getContents(Object requestor) {
105 if (contents != null) {
106 return contents;
107 }
108 return new ClipboardTransferable(this);
|