站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 5.5.1

ExClipboard.Convertor (NetBeans Utilities API) - NetBeans API Javadoc 5.5.1

org.openide.util 6.8.31

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

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

org.openide.util 6.8.31

Built on March 26 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.