org.openide.util.datatransfer
Interface ExClipboard.Convertor

Enclosing class:
ExClipboard

public static interface ExClipboard.Convertor

Convertor that can convert the contents of a clipboard to additional flavors.


Method Summary
 Transferable convert(Transferable t)
          Convert a given transferable to a new transferable, generally one which adds new flavors based on the existing flavors.
 

Method Detail

convert

public Transferable convert(Transferable t)
Convert a given transferable to a new transferable, generally one which adds new flavors based on the existing flavors. The recommended usage is as follows:
 public Transferable convert (final Transferable t) {
   if (! t.isDataFlavorSupported (fromFlavor)) return t;
   if (t.isDataFlavorSupported (toFlavor)) return t;
   ExTransferable et = ExTransferable.create (t);
   et.put (new ExTransferable.Single (toFlavor) {
     public Object getData () throws IOException, UnsupportedFlavorException {
       FromObject from = (FromObject) t.getTransferData (fromFlavor);
       ToObject to = translateFormats (from);
       return to;
     }
   });
   return et;
 }
 

Note that this does not perform the conversion until toFlavor is actually requested, nor does it advertise toFlavor as being available unless fromFlavor already was.

You may also want to convert some flavor to a node selection, in which case you should do:

 public Transferable convert (final Transferable t) {
   if (! t.isDataFlavorSupported (DataFlavor.stringFlavor)) return t;
   if (NodeTransfer.findPaste (t) != null) return t;
   ExTransferable et = ExTransferable.create (t);
   et.put (NodeTransfer.createPaste (new NodeTransfer.Paste () {
     public PasteType[] types (Node target) {
       if (isSuitable (target)) {
         return new PasteType[] { new PasteType () {
           public Transferable paste () throws IOException {
             try {
               String s = (String) t.getTransferData (DataFlavor.stringFlavor);
               addNewSubnode (target, s);
             } catch (UnsupportedFlavorException ufe) {
               throw new IOException (ufe.toString ());
             }
             return t;
           }
         }};
       } else {
         return new PasteType[0];
       }
     }
   }));
   return et;
 }
 

Convertors should generally avoid removing flavors from the transferable, or changing the data for an existing flavor.

Parameters:
t - the incoming basic transferable
Returns:
a possible enhanced transferable


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.