| 
 | org.openide.util 6.8.22 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
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 | 
|---|
Transferable convert(Transferable t)
 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;
 }
 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.
t - the incoming basic transferable
| 
 | org.openide.util 6.8.22 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||