Hi-

I noticed a very similar problem with an example in "CoreJava, 1.1", v.
2.  While the selection goes ONTO the system clipboard as whatever you
declare it to be, it comes OFF the system clipboard as a:

"sun.awt.motif.X11Selection.class"

I don't know whether this is a bug or a feature. ;-)

The work-around I found was to:
==========
import sun.awt.motif.X11Selection; // not good, sun class, but...

// test for X11 selection
Transferable selection = mimeClipboard.getContents(this);
...
if(selection instanceof X11Selection) {
        String sx = (String)selection.getTransferData(DataFlavor.stringFlavor);
        // do whatever...
}
==========
In the CoreJava example, the authors implemented their own image/mime
encoding scheme, so they were alwasy working with strings,
essentially...

HTH.

Bob L.
-- 
Robert Lynch-Berkeley CA [EMAIL PROTECTED]
http://www.best.com/~rmlynch/
--
Steve Zara wrote:
> 
> This example code works fine on Solaris and Win95/NT:
> 
> import java.net.*;
> import java.awt.*;
> import java.awt.datatransfer.*;
> import java.io.*;
> import java.awt.event.*;
> 
> class clipboard extends Frame implements ClipboardOwner{
>         TextArea t1=new TextArea("Area 1...",20,20);
>         TextArea t2=new TextArea("Area 2...",20,20);
>         Button b1=new Button("Copy");
>         Button b2=new Button("Paste");
>         Panel pA=new Panel();
>         Panel pB=new Panel();
>         ClipboardOwner owner=this;
>         Clipboard Clip=getToolkit ().getSystemClipboard ();
> 
>         public void lostOwnership(Clipboard b,Transferable c)
>         {
>                 System.out.println("We lost ownership!");
>         }
> 
>         public static void main(String args[])
>         {
>                 clipboard c=new clipboard();
>                 c.resize(new Dimension(300,300));
>                 c.show();
>         }
> 
>         clipboard()
>         {
>                 setLayout(new BorderLayout(10,10));
>                 pA.setLayout(new FlowLayout());
>                 pB.setLayout(new FlowLayout());
>                 pA.add("West",t1);
>                 pA.add("East",t2);
> 
>                 b1.addActionListener( new ActionListener() {
> 
>                         public void actionPerformed(ActionEvent e)
>                         {
>                                 Transfer trans=new Transfer(t1.getSelectedText());
>                                 Clip.setContents(trans,owner);
>                         }
>                 });
> 
> 
>                 b2.addActionListener( new ActionListener() {
>                         public void actionPerformed(ActionEvent e)
>                         {
> 
>                                 Transferable data=Clip.getContents(this);
>                                 StringReader s;
>                                 if (data.isDataFlavorSupported(new 
>DataFlavor("text/insidejava","Test on InsideJava")))
>                                         System.out.println("Transferable supports 
>text/insidejava Mime Type.");
> 
>                                 if 
>(data.isDataFlavorSupported(DataFlavor.stringFlavor))
>                                         System.out.println("Transferable supports 
>application/x-java-serializedobject Mime Type");
>                                 try {
> 
>                                         String result = "";
>                                         
>s=(StringReader)data.getTransferData(DataFlavor.plainTextFlavor);
> 
>                                         try {
>                                             for (;;) {
>                                                 int c = s.read ();
>                                                 if (c == -1)
>                                                     break;
> 
>                                                 result += (char) c;
>                                             }
>                                         } catch (Exception ioe) {
>                                         }
>                                         t2.setText (result);
>                                         t1.setText (result);
> 
> 
>                                 }
>                                 catch (UnsupportedFlavorException ex) 
>{System.out.println("Unsupported Flavor!");}
>                                 catch (IOException ex) 
>{System.out.println("IOException!");}
> 
>                         }
>                 });
> 
>                 pB.add(b1);
>                 pB.add(b2);
> 
>                 add("South",pB);
>                 add("Center",pA);
>         }
> }
> 
> class Transfer implements Transferable
> {
>         String s;
> 
>         public Transfer(String s)
>         {
>                 this.s=s;
>         }
> 
>         public Object getTransferData(DataFlavor flavor) throws 
>UnsupportedFlavorException, IOException
>         {
>                 if (flavor.getMimeType().equals("text/insidejava")) return s;
>                 if (flavor==DataFlavor.stringFlavor) return s;
>                 return null;
>         }
> 
>         public boolean isDataFlavorSupported(DataFlavor flavor)
>         {
>                 System.out.println("isDataFlavorSupported Method called with:");
>                 System.out.println("  Mime Type: "+flavor.getMimeType());
>                 System.out.println("  Human Name: 
>"+flavor.getHumanPresentableName());
>                 if (flavor.getMimeType().equals("text/insidejava") 
>||flavor==DataFlavor.stringFlavor) return true;
>                 else return false;
>         }
> 
>         public  DataFlavor[] getTransferDataFlavors()
>         {
>                 DataFlavor d[]=new DataFlavor[1];
>                 d[0]=new DataFlavor("text/insidejava","Test on InsideJava");
>                 d[1]=DataFlavor.stringFlavor;
>                 return d;
>         }
> 
> }
> 
> (This is a severe modification of someone else's example)
> 
> The stack trace is:
> Exception occurred during event dispatching:
> java.lang.NullPointerException:
>         at sun.awt.motif.X11Selection.isDataFlavorSupported(X11Selection.java:223)
>         at clipboard$2.actionPerformed(Main.java:53)
>         at java.awt.Button.processActionEvent(Button.java:254)
>         at java.awt.Button.processEvent(Button.java:227)
>         at java.awt.Component.dispatchEventImpl(Component.java:1764)
>         at java.awt.Component.dispatchEvent(Component.java:1704)
>         at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)
> 
> I want to complete an application that can accept text from the
> clipboard, so this is a crucial bug for me.
> 
> Also, can I join the mailing list?

Reply via email to