Source code: com/virtuosotechnologies/asaph/modelutils/TransferableImpl.java
1 /*
2 ================================================================================
3
4 FILE: TransferableImpl.java
5
6 PROJECT:
7
8 Asaph
9
10 CONTENTS:
11
12 Transferable implementation
13
14 PROGRAMMERS:
15
16 Daniel Azuma (DA) <dazuma@kagi.com>
17
18 COPYRIGHT:
19
20 Copyright (C) 2003 Daniel Azuma (dazuma@kagi.com)
21
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public
33 License along with this program; if not, write to
34 Free Software Foundation, Inc.
35 59 Temple Place, Suite 330
36 Boston, MA 02111-1307 USA
37
38 ================================================================================
39 */
40
41
42 package com.virtuosotechnologies.asaph.modelutils;
43
44
45 import java.awt.datatransfer.Transferable;
46 import java.awt.datatransfer.DataFlavor;
47 import java.awt.datatransfer.UnsupportedFlavorException;
48 import java.io.IOException;
49
50 import com.virtuosotechnologies.asaph.model.Song;
51 import com.virtuosotechnologies.asaph.modelutils.impl.LineFragmentData;
52 import com.virtuosotechnologies.asaph.modelutils.impl.LineListData;
53 import com.virtuosotechnologies.asaph.modelutils.impl.BlockListData;
54
55
56 /**
57 * Transferable implementation
58 */
59 /*package*/ class TransferableImpl
60 implements Transferable
61 {
62 private Object data_;
63 private Song song_;
64
65
66 /*package*/ TransferableImpl(
67 LineFragmentData data,
68 Song song)
69 {
70 if (data == null)
71 {
72 throw new NullPointerException();
73 }
74 data_ = data;
75 song_ = song;
76 }
77
78
79 /*package*/ TransferableImpl(
80 LineListData data,
81 Song song)
82 {
83 if (data == null)
84 {
85 throw new NullPointerException();
86 }
87 data_ = data;
88 song_ = song;
89 }
90
91
92 /*package*/ TransferableImpl(
93 BlockListData data,
94 Song song)
95 {
96 if (data == null)
97 {
98 throw new NullPointerException();
99 }
100 data_ = data;
101 song_ = song;
102 }
103
104
105 /*package*/ TransferableImpl(
106 Transferable delegate,
107 Song song)
108 {
109 if (delegate == null)
110 {
111 throw new NullPointerException();
112 }
113 data_ = delegate;
114 song_ = song;
115 }
116
117
118 /*package*/ Song getSong()
119 {
120 return song_;
121 }
122
123
124 public Object getTransferData(
125 DataFlavor flavor)
126 throws
127 UnsupportedFlavorException,
128 IOException
129 {
130 if (data_ instanceof Transferable)
131 {
132 return ((Transferable)data_).getTransferData(flavor);
133 }
134 if (flavor.equals(DataFlavor.stringFlavor))
135 {
136 if (data_ instanceof LineFragmentData)
137 {
138 return ((LineFragmentData)data_).createStringRepresentation();
139 }
140 else if (data_ instanceof LineListData)
141 {
142 return ((LineListData)data_).createStringRepresentation();
143 }
144 else
145 {
146 assert data_ instanceof BlockListData;
147 return ((BlockListData)data_).createStringRepresentation();
148 }
149 }
150 else if (flavor.equals(DataTransferUtils.LINEFRAGMENT_FLAVOR))
151 {
152 if (data_ instanceof LineFragmentData)
153 {
154 return data_;
155 }
156 }
157 else if (flavor.equals(DataTransferUtils.LINELIST_FLAVOR))
158 {
159 if (data_ instanceof LineListData)
160 {
161 return data_;
162 }
163 }
164 else if (flavor.equals(DataTransferUtils.BLOCKLIST_FLAVOR))
165 {
166 if (data_ instanceof BlockListData)
167 {
168 return data_;
169 }
170 }
171 throw new UnsupportedFlavorException(flavor);
172 }
173
174
175 public DataFlavor[] getTransferDataFlavors()
176 {
177 if (data_ instanceof Transferable)
178 {
179 return ((Transferable)data_).getTransferDataFlavors();
180 }
181 DataFlavor[] ret = new DataFlavor[2];
182 if (data_ instanceof LineFragmentData)
183 {
184 ret[0] = DataTransferUtils.LINEFRAGMENT_FLAVOR;
185 }
186 else if (data_ instanceof LineListData)
187 {
188 ret[0] = DataTransferUtils.LINELIST_FLAVOR;
189 }
190 else
191 {
192 assert data_ instanceof BlockListData;
193 ret[0] = DataTransferUtils.BLOCKLIST_FLAVOR;
194 }
195 ret[1] = DataFlavor.stringFlavor;
196 return ret;
197 }
198
199
200 public boolean isDataFlavorSupported(
201 DataFlavor flavor)
202 {
203 if (data_ instanceof Transferable)
204 {
205 return ((Transferable)data_).isDataFlavorSupported(flavor);
206 }
207 if (flavor.equals(DataFlavor.stringFlavor))
208 {
209 return true;
210 }
211 if (flavor.equals(DataTransferUtils.LINEFRAGMENT_FLAVOR))
212 {
213 return data_ instanceof LineFragmentData;
214 }
215 if (flavor.equals(DataTransferUtils.LINELIST_FLAVOR))
216 {
217 return data_ instanceof LineListData;
218 }
219 if (flavor.equals(DataTransferUtils.BLOCKLIST_FLAVOR))
220 {
221 return data_ instanceof BlockListData;
222 }
223 return false;
224 }
225 }