Drag and Drop: determine data types available (win32 only) : Drag Drop « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » Drag DropScreenshots 
Drag and Drop: determine data types available (win32 only)
Drag and Drop: determine data types available (win32 only)



/*
 * Drag and Drop example snippet: determine data types available (win32 only)
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.internal.ole.win32.COM;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

public class Snippet83 extends ByteArrayTransfer {

  private static Snippet83 _instance = new Snippet83();

  private int[] ids;

  private String[] names;

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Table control = new Table(shell, SWT.NONE);
    TableItem item = new TableItem(control, SWT.NONE);
    item
        .setText("Drag data over this site to see the native transfer type.");
    DropTarget target = new DropTarget(control, DND.DROP_DEFAULT
        | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE);
    target.setTransfer(new Transfer[] { Snippet83.getInstance() });
    target.addDropListener(new DropTargetAdapter() {
      public void dragEnter(DropTargetEvent event) {
        String ops = "";
        if ((event.operations & DND.DROP_COPY!= 0)
          ops += "Copy;";
        if ((event.operations & DND.DROP_MOVE!= 0)
          ops += "Move;";
        if ((event.operations & DND.DROP_LINK!= 0)
          ops += "Link;";
        control.removeAll();
        TableItem item1 = new TableItem(control, SWT.NONE);
        item1.setText("Allowed Operations are " + ops);

        if (event.detail == DND.DROP_DEFAULT) {
          if ((event.operations & DND.DROP_COPY!= 0) {
            event.detail = DND.DROP_COPY;
          else if ((event.operations & DND.DROP_LINK!= 0) {
            event.detail = DND.DROP_LINK;
          else if ((event.operations & DND.DROP_MOVE!= 0) {
            event.detail = DND.DROP_MOVE;
          }
        }

        TransferData[] data = event.dataTypes;
        for (int i = 0; i < data.length; i++) {
          int id = data[i].type;
          String name = getNameFromId(id);
          TableItem item2 = new TableItem(control, SWT.NONE);
          item2.setText("Data type is " + id + " " + name);
        }
      }
    });

    shell.setSize(400400);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }

  public static Snippet83 getInstance() {
    return _instance;
  }

  Snippet83() {
    ids = new int[80000];
    names = new String[80000];
    for (int i = 0; i < ids.length; i++) {
      ids[i= i;
      names[i= getNameFromId(i);
    }
  }

  public void javaToNative(Object object, TransferData transferData) {
  }

  public Object nativeToJava(TransferData transferData) {
    return "Hello World";
  }

  protected String[] getTypeNames() {
    return names;
  }

  protected int[] getTypeIds() {
    return ids;
  }

  static String getNameFromId(int id) {
    String name = null;
    int maxSize = 128;
    TCHAR buffer = new TCHAR(0, maxSize);
    int size = COM.GetClipboardFormatName(id, buffer, maxSize);
    String type = null;
    if (size != 0) {
      name = buffer.toString(0, size);
    else {
      switch (id) {
      case COM.CF_HDROP:
        name = "CF_HDROP";
        break;
      case COM.CF_TEXT:
        name = "CF_TEXT";
        break;
      case COM.CF_BITMAP:
        name = "CF_BITMAP";
        break;
      case COM.CF_METAFILEPICT:
        name = "CF_METAFILEPICT";
        break;
      case COM.CF_SYLK:
        name = "CF_SYLK";
        break;
      case COM.CF_DIF:
        name = "CF_DIF";
        break;
      case COM.CF_TIFF:
        name = "CF_TIFF";
        break;
      case COM.CF_OEMTEXT:
        name = "CF_OEMTEXT";
        break;
      case COM.CF_DIB:
        name = "CF_DIB";
        break;
      case COM.CF_PALETTE:
        name = "CF_PALETTE";
        break;
      case COM.CF_PENDATA:
        name = "CF_PENDATA";
        break;
      case COM.CF_RIFF:
        name = "CF_RIFF";
        break;
      case COM.CF_WAVE:
        name = "CF_WAVE";
        break;
      case COM.CF_UNICODETEXT:
        name = "CF_UNICODETEXT";
        break;
      case COM.CF_ENHMETAFILE:
        name = "CF_ENHMETAFILE";
        break;
      case COM.CF_LOCALE:
        name = "CF_LOCALE";
        break;
      case COM.CF_MAX:
        name = "CF_MAX";
        break;
      }

    }
    return name;
  }
}

           
       
Related examples in the same category
1. SWT DND (Drag and Drop) comprehensive Example SWT DND (Drag and Drop) comprehensive Example
2. Word JumblesWord Jumbles
3. Illustrates draggingIllustrates dragging
4. Simple DND (Drag and Drop) ExampleSimple DND (Drag and Drop) Example
5. SWT DnD (Drag and drop) Composite
6. Drag and Drop: determine native data types available (motif only)
7. Drag and Drop example snippet: define a default operation (in this example, Copy)Drag and Drop example snippet: define a default operation (in this example, Copy)
8. Drag and Drop example snippet: define my own data transfer typeDrag and Drop example snippet: define my own data transfer type
9. Drag and Drop example snippet: drag leaf items in a treeDrag and Drop example snippet: drag leaf items in a tree
10. Drag and Drop example snippet: drag text between two labelsDrag and Drop example snippet: drag text between two labels
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.