38 |
|
|
39 |
package java.awt.datatransfer; |
package java.awt.datatransfer; |
40 |
|
|
41 |
|
import java.util.ArrayList; |
42 |
import java.util.HashMap; |
import java.util.HashMap; |
43 |
import java.util.List; |
import java.util.List; |
44 |
import java.util.Map; |
import java.util.Map; |
60 |
* <code>SystemFlavorMaps</code>. |
* <code>SystemFlavorMaps</code>. |
61 |
*/ |
*/ |
62 |
private static final Map systemFlavorMaps = new WeakHashMap(); |
private static final Map systemFlavorMaps = new WeakHashMap(); |
63 |
|
|
64 |
|
/** |
65 |
|
* This map maps native <code>String</code>s to lists of |
66 |
|
* <code>DataFlavor</code>s |
67 |
|
*/ |
68 |
|
private Map nativeToFlavorMap = new HashMap(); |
69 |
|
|
70 |
|
/** |
71 |
|
* This map maps <code>DataFlavor</code>s to lists of native |
72 |
|
* <code>String</code>s |
73 |
|
*/ |
74 |
|
private Map flavorToNativeMap = new HashMap(); |
75 |
|
|
76 |
/** |
/** |
77 |
* Private constructor. |
* Private constructor. |
197 |
{ |
{ |
198 |
throw new Error ("Not implemented"); |
throw new Error ("Not implemented"); |
199 |
} |
} |
200 |
|
|
201 |
|
/** |
202 |
|
* Adds a mapping from a single <code>String</code> native to a single |
203 |
|
* <code>DataFlavor</code>. Unlike <code>getFlavorsForNative</code>, the |
204 |
|
* mapping will only be established in one direction, and the native will |
205 |
|
* not be encoded. To establish a two-way mapping, call |
206 |
|
* <code>addUnencodedNativeForFlavor</code> as well. The new mapping will |
207 |
|
* be of lower priority than any existing mapping. |
208 |
|
* This method has no effect if a mapping from the specified |
209 |
|
* <code>String</code> native to the specified or equal |
210 |
|
* <code>DataFlavor</code> already exists. |
211 |
|
* |
212 |
|
* @param nativeStr the <code>String</code> native key for the mapping |
213 |
|
* @param flavor the <code>DataFlavor</code> value for the mapping |
214 |
|
* @throws NullPointerException if nat or flav is <code>null</code> |
215 |
|
* |
216 |
|
* @see #addUnencodedNativeForFlavor |
217 |
|
* @since 1.4 |
218 |
|
*/ |
219 |
|
public synchronized void addFlavorForUnencodedNative(String nativeStr, |
220 |
|
DataFlavor flavor) |
221 |
|
{ |
222 |
|
if((nativeStr == null) || (flavor == null)) |
223 |
|
throw new NullPointerException(); |
224 |
|
List flavors = (List) nativeToFlavorMap.get(nativeStr); |
225 |
|
if(flavors == null) |
226 |
|
{ |
227 |
|
flavors = new ArrayList(); |
228 |
|
nativeToFlavorMap.put(nativeStr, flavors); |
229 |
|
} |
230 |
|
else |
231 |
|
{ |
232 |
|
if(!flavors.contains(flavor)) |
233 |
|
flavors.add(flavor); |
234 |
|
} |
235 |
|
} |
236 |
|
|
237 |
|
/** |
238 |
|
* Adds a mapping from the specified <code>DataFlavor</code> (and all |
239 |
|
* <code>DataFlavor</code>s equal to the specified <code>DataFlavor</code>) |
240 |
|
* to the specified <code>String</code> native. |
241 |
|
* Unlike <code>getNativesForFlavor</code>, the mapping will only be |
242 |
|
* established in one direction, and the native will not be encoded. To |
243 |
|
* establish a two-way mapping, call |
244 |
|
* <code>addFlavorForUnencodedNative</code> as well. The new mapping will |
245 |
|
* be of lower priority than any existing mapping. |
246 |
|
* This method has no effect if a mapping from the specified or equal |
247 |
|
* <code>DataFlavor</code> to the specified <code>String</code> native |
248 |
|
* already exists. |
249 |
|
* |
250 |
|
* @param flavor the <code>DataFlavor</code> key for the mapping |
251 |
|
* @param nativeStr the <code>String</code> native value for the mapping |
252 |
|
* @throws NullPointerException if flav or nat is <code>null</code> |
253 |
|
* |
254 |
|
* @see #addFlavorForUnencodedNative |
255 |
|
* @since 1.4 |
256 |
|
*/ |
257 |
|
public synchronized void addUnencodedNativeForFlavor(DataFlavor flavor, |
258 |
|
String nativeStr) |
259 |
|
{ |
260 |
|
if((nativeStr == null) || (flavor == null)) |
261 |
|
throw new NullPointerException(); |
262 |
|
List natives = (List) flavorToNativeMap.get(flavor); |
263 |
|
if(natives == null) |
264 |
|
{ |
265 |
|
natives = new ArrayList(); |
266 |
|
flavorToNativeMap.put(flavor, natives); |
267 |
|
} |
268 |
|
else |
269 |
|
{ |
270 |
|
if(!natives.contains(nativeStr)) |
271 |
|
natives.add(nativeStr); |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
|
/** |
276 |
|
* Discards the current mappings for the specified <code>DataFlavor</code> |
277 |
|
* and all <code>DataFlavor</code>s equal to the specified |
278 |
|
* <code>DataFlavor</code>, and creates new mappings to the |
279 |
|
* specified <code>String</code> natives. |
280 |
|
* Unlike <code>getNativesForFlavor</code>, the mappings will only be |
281 |
|
* established in one direction, and the natives will not be encoded. To |
282 |
|
* establish two-way mappings, call <code>setFlavorsForNative</code> |
283 |
|
* as well. The first native in the array will represent the highest |
284 |
|
* priority mapping. Subsequent natives will represent mappings of |
285 |
|
* decreasing priority. |
286 |
|
* <p> |
287 |
|
* If the array contains several elements that reference equal |
288 |
|
* <code>String</code> natives, this method will establish new mappings |
289 |
|
* for the first of those elements and ignore the rest of them. |
290 |
|
* <p> |
291 |
|
* It is recommended that client code not reset mappings established by the |
292 |
|
* data transfer subsystem. This method should only be used for |
293 |
|
* application-level mappings. |
294 |
|
* |
295 |
|
* @param flavor the <code>DataFlavor</code> key for the mappings |
296 |
|
* @param natives the <code>String</code> native values for the mappings |
297 |
|
* @throws NullPointerException if flav or natives is <code>null</code> |
298 |
|
* or if natives contains <code>null</code> elements |
299 |
|
* |
300 |
|
* @see #setFlavorsForNative |
301 |
|
* @since 1.4 |
302 |
|
*/ |
303 |
|
public synchronized void setNativesForFlavor(DataFlavor flavor, |
304 |
|
String[] natives) |
305 |
|
{ |
306 |
|
if((natives == null) || (flavor == null)) |
307 |
|
throw new NullPointerException(); |
308 |
|
|
309 |
|
flavorToNativeMap.remove(flavor); |
310 |
|
for(int i = 0; i < natives.length; i++) |
311 |
|
{ |
312 |
|
addUnencodedNativeForFlavor(flavor, natives[i]); |
313 |
|
} |
314 |
|
} |
315 |
|
|
316 |
|
/** |
317 |
|
* Discards the current mappings for the specified <code>String</code> |
318 |
|
* native, and creates new mappings to the specified |
319 |
|
* <code>DataFlavor</code>s. Unlike <code>getFlavorsForNative</code>, the |
320 |
|
* mappings will only be established in one direction, and the natives need |
321 |
|
* not be encoded. To establish two-way mappings, call |
322 |
|
* <code>setNativesForFlavor</code> as well. The first |
323 |
|
* <code>DataFlavor</code> in the array will represent the highest priority |
324 |
|
* mapping. Subsequent <code>DataFlavor</code>s will represent mappings of |
325 |
|
* decreasing priority. |
326 |
|
* <p> |
327 |
|
* If the array contains several elements that reference equal |
328 |
|
* <code>DataFlavor</code>s, this method will establish new mappings |
329 |
|
* for the first of those elements and ignore the rest of them. |
330 |
|
* <p> |
331 |
|
* It is recommended that client code not reset mappings established by the |
332 |
|
* data transfer subsystem. This method should only be used for |
333 |
|
* application-level mappings. |
334 |
|
* |
335 |
|
* @param nativeStr the <code>String</code> native key for the mappings |
336 |
|
* @param flavors the <code>DataFlavor</code> values for the mappings |
337 |
|
* @throws NullPointerException if nat or flavors is <code>null</code> |
338 |
|
* or if flavors contains <code>null</code> elements |
339 |
|
* |
340 |
|
* @see #setNativesForFlavor |
341 |
|
* @since 1.4 |
342 |
|
*/ |
343 |
|
public synchronized void setFlavorsForNative(String nativeStr, |
344 |
|
DataFlavor[] flavors) |
345 |
|
{ |
346 |
|
if((nativeStr == null) || (flavors == null)) |
347 |
|
throw new NullPointerException(); |
348 |
|
|
349 |
|
nativeToFlavorMap.remove(nativeStr); |
350 |
|
for(int i = 0; i < flavors.length; i++) |
351 |
|
{ |
352 |
|
addFlavorForUnencodedNative(nativeStr, flavors[i]); |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
} // class SystemFlavorMap |
} // class SystemFlavorMap |