diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd')
16 files changed, 106 insertions, 33 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ByteArrayTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ByteArrayTransfer.java index c138c1c0e8..bb4585bc4c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ByteArrayTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ByteArrayTransfer.java @@ -114,6 +114,8 @@ package org.eclipse.swt.dnd; * } * } * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public abstract class ByteArrayTransfer extends Transfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Clipboard.java index fc4839d51b..93b3626411 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Clipboard.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Clipboard.java @@ -20,6 +20,10 @@ import org.eclipse.swt.internal.carbon.OS; * application to another or within an application. * * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#clipboard">Clipboard snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ClipboardExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class Clipboard { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java index b537aafe35..c56ebcafca 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DragSource.java @@ -95,6 +95,10 @@ import org.eclipse.swt.internal.carbon.Point; * <dt><b>Styles</b></dt> <dd>DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK</dd> * <dt><b>Events</b></dt> <dd>DND.DragStart, DND.DragSetData, DND.DragEnd</dd> * </dl> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class DragSource extends Widget { @@ -229,6 +233,7 @@ static DragSource FindDragSource(int dragSendRefCon, int theDrag) { * </ul> * * @see DragSourceListener + * @see #getDragListeners * @see #removeDragListener * @see DragSourceEvent */ @@ -405,6 +410,9 @@ public Control getControl () { * operation is in progress, by sending it one of the messages defined in * the <code>DragSourceListener</code> interface. * + * @return the listeners who will be notified when a drag and drop + * operation is in progress + * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -510,7 +518,7 @@ int osOpToOp(int osOperation){ * Removes the listener from the collection of listeners who will * be notified when a drag and drop operation is in progress. * - * @param listener the listener which should be notified + * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> @@ -522,6 +530,7 @@ int osOpToOp(int osOperation){ * * @see DragSourceListener * @see #addDragListener + * @see #getDragListeners */ public void removeDragListener(DragSourceListener listener) { if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java index 227f9c417a..7b7df10f26 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/DropTarget.java @@ -66,6 +66,10 @@ import org.eclipse.swt.internal.carbon.*; * <dt><b>Events</b></dt> <dd>DND.DragEnter, DND.DragLeave, DND.DragOver, DND.DragOperationChanged, * DND.DropAccept, DND.Drop </dd> * </dl> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class DropTarget extends Widget { @@ -304,6 +308,7 @@ static DropTarget FindDropTarget(int theWindow, int theDrag) { * </ul> * * @see DropTargetListener + * @see #getDropListeners * @see #removeDropListener * @see DropTargetEvent */ @@ -524,6 +529,9 @@ public Control getControl () { * operation is in progress, by sending it one of the messages defined in * the <code>DropTargetListener</code> interface. * + * @return the listeners who will be notified when a drag and drop + * operation is in progress + * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> @@ -633,7 +641,7 @@ int osOpToOp(int osOperation){ * Removes the listener from the collection of listeners who will * be notified when a drag and drop operation is in progress. * - * @param listener the listener which should be notified + * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> @@ -645,6 +653,7 @@ int osOpToOp(int osOperation){ * * @see DropTargetListener * @see #addDropListener + * @see #getDropListeners */ public void removeDropListener(DropTargetListener listener) { if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/FileTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/FileTransfer.java index 91ed4251cd..ba7123a7b8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/FileTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/FileTransfer.java @@ -32,6 +32,8 @@ import org.eclipse.swt.internal.carbon.*; * fileData[0] = file1.getAbsolutePath(); * fileData[1] = file2.getAbsolutePath(); * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class FileTransfer extends ByteArrayTransfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/HTMLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/HTMLTransfer.java index 64e81d2fbb..142ea24c08 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/HTMLTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/HTMLTransfer.java @@ -24,6 +24,8 @@ import org.eclipse.swt.internal.carbon.OS; * <code><pre> * String htmlData = "<p>This is a paragraph of text.</p>"; * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class HTMLTransfer extends ByteArrayTransfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ImageTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ImageTransfer.java index 01add3417f..51155adce7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ImageTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/ImageTransfer.java @@ -17,21 +17,22 @@ import org.eclipse.swt.internal.carbon.*; import org.eclipse.swt.widgets.*; /** - * The class <code>ImageTransfer</code> provides a platform specific mechanism - * for converting an Image represented as a java <code>ImageData</code> to a - * platform specific representation of the data and vice versa. The - * <code>ImageData</code> contains infomration about the Image. See - * <code>Transfer</code> for additional information. + * The class <code>ImageTransfer</code> provides a platform specific mechanism + * for converting a Image represented as a java <code>ImageData</code> to a + * platform specific representation of the data and vice versa. + * See <code>Transfer</code> for additional information. * - * <p> - * An example of a java <code>Image</code> containing an ImageData is shown - * below: - * </p> + * <p>An example of a java <code>ImageData</code> is shown + * below:</p> * * <code><pre> - * Image image = new Image(display, fileName); - * ImageData imgData = image.getImageData(); + * Image image = new Image("C:\temp\img1.gif"); + * ImageData imgData = image.getImageData(); * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + * + * @since 3.4 */ public class ImageTransfer extends ByteArrayTransfer { @@ -46,7 +47,7 @@ ImageTransfer() { /** * Returns the singleton instance of the ImageTransfer class. - * + * * @return the singleton instance of the ImageTransfer class */ public static ImageTransfer getInstance() { @@ -54,17 +55,14 @@ public static ImageTransfer getInstance() { } /** - * This implementation of <code>javaToNative</code> converts an ImageData - * object represented by a java <code>ImageData</code> to a platform - * specific representation. For additional information see - * <code>Transfer#javaToNative</code>. + * This implementation of <code>javaToNative</code> converts an ImageData object represented + * by java <code>ImageData</code> to a platform specific representation. + * For additional information see <code>Transfer#javaToNative</code>. * - * @param object - * a java <code>ImageData</code> - * @param transferData - * an empty <code>TransferData</code> object; this object will - * be filled in on return with the platform specific format of - * the data + * @param object a java <code>ImageData</code> containing the ImageData to be + * converted + * @param transferData an empty <code>TransferData</code> object; this + * object will be filled in on return with the platform specific format of the data */ public void javaToNative(Object object, TransferData transferData) { if (!checkImage(object) || !isSupportedType(transferData)) { @@ -117,15 +115,14 @@ public void javaToNative(Object object, TransferData transferData) { } /** - * This implementation of <code>nativeToJava</code> converts a platform - * specific representation of an ImageData <code>ImageData</code>. For - * additional information see <code>Transfer#nativeToJava</code>. + * This implementation of <code>nativeToJava</code> converts a platform specific + * representation of an image to java <code>ImageData</code>. + * For additional information see <code>Transfer#nativeToJava</code>. * - * @param transferData - * the platform specific representation of the data to be been - * converted - * @return a java <code>ImageData</code> object if the conversion was - * successful; otherwise null + * @param transferData the platform specific representation of the data to be + * been converted + * @return a java <code>ImageData</code> of the image if + * conversion was successful; otherwise null */ public Object nativeToJava(TransferData transferData) { if (!isSupportedType(transferData) || transferData.data == null) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/RTFTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/RTFTransfer.java index fed105d0ce..a60bf238db 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/RTFTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/RTFTransfer.java @@ -25,6 +25,8 @@ import org.eclipse.swt.internal.carbon.CFRange; * <code><pre> * String rtfData = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i Hello World}"; * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class RTFTransfer extends ByteArrayTransfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java index 416864d6f5..634c82ac1c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDragSourceEffect.java @@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.*; * * @see DragSourceEffect * @see DragSourceEvent + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> * * @since 3.3 */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java index 1f8f804902..bbc69a1241 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TableDropTargetEffect.java @@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.*; * * @see DropTargetAdapter * @see DropTargetEvent + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> * * @since 3.3 */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TextTransfer.java index 0c9c0e7d05..4ff2324d09 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TextTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TextTransfer.java @@ -26,6 +26,7 @@ import org.eclipse.swt.internal.carbon.OS; * </code></pre> * * @see Transfer + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class TextTransfer extends ByteArrayTransfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Transfer.java index f5a8ee287e..a67930280e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Transfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/Transfer.java @@ -22,6 +22,9 @@ package org.eclipse.swt.dnd; * ByteArrayTransfer class.</p> * * @see ByteArrayTransfer + * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public abstract class Transfer { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TransferData.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TransferData.java index cd7e4248e7..da128c09df 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TransferData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TransferData.java @@ -24,6 +24,8 @@ package org.eclipse.swt.dnd; * <p>You should only need to become familiar with the fields in this class if you * are implementing a Transfer subclass and you are unable to subclass the * ByteArrayTransfer class.</p> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class TransferData { /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java index 97cd46f444..0d6d6d9949 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDragSourceEffect.java @@ -25,6 +25,7 @@ import org.eclipse.swt.widgets.*; * * @see DragSourceEffect * @see DragSourceEvent + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> * * @since 3.3 */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java index cb1f7e55cb..4728b5044e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/TreeDropTargetEffect.java @@ -46,6 +46,7 @@ import org.eclipse.swt.widgets.*; * * @see DropTargetAdapter * @see DropTargetEvent + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> * * @since 3.3 */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/URLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/URLTransfer.java index cfb53dfc03..a1e97aac13 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/URLTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/carbon/org/eclipse/swt/dnd/URLTransfer.java @@ -1 +1,37 @@ -/*******************************************************************************
* Copyright (c) 20007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.dnd;
import org.eclipse.swt.internal.carbon.*;
/**
* The class <code>URLTransfer</code> provides a platform specific mechanism
* for converting text in URL format represented as a java <code>String</code>
* to a platform specific representation of the data and vice versa. See
* <code>Transfer</code> for additional information. The string
* must contain the fully specified url.
*
* <p>An example of a java <code>String[]</code> containing a URL is shown
* below:</p>
*
* <code><pre>
* String url = "http://www.eclipse.org";
* </code></pre>
*/
public class URLTransfer extends ByteArrayTransfer {
static URLTransfer _instance = new URLTransfer();
static final String URL = "url "; //$NON-NLS-1$
static final int URL_ID = registerType(URL);
static final String URLN = "urln"; //$NON-NLS-1$
static final int URLN_ID = registerType(URLN);
private URLTransfer() {}
/**
* Returns the singleton instance of the URLTransfer class.
*
* @return the singleton instance of the URLTransfer class
*/
public static URLTransfer getInstance () {
return _instance;
}
/**
* This implementation of <code>javaToNative</code> converts a URL
* represented by a java <code>String</code> to a platform specific representation.
* For additional information see <code>Transfer#javaToNative</code>.
*
* @param object a java <code>String[]</code> containing a URL
* @param transferData an empty <code>TransferData</code> object; this
* object will be filled in on return with the platform specific format of the data
*/
public void javaToNative (Object object, TransferData transferData){
if (!checkURL(object) || !isSupportedType(transferData)) {
DND.error(DND.ERROR_INVALID_DATA);
}
transferData.result = -1;
String url = (String)object;
int count = url.length();
char[] chars = new char[count];
url.getChars(0, count, chars, 0);
int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, count);
if (cfstring == 0) return;
try {
CFRange range = new CFRange();
range.length = chars.length;
int encoding = OS.kCFStringEncodingUTF8;
int[] size = new int[1];
int numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, null, 0, size);
if (numChars == 0 || size[0] == 0) return;
byte[] buffer = new byte[size[0]];
numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, buffer, size [0], size);
if (numChars == 0) return;
transferData.data = new byte[][] {buffer};
transferData.result = 0;
} finally {
OS.CFRelease(cfstring);
}
}
/**
* This implementation of <code>nativeToJava</code> converts a platform specific
* representation of a URL to a java <code>String</code>.
* For additional information see <code>Transfer#nativeToJava</code>.
*
* @param transferData the platform specific representation of the data to be
* converted
* @return a java <code>String[]</code> containing a URL if the
* conversion was successful; otherwise null
*/
public Object nativeToJava(TransferData transferData){
if (!isSupportedType(transferData) || transferData.data == null) return null;
if (transferData.data.length == 0) return null;
byte[] buffer = transferData.data[0];
int encoding = OS.kCFStringEncodingUTF8;
int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true);
if (cfstring == 0) return null;
char[] unescapedChars = new char[] {'%'};
int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length);
int str = OS.CFURLCreateStringByReplacingPercentEscapes(OS.kCFAllocatorDefault, cfstring, unescapedStr);
OS.CFRelease(unescapedStr);
OS.CFRelease(cfstring);
if (str == 0) return null;
try {
int length = OS.CFStringGetLength(str);
if (length == 0) return null;
char[] chars = new char[length];
CFRange range = new CFRange();
range.length = length;
OS.CFStringGetCharacters(str, range, chars);
return new String(chars);
} finally {
OS.CFRelease(str);
}
}
protected int[] getTypeIds(){
return new int[] {URL_ID, URLN_ID};
}
protected String[] getTypeNames(){
return new String[] {URL, URLN};
}
boolean checkURL(Object object) {
return object != null && (object instanceof String) && ((String)object).length() > 0;
}
protected boolean validate(Object object) {
return checkURL(object);
}
}
\ No newline at end of file +/*******************************************************************************
* Copyright (c) 20007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.dnd;
import org.eclipse.swt.internal.carbon.*;
/** + * The class <code>URLTransfer</code> provides a platform specific mechanism + * for converting text in URL format represented as a java <code>String</code> + * to a platform specific representation of the data and vice versa. See + * <code>Transfer</code> for additional information. The string + * must contain a fully specified url. + * + * <p>An example of a java <code>String</code> containing a URL is shown + * below:</p> + * + * <code><pre> + * String url = "http://www.eclipse.org"; + * </code></pre> + * + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> + */
public class URLTransfer extends ByteArrayTransfer {
static URLTransfer _instance = new URLTransfer();
static final String URL = "url "; //$NON-NLS-1$
static final int URL_ID = registerType(URL);
static final String URLN = "urln"; //$NON-NLS-1$
static final int URLN_ID = registerType(URLN);
private URLTransfer() {}
/** + * Returns the singleton instance of the URLTransfer class. + * + * @return the singleton instance of the URLTransfer class + */
public static URLTransfer getInstance () {
return _instance;
}
/** + * This implementation of <code>javaToNative</code> converts a URL + * represented by a java <code>String</code> to a platform specific representation. + * For additional information see <code>Transfer#javaToNative</code>. + * + * @param object a java <code>String</code> containing a URL + * @param transferData an empty <code>TransferData</code> object; this + * object will be filled in on return with the platform specific format of the data + */
public void javaToNative (Object object, TransferData transferData){
if (!checkURL(object) || !isSupportedType(transferData)) {
DND.error(DND.ERROR_INVALID_DATA);
}
transferData.result = -1;
String url = (String)object;
int count = url.length();
char[] chars = new char[count];
url.getChars(0, count, chars, 0);
int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, count);
if (cfstring == 0) return;
try {
CFRange range = new CFRange();
range.length = chars.length;
int encoding = OS.kCFStringEncodingUTF8;
int[] size = new int[1];
int numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, null, 0, size);
if (numChars == 0 || size[0] == 0) return;
byte[] buffer = new byte[size[0]];
numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, buffer, size [0], size);
if (numChars == 0) return;
transferData.data = new byte[][] {buffer};
transferData.result = 0;
} finally {
OS.CFRelease(cfstring);
}
}
/** + * This implementation of <code>nativeToJava</code> converts a platform specific + * representation of a URL to a java <code>String</code>. + * For additional information see <code>Transfer#nativeToJava</code>. + * + * @param transferData the platform specific representation of the data to be + * converted + * @return a java <code>String</code> containing a URL if the + * conversion was successful; otherwise null + */
public Object nativeToJava(TransferData transferData){
if (!isSupportedType(transferData) || transferData.data == null) return null;
if (transferData.data.length == 0) return null;
byte[] buffer = transferData.data[0];
int encoding = OS.kCFStringEncodingUTF8;
int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true);
if (cfstring == 0) return null;
char[] unescapedChars = new char[] {'%'};
int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length);
int str = OS.CFURLCreateStringByReplacingPercentEscapes(OS.kCFAllocatorDefault, cfstring, unescapedStr);
OS.CFRelease(unescapedStr);
OS.CFRelease(cfstring);
if (str == 0) return null;
try {
int length = OS.CFStringGetLength(str);
if (length == 0) return null;
char[] chars = new char[length];
CFRange range = new CFRange();
range.length = length;
OS.CFStringGetCharacters(str, range, chars);
return new String(chars);
} finally {
OS.CFRelease(str);
}
}
protected int[] getTypeIds(){
return new int[] {URL_ID, URLN_ID};
}
protected String[] getTypeNames(){
return new String[] {URL, URLN};
}
boolean checkURL(Object object) {
return object != null && (object instanceof String) && ((String)object).length() > 0;
}
protected boolean validate(Object object) {
return checkURL(object);
}
}
\ No newline at end of file |