1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.devaki.nextobjects.workspace.models.graphics;
22
23 import java.awt.datatransfer.Clipboard;
24 import java.awt.datatransfer.DataFlavor;
25 import java.awt.datatransfer.Transferable;
26 import java.awt.datatransfer.UnsupportedFlavorException;
27 import java.util.Vector;
28
29
30 /***
31 * This class represent a group of selectioned objects
32 * This could be a string or a list of objects
33 * @author eflorent
34 */
35 public class ObjectSelection implements Transferable
36 {
37
38 public static DataFlavor baseObjectFlavor = new DataFlavor(Vector.class , "Vector");
39
40
41 static private DataFlavor stringFlavor = new DataFlavor(String.class , "String");
42
43
44 private DataFlavor [] supportedFlavors = { baseObjectFlavor, stringFlavor };
45
46
47 private Object view;
48
49
50 /***
51 * Construct a selection
52 * @param pView a vector of object views
53 */
54 public ObjectSelection(Vector pView)
55 {
56 view = pView;
57 }
58
59
60 /***
61 * Construct a selection
62 * @param pString a String
63 */
64 public ObjectSelection(String pString)
65 {
66 view = pString;
67 }
68
69
70 /***
71 * Get the supported flavors
72 * @return supported dataflavors as an array
73 */
74 public synchronized DataFlavor[] getTransferDataFlavors()
75 {
76 return (supportedFlavors);
77 }
78
79
80 /***
81 * Check if this dataflavor is supported
82 * @param parFlavor the flavor
83 * @return true if supported
84 */
85 public boolean isDataFlavorSupported(DataFlavor parFlavor)
86 {
87 return (parFlavor.equals(baseObjectFlavor));
88 }
89
90
91 /***
92 * Get the data for a given dataflavor
93 * @param parFlavor the dataflavor
94 * @return the object
95 */
96 public synchronized Object getTransferData(DataFlavor parFlavor)
97 throws UnsupportedFlavorException
98 {
99 if (parFlavor.equals (baseObjectFlavor))
100 return view;
101 else
102 throw new UnsupportedFlavorException(baseObjectFlavor);
103 }
104
105
106 /***
107 * The clipboard lost ownership
108 * @param parClipboard the clipboard
109 * @param parTransferable the object
110 */
111 public void lostOwnership(Clipboard parClipboard, Transferable parTransferable)
112 {
113 System.out.println ("Lost ownership");
114 }
115 }