comparison dwt/dnd/Transfer.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 380af2bdd8e5
children a7e41c09df9e
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/ 10 *******************************************************************************/
11 module dwt.dnd; 11 module dwt.dnd.Transfer;
12
13 import dwt.dwthelper.utils;
12 14
13 15
14 /** 16 /**
15 * <code>Transfer</code> provides a mechanism for converting between a java 17 * <code>Transfer</code> provides a mechanism for converting between a java
16 * representation of data and a platform specific representation of data and 18 * representation of data and a platform specific representation of data and
20 * <p>You should only need to become familiar with this class if you are 22 * <p>You should only need to become familiar with this class if you are
21 * implementing a Transfer subclass and you are unable to subclass the 23 * implementing a Transfer subclass and you are unable to subclass the
22 * ByteArrayTransfer class.</p> 24 * ByteArrayTransfer class.</p>
23 * 25 *
24 * @see ByteArrayTransfer 26 * @see ByteArrayTransfer
27 * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
28 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: DNDExample</a>
29 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
25 */ 30 */
26 public abstract class Transfer { 31 public abstract class Transfer {
27 32
33 static String[] TYPES = new String[4];
34
28 /** 35 /**
29 * Returns a list of the platform specific data types that can be converted using 36 * Returns a list of the platform specific data types that can be converted using
30 * this transfer agent. 37 * this transfer agent.
31 * 38 *
32 * <p>Only the data type fields of the <code>TransferData</code> objects are filled 39 * <p>Only the data type fields of the <code>TransferData</code> objects are filled
126 * @param formatName the name of a data type 133 * @param formatName the name of a data type
127 * 134 *
128 * @return the unique identifier associated with this data type 135 * @return the unique identifier associated with this data type
129 */ 136 */
130 public static int registerType(String formatName) { 137 public static int registerType(String formatName) {
131 int length = formatName.length(); 138 /* Note the type 0 is not used */
132 // TODO - hashcode may not be unique - need another way 139 int index = 1;
133 if (length > 4) return formatName.toHash(); 140 while (index < TYPES.length) {
134 int type = 0; 141 String type = TYPES[index];
135 if (length > 0) type |= (formatName.charAt(0) & 0xff) << 24; 142 if (type !is null && formatName.equals(type)) {
136 if (length > 1) type |= (formatName.charAt(1) & 0xff) << 16; 143 return index;
137 if (length > 2) type |= (formatName.charAt(2) & 0xff) << 8; 144 }
138 if (length > 3) type |= formatName.charAt(3) & 0xff; 145 index++;
139 return type; 146 }
147 if (index is TYPES.length) {
148 String[] newTypes = new String[TYPES.length + 4];
149 System.arraycopy(TYPES, 0, newTypes, 0, TYPES.length);
150 TYPES = newTypes;
151 }
152 TYPES[index] = formatName;
153 return index;
140 } 154 }
141 155
142 /** 156 /**
143 * Test that the object is of the correct format for this Transfer class. 157 * Test that the object is of the correct format for this Transfer class.
144 * 158 *