Drag and Drop: determine native data types available (motif 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. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » SWT JFace Eclipse » Drag DropScreenshots 
Drag and Drop: determine native data types available (motif only)


/*******************************************************************************
 * Copyright (c) 2000, 2004 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.snippets;

/*
 * Drag and Drop example snippet: determine native data types available (motif
 * 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.*;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet158 extends ByteArrayTransfer {

  private static Snippet158 _instance = new Snippet158();

  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[] { Snippet158.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 Snippet158 getInstance() {
    return _instance;
  }

  Snippet158() {
  }

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

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

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

  static int shellHandle;

  protected int[] getTypeIds() {
    if (ids == null) {
      Display display = Display.getCurrent();
      int widgetClass = OS.topLevelShellWidgetClass();
      shellHandle = OS.XtAppCreateShell(null, null, widgetClass,
          display.xDisplay, null, 0);
      OS.XtSetMappedWhenManaged(shellHandle, false);
      OS.XtRealizeWidget(shellHandle);

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

  static String getNameFromId(int id) {
    int xDisplay = OS.XtDisplay(shellHandle);
    int ptr = 0;
    try {
      ptr = OS.XmGetAtomName(xDisplay, id);
    catch (Throwable t) {
    }
    if (ptr == 0)
      return "invalid " + id;
    int length = OS.strlen(ptr);
    byte[] nameBuf = new byte[length];
    OS.memmove(nameBuf, ptr, length);
    OS.XFree(ptr);
    return new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
  }
}

           
       
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 data types available (win32 only)Drag and Drop: determine data types available (win32 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_.___jav__a2_s._c___o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.