View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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   /* baseObjectFlavor is a vector */
38   public static DataFlavor baseObjectFlavor = new DataFlavor(Vector.class , "Vector");
39  
40   /* The string dataFlavor */
41   static private DataFlavor stringFlavor = new DataFlavor(String.class , "String");
42  
43   /* Supported flavors */
44   private DataFlavor [] supportedFlavors = { baseObjectFlavor, stringFlavor };
45  
46   /* The current object view */
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 }