Index: org/netbeans/modules/editor/NbEditorToolBar.java =================================================================== RCS file: /cvs/editor/src/org/netbeans/modules/editor/NbEditorToolBar.java,v retrieving revision 1.14 diff -c -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 20 Jul 2005 08:47:06 -0000 *************** *** 16,21 **** --- 16,31 ---- import java.awt.Component; import java.awt.Image; import java.awt.Insets; + import java.awt.datatransfer.StringSelection; + import java.awt.datatransfer.Transferable; + 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,54 **** --- 59,65 ---- 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; *************** *** 73,78 **** --- 84,90 ---- import org.openide.loaders.DataObjectNotFoundException; import org.openide.util.TopologicalSortException; import org.openide.util.actions.Presenter; + import org.openide.text.CallbackTransferable; /** * Editor toolbar component. *************** *** 464,471 **** --- 476,540 ---- } } } + 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) { + Transferable t = new StringSelection(getText()); // gets the JButton text in the clip + dragSource.startDrag (evt, DragSource.DefaultCopyDrop, new MyCallbackTransferable(t), 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 MyCallbackTransferable extends CallbackTransferable{ + public MyCallbackTransferable(Transferable t){ + super(t); + } + + public void handleTransfer(java.awt.Component targetComponent) { + System.out.println("drop happen in component:"+targetComponent); + JTextComponent comp = (JTextComponent)targetComponent; + System.out.println("caret:"+comp.getCaretPosition()); + } + + } + + private void processButton(AbstractButton button) { button.setContentAreaFilled(false); button.setBorderPainted(false);