org.gudy.azureus2.ui.swt
Class URLTransfer

java.lang.Object
  extended by org.eclipse.swt.dnd.Transfer
      extended by org.eclipse.swt.dnd.ByteArrayTransfer
          extended by org.gudy.azureus2.ui.swt.URLTransfer

public class URLTransfer
extends org.eclipse.swt.dnd.ByteArrayTransfer

URL Transfer type for Drag and Drop of URLs Windows IDs are already functional. Please use Win32TransferTypes to determine the IDs for other OSes!

Author:
Rene Leonhardt, TuxPaper (require incoming string types have an URL prefix), TuxPaper (UTF-8, UTF-16, BOM stuff) TuxPaper's Notes: This class is flakey. It's better to use HTMLTransfer, and then parse the URL from the HTML. However, IE drag and drops do not support HTMLTransfer, so this class must stay Windows --- TypeIDs seem to be assigned differently on different platform versions (or maybe even different installations!). Here's some examples 49314: Moz/IE 0x01 4-0x00 0x80 lots-of-0x00 "[D]URL" lots-more-0x00 49315: Moz/IE Same as 49315, except unicode 49313: Moz/IE URL in .url format "[InternetShortcut]\nURL=%1" 49324: Moz/IE URL in text format 49395: Moz Same as 49324, except unicode 49319: Moz Dragged HTML Fragment with position information 49398: Moz Dragged HTML Fragment (NO position information, just HTML), unicode 49396: Moz HTML. Unknown. There's probably a link to the ID and they type name in the registry, or via a Windows API call. We don't want to do that, and fortunately, SWT doesn't seem to pay attention to getTypeIds() on Windows, so we check every typeid we get to see if we can parse an URL from it. Also, dragging from the IE URL bar hangs SWT (sometimes for a very long time). Fortunately, most people willdrag the URL from the actual content window. Dragging an IE bookmark is actually dragging the .url file, and should be handled by the FileTranfer (and then opening it and extracting the URL). Moz Bookmarks are processed as HTML. Linux --- For Linux, this class isn't required. HTMLTransfer will take care of Gecko and Konquerer. Opera --- As of 8.5, Opera still doesn't allow dragging outside of itself (at least on windows)
See Also:
org.gudy.azureus2.ui.swt.test.Win32TransferTypes

Nested Class Summary
static class URLTransfer.URLType
           
 
Constructor Summary
URLTransfer()
           
 
Method Summary
 URLTransfer.URLType bytebufferToJava(byte[] buffer)
           
static URLTransfer getInstance()
           
protected  int[] getTypeIds()
           
protected  String[] getTypeNames()
           
 boolean isSupportedType(org.eclipse.swt.dnd.TransferData transferData)
           
 void javaToNative(Object object, org.eclipse.swt.dnd.TransferData transferData)
           
static void main(String[] args)
          Test for varioud UTF Strings BOM information from http://www.unicode.org/faq/utf_bom.html
 Object nativeToJava(org.eclipse.swt.dnd.TransferData transferData)
           
static org.eclipse.swt.dnd.TransferData pickBestType(org.eclipse.swt.dnd.TransferData[] dataTypes, org.eclipse.swt.dnd.TransferData def)
          Sometimes, CF_Text will be in currentDataType even though CF_UNICODETEXT is present.
 
Methods inherited from class org.eclipse.swt.dnd.ByteArrayTransfer
getSupportedTypes
 
Methods inherited from class org.eclipse.swt.dnd.Transfer
registerType, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLTransfer

public URLTransfer()
Method Detail

getInstance

public static URLTransfer getInstance()

javaToNative

public void javaToNative(Object object,
                         org.eclipse.swt.dnd.TransferData transferData)
Overrides:
javaToNative in class org.eclipse.swt.dnd.ByteArrayTransfer

nativeToJava

public Object nativeToJava(org.eclipse.swt.dnd.TransferData transferData)
Overrides:
nativeToJava in class org.eclipse.swt.dnd.ByteArrayTransfer

bytebufferToJava

public URLTransfer.URLType bytebufferToJava(byte[] buffer)

getTypeNames

protected String[] getTypeNames()
Specified by:
getTypeNames in class org.eclipse.swt.dnd.Transfer

getTypeIds

protected int[] getTypeIds()
Specified by:
getTypeIds in class org.eclipse.swt.dnd.Transfer

isSupportedType

public boolean isSupportedType(org.eclipse.swt.dnd.TransferData transferData)
Overrides:
isSupportedType in class org.eclipse.swt.dnd.ByteArrayTransfer
Parameters:
transferData -
Returns:
See Also:
Transfer.isSupportedType(org.eclipse.swt.dnd.TransferData)

pickBestType

public static org.eclipse.swt.dnd.TransferData pickBestType(org.eclipse.swt.dnd.TransferData[] dataTypes,
                                                            org.eclipse.swt.dnd.TransferData def)
Sometimes, CF_Text will be in currentDataType even though CF_UNICODETEXT is present. This is a workaround until its fixed properly.

Place it in dropAccept

if (event.data instanceof URLTransfer.URLType)
        event.currentDataType = URLTransfer.pickBestType(event.dataTypes, event.currentDataType);
 

Parameters:
dataTypes -
def -
Returns:

main

public static void main(String[] args)
Test for varioud UTF Strings BOM information from http://www.unicode.org/faq/utf_bom.html

Parameters:
args -