author | hannesw |
Thu, 23 Nov 2017 16:20:10 +0100 | |
changeset 47929 | df9e7f2df01f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
2 |
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt.datatransfer; |
|
27 |
||
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
28 |
import java.io.IOException; |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
29 |
import java.util.Arrays; |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
30 |
import java.util.HashSet; |
24153
2c19973ab9f2
6463901: Either generify or deprecate sun.awt.EventListenerAggregate
pchelko
parents:
22281
diff
changeset
|
31 |
import java.util.Objects; |
2 | 32 |
import java.util.Set; |
33 |
||
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
34 |
import sun.datatransfer.DataFlavorUtil; |
2 | 35 |
|
36 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
37 |
* A class that implements a mechanism to transfer data using cut/copy/paste |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
38 |
* operations. |
2 | 39 |
* <p> |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
40 |
* {@link FlavorListener}s may be registered on an instance of the Clipboard |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
41 |
* class to be notified about changes to the set of {@link DataFlavor}s |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
42 |
* available on this clipboard (see {@link #addFlavorListener}). |
2 | 43 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
44 |
* @author Amy Fowler |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
45 |
* @author Alexander Gerasimov |
2 | 46 |
* @see java.awt.Toolkit#getSystemClipboard |
47 |
* @see java.awt.Toolkit#getSystemSelection |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
28987
diff
changeset
|
48 |
* @since 1.1 |
2 | 49 |
*/ |
50 |
public class Clipboard { |
|
51 |
||
52 |
String name; |
|
53 |
||
22281
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
54 |
/** |
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
55 |
* The owner of the clipboard. |
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
56 |
*/ |
2 | 57 |
protected ClipboardOwner owner; |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
58 |
|
22281
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
59 |
/** |
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
60 |
* Contents of the clipboard. |
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
61 |
*/ |
2 | 62 |
protected Transferable contents; |
63 |
||
64 |
/** |
|
65 |
* An aggregate of flavor listeners registered on this local clipboard. |
|
66 |
* |
|
67 |
* @since 1.5 |
|
68 |
*/ |
|
24172
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
69 |
private Set<FlavorListener> flavorListeners; |
2 | 70 |
|
71 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
72 |
* A set of {@code DataFlavor}s that is available on this local clipboard. |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
73 |
* It is used for tracking changes of {@code DataFlavor}s available on this |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
74 |
* clipboard. |
2 | 75 |
* |
76 |
* @since 1.5 |
|
77 |
*/ |
|
15994
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
12813
diff
changeset
|
78 |
private Set<DataFlavor> currentDataFlavors; |
2 | 79 |
|
80 |
/** |
|
81 |
* Creates a clipboard object. |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
82 |
* |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
83 |
* @param name for the clipboard |
2 | 84 |
* @see java.awt.Toolkit#getSystemClipboard |
85 |
*/ |
|
86 |
public Clipboard(String name) { |
|
87 |
this.name = name; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Returns the name of this clipboard object. |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
92 |
* |
22281
830790e8640d
8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents:
15994
diff
changeset
|
93 |
* @return the name of this clipboard object |
2 | 94 |
* @see java.awt.Toolkit#getSystemClipboard |
95 |
*/ |
|
96 |
public String getName() { |
|
97 |
return name; |
|
98 |
} |
|
99 |
||
100 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
101 |
* Sets the current contents of the clipboard to the specified transferable |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
102 |
* object and registers the specified clipboard owner as the owner of the |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
103 |
* new contents. |
2 | 104 |
* <p> |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
105 |
* If there is an existing owner different from the argument {@code owner}, |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
106 |
* that owner is notified that it no longer holds ownership of the clipboard |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
107 |
* contents via an invocation of {@code ClipboardOwner.lostOwnership()} on |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
108 |
* that owner. An implementation of {@code setContents()} is free not to |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
109 |
* invoke {@code lostOwnership()} directly from this method. For example, |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
110 |
* {@code lostOwnership()} may be invoked later on a different thread. The |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
111 |
* same applies to {@code FlavorListener}s registered on this clipboard. |
2 | 112 |
* <p> |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
113 |
* The method throws {@code IllegalStateException} if the clipboard is |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
114 |
* currently unavailable. For example, on some platforms, the system |
2 | 115 |
* clipboard is unavailable while it is accessed by another application. |
116 |
* |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
117 |
* @param contents the transferable object representing the clipboard |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
118 |
* content |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
119 |
* @param owner the object which owns the clipboard content |
2 | 120 |
* @throws IllegalStateException if the clipboard is currently unavailable |
121 |
* @see java.awt.Toolkit#getSystemClipboard |
|
122 |
*/ |
|
123 |
public synchronized void setContents(Transferable contents, ClipboardOwner owner) { |
|
124 |
final ClipboardOwner oldOwner = this.owner; |
|
125 |
final Transferable oldContents = this.contents; |
|
126 |
||
127 |
this.owner = owner; |
|
128 |
this.contents = contents; |
|
129 |
||
130 |
if (oldOwner != null && oldOwner != owner) { |
|
26010
9a3cf8ee0776
8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents:
24172
diff
changeset
|
131 |
DataFlavorUtil.getDesktopService().invokeOnEventThread(() -> |
9a3cf8ee0776
8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents:
24172
diff
changeset
|
132 |
oldOwner.lostOwnership(Clipboard.this, oldContents)); |
2 | 133 |
} |
134 |
fireFlavorsChanged(); |
|
135 |
} |
|
136 |
||
137 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
138 |
* Returns a transferable object representing the current contents of the |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
139 |
* clipboard. If the clipboard currently has no contents, it returns |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
140 |
* {@code null}. The parameter Object requestor is not currently used. The |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
141 |
* method throws {@code IllegalStateException} if the clipboard is currently |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
142 |
* unavailable. For example, on some platforms, the system clipboard is |
2 | 143 |
* unavailable while it is accessed by another application. |
144 |
* |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
145 |
* @param requestor the object requesting the clip data (not used) |
2 | 146 |
* @return the current transferable object on the clipboard |
147 |
* @throws IllegalStateException if the clipboard is currently unavailable |
|
148 |
* @see java.awt.Toolkit#getSystemClipboard |
|
149 |
*/ |
|
150 |
public synchronized Transferable getContents(Object requestor) { |
|
151 |
return contents; |
|
152 |
} |
|
153 |
||
154 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
155 |
* Returns an array of {@code DataFlavor}s in which the current contents of |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
156 |
* this clipboard can be provided. If there are no {@code DataFlavor}s |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
157 |
* available, this method returns a zero-length array. |
2 | 158 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
159 |
* @return an array of {@code DataFlavor}s in which the current contents of |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
160 |
* this clipboard can be provided |
2 | 161 |
* @throws IllegalStateException if this clipboard is currently unavailable |
162 |
* @since 1.5 |
|
163 |
*/ |
|
164 |
public DataFlavor[] getAvailableDataFlavors() { |
|
165 |
Transferable cntnts = getContents(null); |
|
166 |
if (cntnts == null) { |
|
167 |
return new DataFlavor[0]; |
|
168 |
} |
|
169 |
return cntnts.getTransferDataFlavors(); |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* Returns whether or not the current contents of this clipboard can be |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
174 |
* provided in the specified {@code DataFlavor}. |
2 | 175 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
176 |
* @param flavor the requested {@code DataFlavor} for the contents |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
177 |
* @return {@code true} if the current contents of this clipboard can be |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
178 |
* provided in the specified {@code DataFlavor}; {@code false} |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
179 |
* otherwise |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
180 |
* @throws NullPointerException if {@code flavor} is {@code null} |
2 | 181 |
* @throws IllegalStateException if this clipboard is currently unavailable |
182 |
* @since 1.5 |
|
183 |
*/ |
|
184 |
public boolean isDataFlavorAvailable(DataFlavor flavor) { |
|
185 |
if (flavor == null) { |
|
186 |
throw new NullPointerException("flavor"); |
|
187 |
} |
|
188 |
||
189 |
Transferable cntnts = getContents(null); |
|
190 |
if (cntnts == null) { |
|
191 |
return false; |
|
192 |
} |
|
193 |
return cntnts.isDataFlavorSupported(flavor); |
|
194 |
} |
|
195 |
||
196 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
197 |
* Returns an object representing the current contents of this clipboard in |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
198 |
* the specified {@code DataFlavor}. The class of the object returned is |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
199 |
* defined by the representation class of {@code flavor}. |
2 | 200 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
201 |
* @param flavor the requested {@code DataFlavor} for the contents |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
202 |
* @return an object representing the current contents of this clipboard in |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
203 |
* the specified {@code DataFlavor} |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
204 |
* @throws NullPointerException if {@code flavor} is {@code null} |
2 | 205 |
* @throws IllegalStateException if this clipboard is currently unavailable |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
206 |
* @throws UnsupportedFlavorException if the requested {@code DataFlavor} is |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
207 |
* not available |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
208 |
* @throws IOException if the data in the requested {@code DataFlavor} can |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
209 |
* not be retrieved |
2 | 210 |
* @see DataFlavor#getRepresentationClass |
211 |
* @since 1.5 |
|
212 |
*/ |
|
213 |
public Object getData(DataFlavor flavor) |
|
214 |
throws UnsupportedFlavorException, IOException { |
|
215 |
if (flavor == null) { |
|
216 |
throw new NullPointerException("flavor"); |
|
217 |
} |
|
218 |
||
219 |
Transferable cntnts = getContents(null); |
|
220 |
if (cntnts == null) { |
|
221 |
throw new UnsupportedFlavorException(flavor); |
|
222 |
} |
|
223 |
return cntnts.getTransferData(flavor); |
|
224 |
} |
|
225 |
||
226 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
227 |
* Registers the specified {@code FlavorListener} to receive |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
228 |
* {@code FlavorEvent}s from this clipboard. If {@code listener} is |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
229 |
* {@code null}, no exception is thrown and no action is performed. |
2 | 230 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
231 |
* @param listener the listener to be added |
2 | 232 |
* @see #removeFlavorListener |
233 |
* @see #getFlavorListeners |
|
234 |
* @see FlavorListener |
|
235 |
* @see FlavorEvent |
|
236 |
* @since 1.5 |
|
237 |
*/ |
|
238 |
public synchronized void addFlavorListener(FlavorListener listener) { |
|
239 |
if (listener == null) { |
|
240 |
return; |
|
241 |
} |
|
24172
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
242 |
|
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
243 |
if (flavorListeners == null) { |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
244 |
flavorListeners = new HashSet<>(); |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
245 |
currentDataFlavors = getAvailableDataFlavorSet(); |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
246 |
} |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
247 |
|
2 | 248 |
flavorListeners.add(listener); |
249 |
} |
|
250 |
||
251 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
252 |
* Removes the specified {@code FlavorListener} so that it no longer |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
253 |
* receives {@code FlavorEvent}s from this {@code Clipboard}. This method |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
254 |
* performs no function, nor does it throw an exception, if the listener |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
255 |
* specified by the argument was not previously added to this |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
256 |
* {@code Clipboard}. If {@code listener} is {@code null}, no exception is |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
257 |
* thrown and no action is performed. |
2 | 258 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
259 |
* @param listener the listener to be removed |
2 | 260 |
* @see #addFlavorListener |
261 |
* @see #getFlavorListeners |
|
262 |
* @see FlavorListener |
|
263 |
* @see FlavorEvent |
|
264 |
* @since 1.5 |
|
265 |
*/ |
|
266 |
public synchronized void removeFlavorListener(FlavorListener listener) { |
|
24172
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
267 |
if (listener == null || flavorListeners == null) { |
2 | 268 |
return; |
269 |
} |
|
270 |
flavorListeners.remove(listener); |
|
271 |
} |
|
272 |
||
273 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
274 |
* Returns an array of all the {@code FlavorListener}s currently registered |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
275 |
* on this {@code Clipboard}. |
2 | 276 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
277 |
* @return all of this clipboard's {@code FlavorListener}s or an empty array |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
278 |
* if no listeners are currently registered |
2 | 279 |
* @see #addFlavorListener |
280 |
* @see #removeFlavorListener |
|
281 |
* @see FlavorListener |
|
282 |
* @see FlavorEvent |
|
283 |
* @since 1.5 |
|
284 |
*/ |
|
285 |
public synchronized FlavorListener[] getFlavorListeners() { |
|
24172
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
286 |
return flavorListeners == null ? new FlavorListener[0] : |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
287 |
flavorListeners.toArray(new FlavorListener[flavorListeners.size()]); |
2 | 288 |
} |
289 |
||
290 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
291 |
* Checks change of the {@code DataFlavor}s and, if necessary, notifies all |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
292 |
* listeners that have registered interest for notification on |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
293 |
* {@code FlavorEvent}s. |
2 | 294 |
* |
295 |
* @since 1.5 |
|
296 |
*/ |
|
297 |
private void fireFlavorsChanged() { |
|
24172
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
298 |
if (flavorListeners == null) { |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
299 |
return; |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
300 |
} |
814fb69fa9a5
8039752: Regression: Clipboard couldn't be used on linux
pchelko
parents:
24153
diff
changeset
|
301 |
|
15994
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
12813
diff
changeset
|
302 |
Set<DataFlavor> prevDataFlavors = currentDataFlavors; |
2 | 303 |
currentDataFlavors = getAvailableDataFlavorSet(); |
24153
2c19973ab9f2
6463901: Either generify or deprecate sun.awt.EventListenerAggregate
pchelko
parents:
22281
diff
changeset
|
304 |
if (Objects.equals(prevDataFlavors, currentDataFlavors)) { |
2 | 305 |
return; |
306 |
} |
|
24153
2c19973ab9f2
6463901: Either generify or deprecate sun.awt.EventListenerAggregate
pchelko
parents:
22281
diff
changeset
|
307 |
flavorListeners.forEach(listener -> |
26010
9a3cf8ee0776
8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents:
24172
diff
changeset
|
308 |
DataFlavorUtil.getDesktopService().invokeOnEventThread(() -> |
24153
2c19973ab9f2
6463901: Either generify or deprecate sun.awt.EventListenerAggregate
pchelko
parents:
22281
diff
changeset
|
309 |
listener.flavorsChanged(new FlavorEvent(Clipboard.this)))); |
2 | 310 |
} |
311 |
||
312 |
/** |
|
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
313 |
* Returns a set of {@code DataFlavor}s currently available on this |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
314 |
* clipboard. |
2 | 315 |
* |
45655
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
316 |
* @return a set of {@code DataFlavor}s currently available on this |
02c95aa8a53a
8180889: Cleanup of javadoc in java.datatransfer module
serb
parents:
45434
diff
changeset
|
317 |
* clipboard |
2 | 318 |
* @since 1.5 |
319 |
*/ |
|
15994
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
12813
diff
changeset
|
320 |
private Set<DataFlavor> getAvailableDataFlavorSet() { |
5c8a3d840366
8007295: Reduce number of warnings in awt classes
mcherkas
parents:
12813
diff
changeset
|
321 |
Set<DataFlavor> set = new HashSet<>(); |
2 | 322 |
Transferable contents = getContents(null); |
323 |
if (contents != null) { |
|
324 |
DataFlavor[] flavors = contents.getTransferDataFlavors(); |
|
325 |
if (flavors != null) { |
|
326 |
set.addAll(Arrays.asList(flavors)); |
|
327 |
} |
|
328 |
} |
|
329 |
return set; |
|
330 |
} |
|
331 |
} |