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

cannot drag text from a Java application to drop into an external application

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.3.0
    • Fix Version/s: 1.3.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_7, windows_95, windows_98, windows_nt
    • Verification:
      Verified

      Description

      jdk1.3-M Drag-N-Drop works for dragging text from an external application
      such as Solaris TextEditor or Window's WordPad and dropping it into the
      Java application, but not the other way around.


      The following sample code demonstrate the problem.

      Roger 11/2/99


      import java.io.*;
      import java.awt.*;
      import java.awt.dnd.*;
      import java.awt.event.*;
      import java.awt.datatransfer.*;

      public class dnd extends Frame {

          public static void main(String argv[]) {
              dnd test = new dnd();
          }

          dnd () {


              String textToBeDropped =
      "\n" +
      "\tJava, Java, Java.\n\n";

      Panel workPanel = new Panel(new BorderLayout());

              Label dragComponent =
      new Label(" Drag Me and drop an editor ", Label.CENTER);
      dragComponent.setBackground(Color.pink);
              dragComponent.setFont(new Font("Courier", Font.BOLD, 32));

      workPanel.add(dragComponent, BorderLayout.NORTH);
          
              TextArea droppedText =
      new TextArea(textToBeDropped, 4, 42, TextArea.SCROLLBARS_NONE);
              droppedText.setEditable(false);
              droppedText.setBackground(Color.white);
              droppedText.setFont(new Font("Courier", Font.PLAIN, 14));

              workPanel.add(droppedText, BorderLayout.CENTER);
          
              add(workPanel); // Add test panel to frame
          
              DnDTest3 dnd =
      new DnDTest3(dragComponent, textToBeDropped);
              DragGestureRecognizer recognizer=DragSource.getDefaultDragSource().
              createDefaultDragGestureRecognizer(dragComponent,
      DnDConstants.ACTION_COPY, dnd);
          
              setSize(600, 400);
      setVisible(true);
          }
      }

      class ComponentTransferable3 implements Transferable {
          String text = "";
          DataFlavor possibleFlavors[] = {
      new DataFlavor
      ("text/plain; class=java.io.InputStream; charset=iso8859-1",
      "Latin based language"),
      new DataFlavor
      ("text/plain; class=java.io.InputStream; charset=ascii",
      "plain ASCII"),
      new DataFlavor
      ("text/enhanced; class=java.io.InputStream; charset=ascii",
      "enhanced ASCII"),
      new DataFlavor
      ("text/plain; class=java.io.InputStream; charset=unknown",
      "other ISO standards"),
      // new DataFlavor
      // ("text/plain; class=java.io.InputStream; charset=unicode",
      // "Java Unicode")
          };

          ByteArrayInputStream inputS = null;

          public ComponentTransferable3 (String text) {
              this.text = text;
      byte[] bytes = text.getBytes();

      inputS = new ByteArrayInputStream(bytes);

          }

          public DataFlavor[] getTransferDataFlavors() {
              return possibleFlavors;
          }

          public boolean isDataFlavorSupported(DataFlavor flavor) {
              return true;
          }

          public Object getTransferData(DataFlavor flavor) {
              return inputS;
          }
      }


      class DnDTest3 implements DragGestureListener {
          String textToBeDropped = "The text to be dragged";
          public Label dragComponent;

          public DnDTest3(Label dragComponent,
      String textToBeDropped) {
              this.dragComponent = dragComponent;
              this.textToBeDropped = textToBeDropped;
          }


          public void dragGestureRecognized(DragGestureEvent e) {

              ComponentTransferable3 myTransferable =
      new ComponentTransferable3(textToBeDropped);
          
              e.startDrag(DragSource.DefaultCopyDrop, myTransferable,
      new DragSourceListener() {
      public void dragEnter(DragSourceDragEvent dsde) {}
      public void dragOver(DragSourceDragEvent dsde) {}
      public void dropActionChanged(DragSourceDragEvent dsde) {}
      public void dragExit(DragSourceEvent dse) {}
      public void dragDropEnd(DragSourceDropEvent dsde) {}
      });
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmendenhsunw David Mendenhall (Inactive)
                Reporter:
                rphamsunw Roger Pham (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: