Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6612015

Cannot drop filename data to dtfile by using DnD on XAWT

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 6u2
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5.1, solaris_7

      Description

      OPERATING SYSTEM(S):
      --------------------
      Solaris Express Developer Edition x86 (SunOS 5.11 snv_64a October 2007)

      FULL JDK VERSION(S):
      -------------------
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
      Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode)

      DESCRIPTION:
      ------------
      On Motif AWT, I can drop filename data to dtfile by using DnD.
      But it does not work on XAWT.

      Please try following steps:

       1. Login with CDE
       2. Create temporary directory (temp)
          $ mkdir temp
       3. Change directory to temp and create temporary file
          $ touch tempfile.txt
       4. Start dtfile
          $ dtfile -dir $PWD
       5. Store testcase and Compile it
          $ javac DraggableFileTest.java
       6. Run with Motif AWT
          $ AWT_TOOLKIT=MToolkit java DraggableFileTest tempfile.txt
       7. JButton window is displayed, drag "tempfile.txt" and drop it to dtfile
       8. "File Manager - Move Warning" window is displayed
       9. Press "Cancel Move" button on Warning window
      10. Stop DraggableFileTest, and rerun it with XAWT
          $ AWT_TOOLKIT=XToolkit java DraggableFileTest tempfile.txt
      11. JButton window is displayed, drag "tempfile.txt" and drop it to dtfile.
          But nothing happen <=== PROBLEM

      On XAWT, it seems data type for filename data is not correct.
      Now it seems data type is FILE_NAME, but it should be TEXT or STRING

      =====================================================================
      import java.io.*;
      import java.util.*;
      import java.awt.*;
      import java.awt.dnd.*;
      import java.awt.datatransfer.*;
      import javax.swing.*;

      class DraggableFileTest {
          DraggableFileTest(String[] files) {
              JFrame f = new JFrame(Toolkit.getDefaultToolkit().getClass().getName());
              f.getContentPane().add(new DraggableComponent(files));
              f.pack();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setVisible(true);
          }
          public static void main(String[] args) {
              new DraggableFileTest(args);
          }

          class FileTransferable implements Transferable {
              Vector fileList = new Vector();
              FileTransferable(String[] files) {
                  for(String file: files) fileList.add(new File(file));
              }
              public DataFlavor[] getTransferDataFlavors() {
                  return new DataFlavor[] {DataFlavor.javaFileListFlavor};
              }
              public boolean isDataFlavorSupported(DataFlavor flavor) {
                  return flavor.equals(DataFlavor.javaFileListFlavor);
              }
              public Object getTransferData(DataFlavor flavor)
                  throws UnsupportedFlavorException, IOException {
                  return (Object) fileList;
              }
          }

          class DraggableComponent extends JButton
                  implements DragGestureListener, DragSourceListener {
              DragSource dragSource;
              String[] files;
              public DraggableComponent(String[] files) {
                  dragSource = new DragSource();
                  this.files = files;
                  StringBuffer sb = new StringBuffer();
                  for(String file: files) sb.append(","+file);
                  setLabel(sb.toString().substring(1));
                  dragSource.createDefaultDragGestureRecognizer(
                      this, DnDConstants.ACTION_COPY_OR_MOVE, this);
              }
              public void dragGestureRecognized(DragGestureEvent evt) {
                  System.out.println("dragGestureRecognized is called");
                  Transferable t = new FileTransferable(files);
                  dragSource.startDrag (evt, DragSource.DefaultCopyDrop, t, this);
              }
              public void dragEnter(DragSourceDragEvent evt) {
                  System.out.println("dragEnter is called");
              }
              public void dragOver(DragSourceDragEvent evt) {
                  System.out.println("dragOver is called");
              }
              public void dragExit(DragSourceEvent evt) {
                  System.out.println("dragExit is called");
              }
              public void dropActionChanged(DragSourceDragEvent evt) {
                  System.out.println("dropActionChanged is called");
              }
              public void dragDropEnd(DragSourceDropEvent evt) {
                  System.out.println("dragDropEnd is called");
              }
          }
      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: