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

ActiveEditorDrop (NetBeans Text API) - NetBeans API Javadoc 5.0.0

 

org.openide.text
Interface ActiveEditorDrop


public interface ActiveEditorDrop

ActiveEditorDrop with artificial DataFlavor. Drag and drop initiator sometimes needs to be notified about a target component, where the drop operation was performed. Initiator should implement this interface and use the required artificial DataFlavor. Component that will support drop operation of the ActiveEditorDrop should call handleTransfer method.
Sample usage of the client:

   private class MyDrop extends StringSelection implements ActiveEditorDrop {
       
       public MyDrop(String text){
           super(text); //NOI18N
       }
       
       public boolean isDataFlavorSupported(DataFlavor f) {
           return super.isDataFlavorSupported(f) || ActiveEditorDrop.FLAVOR == f;
       }
       
       public final DataFlavor[] getTransferDataFlavors() {
           DataFlavor delegatorFlavor[] = super.getTransferDataFlavors();
           int delegatorFlavorLength = delegatorFlavor.length;
           DataFlavor newArray[] = new DataFlavor[delegatorFlavorLength + 1];
           System.arraycopy(delegatorFlavor, 0, newArray, 0, delegatorFlavorLength);
           newArray[delegatorFlavorLength] = ActiveEditorDrop.FLAVOR;
           return newArray;
       }
       
       public final Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
           if (flavor == ActiveEditorDrop.FLAVOR) {
               return this;
           }
           return super.getTransferData(flavor);
       }
       
       public boolean handleTransfer(JTextComponent targetComponent) {
          // your implementation
       }
   }
   
or simplified solution:

   private class MyDrop implements ActiveEditorDrop, Transferable {
 
      public MyDrop(){
      }
      
      public boolean isDataFlavorSupported(DataFlavor f) {
          return ActiveEditorDrop.FLAVOR == f;
      }
      
      public final DataFlavor[] getTransferDataFlavors() {
          DataFlavor delegatorFlavor[] = new DataFlavor[1];
          delegatorFlavor[0] = ActiveEditorDrop.FLAVOR;
          return delegatorFlavor;
      }
      
      public final Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
          return (flavor == ActiveEditorDrop.FLAVOR) ? this : null;
      }
      
      public boolean handleTransfer(JTextComponent targetComponent) {
          //your implementation
      }
      
  }

   

Since:
org.openide.text 6.5

Field Summary
static DataFlavor FLAVOR
          Active editor DataFlavor used for communication between DragSource and DragTarget.
 
Method Summary
 boolean handleTransfer(JTextComponent targetComponent)
          A method called from the drop target that supports the artificial DataFlavor.
 

Field Detail

FLAVOR

public static final DataFlavor FLAVOR
Active editor DataFlavor used for communication between DragSource and DragTarget. This DataFlavor should be used for case where target component is instance of JTextComponent.

Method Detail

handleTransfer

public boolean handleTransfer(JTextComponent targetComponent)
A method called from the drop target that supports the artificial DataFlavor.

Parameters:
targetComponent - a Component where drop operation occured.
Returns:
true if implementor allowed a drop operation into the targetComponent

 

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