KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > dnd > Transfer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.dnd;
12
13  
14 import org.eclipse.swt.internal.win32.*;
15
16 /**
17  * <code>Transfer</code> provides a mechanism for converting between a java
18  * representation of data and a platform specific representation of data and
19  * vice versa. It is used in data transfer operations such as drag and drop and
20  * clipboard copy/paste.
21  *
22  * <p>You should only need to become familiar with this class if you are
23  * implementing a Transfer subclass and you are unable to subclass the
24  * ByteArrayTransfer class.</p>
25  *
26  * @see ByteArrayTransfer
27  */

28 public abstract class Transfer {
29     
30 /**
31  * Returns a list of the platform specific data types that can be converted using
32  * this transfer agent.
33  *
34  * <p>Only the data type fields of the <code>TransferData</code> objects are filled
35  * in.</p>
36  *
37  * @return a list of the data types that can be converted using this transfer agent
38  */

39 abstract public TransferData[] getSupportedTypes();
40
41 /**
42  * Returns true if the <code>TransferData</code> data type can be converted
43  * using this transfer agent, or false otherwise (including if transferData is
44  * <code>null</code>).
45  *
46  * @param transferData a platform specific description of a data type; only the data
47  * type fields of the <code>TransferData</code> object need to be filled in
48  *
49  * @return true if the transferData data type can be converted using this transfer
50  * agent
51  */

52 abstract public boolean isSupportedType(TransferData transferData);
53
54 /**
55  * Returns the platform specific ids of the data types that can be converted using
56  * this transfer agent.
57  *
58  * @return the platform specific ids of the data types that can be converted using
59  * this transfer agent
60  */

61 abstract protected int[] getTypeIds();
62
63 /**
64  * Returns the platform specific names of the data types that can be converted
65  * using this transfer agent.
66  *
67  * @return the platform specific names of the data types that can be converted
68  * using this transfer agent.
69  */

70 abstract protected String JavaDoc[] getTypeNames();
71
72 /**
73  * Converts a java representation of data to a platform specific representation of
74  * the data.
75  *
76  * <p>On a successful conversion, the transferData.result field will be set as follows:
77  * <ul>
78  * <li>Windows: COM.S_OK
79  * <li>Motif: 1
80  * <li>GTK: 1
81  * <li>Photon: 1
82  * </ul></p>
83  *
84  * <p>If this transfer agent is unable to perform the conversion, the transferData.result
85  * field will be set to a failure value as follows:
86  * <ul>
87  * <li>Windows: COM.DV_E_TYMED or COM.E_FAIL
88  * <li>Motif: 0
89  * <li>GTK: 0
90  * <li>Photon: 0
91  * </ul></p>
92  *
93  * @param object a java representation of the data to be converted; the type of
94  * Object that is passed in is dependent on the <code>Transfer</code> subclass.
95  *
96  * @param transferData an empty TransferData object; this object will be
97  * filled in on return with the platform specific representation of the data
98  *
99  * @exception org.eclipse.swt.SWTException <ul>
100  * <li>ERROR_INVALID_DATA - if object does not contain data in a valid format or is <code>null</code></li>
101  * </ul>
102  */

103 abstract protected void javaToNative (Object JavaDoc object, TransferData transferData);
104
105 /**
106  * Converts a platform specific representation of data to a java representation.
107  *
108  * @param transferData the platform specific representation of the data to be
109  * converted
110  *
111  * @return a java representation of the converted data if the conversion was
112  * successful; otherwise null. If transferData is <code>null</code> then
113  * <code>null</code> is returned. The type of Object that is returned is
114  * dependent on the <code>Transfer</code> subclass.
115  */

116 abstract protected Object JavaDoc nativeToJava(TransferData transferData);
117
118 /**
119  * Registers a name for a data type and returns the associated unique identifier.
120  *
121  * <p>You may register the same type more than once, the same unique identifier
122  * will be returned if the type has been previously registered.</p>
123  *
124  * <p>Note: On windows, do <b>not</b> call this method with pre-defined
125  * Clipboard Format types such as CF_TEXT or CF_BITMAP because the
126  * pre-defined identifier will not be returned</p>
127  *
128  * @param formatName the name of a data type
129  *
130  * @return the unique identifier associated with this data type
131  */

132 public static int registerType(String JavaDoc formatName) {
133     // Look name up in the registry
134
// If name is not in registry, add it and return assigned value.
135
// If name already exists in registry, return its assigned value
136
TCHAR chFormatName = new TCHAR(0, formatName, true);
137     return OS.RegisterClipboardFormat(chFormatName);
138 }
139
140 /**
141  * Test that the object is of the correct format for this Transfer class.
142  *
143  * @param object a java representation of the data to be converted
144  *
145  * @return true if object is of the correct form for this transfer type
146  *
147  * @since 3.1
148  */

149 protected boolean validate(Object JavaDoc object) {
150     return true;
151 }
152 }
153
Popular Tags