Index: org/netbeans/modules/editor/NbEditorToolBar.java =================================================================== RCS file: /cvs/editor/src/org/netbeans/modules/editor/NbEditorToolBar.java,v retrieving revision 1.14 diff -u -r1.14 NbEditorToolBar.java --- org/netbeans/modules/editor/NbEditorToolBar.java 15 Apr 2005 12:14:24 -0000 1.14 +++ org/netbeans/modules/editor/NbEditorToolBar.java 28 Jul 2005 07:20:22 -0000 @@ -16,6 +16,18 @@ import java.awt.Component; import java.awt.Image; import java.awt.Insets; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragSource; +import java.awt.dnd.DragSourceDragEvent; +import java.awt.dnd.DragSourceDropEvent; +import java.awt.dnd.DragSourceEvent; +import java.awt.dnd.DragSourceListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -49,6 +61,7 @@ import javax.swing.border.Border; import javax.swing.plaf.ToolBarUI; import javax.swing.text.EditorKit; +import javax.swing.text.JTextComponent; import org.netbeans.editor.BaseAction; import org.netbeans.editor.BaseKit; import org.netbeans.editor.BaseTextUI; @@ -71,6 +84,7 @@ import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; +import org.openide.text.ActiveEditorDrop; import org.openide.util.TopologicalSortException; import org.openide.util.actions.Presenter; @@ -464,8 +478,87 @@ } } } + DraggableButton b1 = new DraggableButton(); + b1.setText("A"); + add(b1); + DraggableButton b2 = new DraggableButton(); + b2.setText("B"); + add(b2); + + } + + + /** DraggableButton - creates transferable containing button's text */ + private class DraggableButton extends javax.swing.JButton + implements DragGestureListener, DragSourceListener { + DragSource dragSource; + + public DraggableButton() { + dragSource = new DragSource(); + dragSource.createDefaultDragGestureRecognizer( + this, DnDConstants.ACTION_COPY_OR_MOVE, this); + } + + public void dragGestureRecognized(DragGestureEvent evt) { + dragSource.startDrag (evt, DragSource.DefaultCopyDrop, new MyDrop(getText()), this); + } + public void dragEnter(DragSourceDragEvent evt) { + // Called when the user is dragging this drag source and enters + // the drop target. + } + public void dragOver(DragSourceDragEvent evt) { + // Called when the user is dragging this drag source and moves + // over the drop target. + } + public void dragExit(DragSourceEvent evt) { + // Called when the user is dragging this drag source and leaves + // the drop target. + } + public void dropActionChanged(DragSourceDragEvent evt) { + // Called when the user changes the drag action between copy or move. + } + public void dragDropEnd(DragSourceDropEvent evt) { + // Called when the user finishes or cancels the drag operation. + } } + 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(java.awt.Component targetComponent) { + System.out.println("*** drop happen in component:"+targetComponent); + JTextComponent comp = (JTextComponent)targetComponent; + System.out.println("caret:"+comp.getCaretPosition()); + return true; + } + + // blablabla... + } + + private void processButton(AbstractButton button) { button.setContentAreaFilled(false); button.setBorderPainted(false);