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

datatransfer API doesn't work on Windows95/NT(4.0) platforms , but works on sola

XMLWordPrintable

    • x86, sparc
    • solaris, windows_95



      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 - ###@###.###
      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: