JDK-4032895 : datatransfer API doesn't work on Windows95/NT(4.0) platforms , but works on sola
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.0e,1.1,1.1.4
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris,windows_95
  • CPU: x86,sparc
  • Submitted: 1997-02-18
  • Updated: 1999-11-09
  • Resolved: 1999-11-09
Related Reports
Duplicate :  
Description

Name: mc57594			Date: 02/18/97


// fl.java
import java.awt.datatransfer.DataFlavor;

 public  class fl { 


         public static DataFlavor CompFlavor; 
         static {
         try {
            CompFlavor = new DataFlavor(Class.forName("java.awt.Component"), "Awt Component");
         } catch (ClassNotFoundException e) { }
         }      

         public fl() {}

}
*****************************************************************

// ComponentSelection.java
import java.awt.*;
import java.io.*;
import java.awt.datatransfer.*;

 public class ComponentSelection implements Transferable, ClipboardOwner {
    public static DataFlavor CompFlavor = fl.CompFlavor;

        final static int COMPONENT = 0;

        DataFlavor flavors[] = {fl.CompFlavor};

        private Component data;

        public ComponentSelection(Component data) {
                //CompFlavor = fl.CompFlavor;
                this.data = data;
        }

        public synchronized DataFlavor[] getTransferDataFlavors() {

        //      System.out.println(" I am here in clipboardTest.getTransferDataFlavors");
                return flavors;
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
                return (flavor.equals(flavors[COMPONENT]));
        }

        public synchronized Object getTransferData(DataFlavor flavor) 
                throws UnsupportedFlavorException, IOException {
                
                if(flavor.equals(flavors[COMPONENT])) {
                        System.out.println("Name is : " + data);
                         return (Object) data;
                } else {
                         throw new UnsupportedFlavorException(flavor);
                }
        }

        public void lostOwnership(Clipboard clipboard, Transferable contents) {
         System.out.println("Clipboard contents replaced");
     }

}

*****************************************************************
// clipboardTest.java
import java.awt.*;
import java.io.*;
import java.awt.datatransfer.*;
import java.awt.event.*;


public class clipboardTest extends Frame implements ClipboardOwner, ActionListener {

         Button copyButton, pasteButton;
         Button testButton = new Button("testButton");
         Clipboard clipboard = getToolkit().getSystemClipboard();

         public clipboardTest() {
                 super("Clipboard Test");
                 setLayout(new FlowLayout());
                 copyButton = new Button("Copy");
                 add(copyButton);
                 copyButton.addActionListener(this);
                 pasteButton = new Button("Paste");
                 add(pasteButton);
                 pasteButton.addActionListener(this);
                 pasteButton.disable();
                 pack();
         }


         public void actionPerformed(ActionEvent evt) {
                 Object source = evt.getSource();
                 if((Button) source == copyButton) {
                         Button srcData = testButton;
                         if (srcData != null) {
                                ComponentSelection contents = new ComponentSelection((Component)srcData);

                                //System.out.println(""clipboardTest:actionPerformed:  ");
                                //System.out.println(contents.getTransferDataFlavors()[0].getMimeType());
                                //System.out.println(contents.getTransferDataFlavors()[0].getRepresentationClass().getName());
                                //System.out.println(contents.getTransferDataFlavors()[0].getHumanPresentableName());
                        
                                if (contents != null) {
                                        clipboard.setContents(contents, this);
                                        pasteButton.enable();
                                }
                                else 
                                        System.out.println("actionPerformed: contents == null");
                         }
                        
                 } else if(evt.getSource() == pasteButton) {
                         Transferable content = clipboard.getContents(this);

                                //System.out.println(content.getTransferDataFlavors()[0].getMimeType());
                                //System.out.println(content.getTransferDataFlavors()[0].getRepresentationClass().getName());
                                //System.out.println(content.getTransferDataFlavors()[0].getHumanPresentableName());

                         if (content != null) {
                                 try {
                                         Button dstData = (Button) content.getTransferData(fl.CompFlavor);
                                         this.add(dstData);
                                         this.validate();

                                 } catch (Exception e) {
                                         System.out.println("Couldn't get contents in format: " + ComponentSelection.CompFlavor.getHumanPresentableName());
                                 }
                         }
        
                 }
        
         }

         public void lostOwnership(Clipboard clipboard, Transferable contents) {
         System.out.println("Clipboard contents replaced");
     }

                 
        public static void main(String[] args) {
                clipboardTest test = new clipboardTest();
                test.show();
        }
}
company  -  WVU  , email  -  ###@###.###
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 02/18/97 ======================================================================
11-06-2004

PUBLIC COMMENTS Datatransfer API doesn't work on Windows95/NT(4.0) platforms, but works on solaris.
10-06-2004

EVALUATION Implemented support for Java objects like Solaris implementation had. thomas.ball@Eng 1998-02-23 No, this was never implemented. Tom did implement code to register a new type of clipboard object, and posted the data with SetClipboardData(<type>, NULL). This is a valid way to post data -- it means that the data will be rendered on demand. However, he never handled the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages. I have removed the fixed and integrated tags from this bug, and instead closed it as a duplicate of 4066902, which is still open. david.mendenhall@eng 1999-11-09
09-11-1999