public class DragDropPlugin extends DropTargetPlugin implements java.awt.dnd.DragGestureListener, java.awt.dnd.DragSourceListener
DragDropPlugin
is an editor plugin which extends
the DropTargetPlugin
to support full Drag-N-Drop
functionality for the BasicEditorPane
. Modifier and Type | Class and Description |
---|---|
protected class |
DragDropPlugin.DragCaret
The
DragCaret class extends the editor caret
implementation to support the initiation of dragging without
moving the cursor. |
protected class |
DragDropPlugin.DragTransferable
The
DragTransferable class provides extra
information like the editor and offset where the data comes from. |
Modifier and Type | Field and Description |
---|---|
protected static EditDescriptor |
DRAG_DESCRIPTOR
The edit (undo) descriptor for a drag operation.
|
protected static EditDescriptor |
DRAGDROP_DESCRIPTOR
The edit (undo) descriptor for a drag and drop operation within
the same editor.
|
protected boolean |
dragInProgress
Whether a drag operation was actually started.
|
protected java.awt.dnd.DragGestureRecognizer |
dragRecognizer
The drag gesture recognizer associated with this editor.
|
protected OffsetMark |
dropOffsetMark
The offset where the drop occurred.
|
protected boolean |
focusWasGained
Whether the focus was just gained.
|
protected javax.swing.text.Caret |
originalCaret
Preserve the old caret that was used before the Drag plugin
was installed.
|
static java.awt.datatransfer.DataFlavor |
OUR_FLAVOR
Our custom data flavor which has extra information, like the
editor and offset info.
|
protected boolean |
queuedPopupTrigger
Whether an "isPopupTrigger = true" from a mousePressed has been
queued due to us eating the mousePressed for drag and drop.
|
protected boolean |
selectionClicked
Whether the current mouse press occurred in a selection.
|
DROP_DESCRIPTOR, DROP_RECT_WIDTH, dropTarget, editor, lastDropRect, PLAIN_FLAVOR, STRING_FLAVOR
Constructor and Description |
---|
DragDropPlugin()
Constructs a new
DragDropPlugin instance that
adds drag-n-drop capability to the editor. |
Modifier and Type | Method and Description |
---|---|
protected void |
cancelDragEvent(java.awt.dnd.DragSourceEvent event)
Utility method to handle the case where the drag cursor has
exited a viable DropTarget - note that this does not mean that
the drag operation has been cancelled completely though.
|
void |
deinstall(BasicEditorPane editor)
Called when the plugin is being removed from the BasicEditorPane
(for example when the editor is closed.) This is used to notify
plugins that they should unregister any listeners that were
attached.
|
protected void |
deinstallDragCaret()
Utility method to swap out our custom drag caret when this plugin
is deinstalled.
|
void |
dragDropEnd(java.awt.dnd.DragSourceDropEvent event)
This method is invoked to signify that the Drag and Drop
operation is complete.
|
void |
dragEnter(java.awt.dnd.DragSourceDragEvent event)
Called as the hotspot enters a platform dependent drop site.
|
void |
dragExit(java.awt.dnd.DragSourceEvent event)
Called as the hotspot exits a platform dependent drop site.
|
void |
dragGestureRecognized(java.awt.dnd.DragGestureEvent event)
A
DragGestureRecognizer has detected a
platform-dependent drag initiating gesture and is notifying this
listener in order for it to initiate the action for the user. |
void |
dragOver(java.awt.dnd.DragSourceDragEvent event)
Called as the hotspot moves over a platform dependent drop site.
|
void |
dropActionChanged(java.awt.dnd.DragSourceDragEvent event)
Called when the user has modified the drop gesture.
|
protected void |
exchangeCaret(javax.swing.text.Caret oldCaret,
javax.swing.text.Caret newCaret)
Utility method to swap editor carets.
|
protected void |
handleDragEvent(java.awt.dnd.DragSourceDragEvent event)
Utility method to handle the various drag events that occur
on the DragSource side before the actual drop occurs.
|
protected void |
handleDropEvent(java.awt.dnd.DragSourceDropEvent event)
Utility method to handle the actual drop event for the DragSource
side of things.
|
protected void |
handleDropEvent(java.awt.dnd.DropTargetDropEvent event)
Utility method to handle the actual drop event that occurred.
|
void |
install(BasicEditorPane editor)
Called when this plugin is being installed into the BasicEditorPane.
|
protected void |
installDragCaret()
Utility method to install and swap in our custom drag caret to
support drag functionality.
|
protected boolean |
isInSelection(int offset)
Return true if the given offset is within the current selection, false otherwise
|
void |
propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.
|
protected void |
removeSelectedText()
Utility method to remove the selected text of editor.
|
protected void |
updateDragCursor(java.awt.dnd.DragSourceEvent event,
int dropAction)
Utility method to update the drag cursor based on the given
event.
|
cancelDragEvent, clearDropLocation, dragEnter, dragExit, dragOver, drop, dropActionChanged, getDocument, getDropRectangle, getPreferredDataFlavor, getSupportedFlavors, getTransferText, handleDragEvent, isDataFlavorSupported, isDataFlavorSupported, isDropActionSupported, paintDropLocation
protected javax.swing.text.Caret originalCaret
protected java.awt.dnd.DragGestureRecognizer dragRecognizer
protected boolean selectionClicked
protected boolean queuedPopupTrigger
protected boolean dragInProgress
protected OffsetMark dropOffsetMark
protected static final EditDescriptor DRAG_DESCRIPTOR
protected static final EditDescriptor DRAGDROP_DESCRIPTOR
protected boolean focusWasGained
public static final java.awt.datatransfer.DataFlavor OUR_FLAVOR
public DragDropPlugin()
DragDropPlugin
instance that
adds drag-n-drop capability to the editor.public void install(BasicEditorPane editor)
install
in interface EditorPlugin
install
in class DropTargetPlugin
editor
- the editor panepublic void deinstall(BasicEditorPane editor)
deinstall
in interface EditorPlugin
deinstall
in class DropTargetPlugin
editor
- the editor paneprotected void installDragCaret()
protected void deinstallDragCaret()
protected void exchangeCaret(javax.swing.text.Caret oldCaret, javax.swing.text.Caret newCaret)
oldCaret
- the old caret that is currently in the editornewCaret
- the new caret to be installed into the editorpublic void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
propertyChange
in class DropTargetPlugin
event
- A PropertyChangeEvent object describing the event source
and the property that has changed.public void dragGestureRecognized(java.awt.dnd.DragGestureEvent event)
DragGestureRecognizer
has detected a
platform-dependent drag initiating gesture and is notifying this
listener in order for it to initiate the action for the user. dragGestureRecognized
in interface java.awt.dnd.DragGestureListener
event
- the event describing the gesture that has just occurredpublic void dragEnter(java.awt.dnd.DragSourceDragEvent event)
dragEnter
in interface java.awt.dnd.DragSourceListener
event
- the drag source eventpublic void dragOver(java.awt.dnd.DragSourceDragEvent event)
dragOver
in interface java.awt.dnd.DragSourceListener
event
- the drag source eventpublic void dropActionChanged(java.awt.dnd.DragSourceDragEvent event)
dropActionChanged
in interface java.awt.dnd.DragSourceListener
event
- the drag source eventpublic void dragExit(java.awt.dnd.DragSourceEvent event)
dragExit
in interface java.awt.dnd.DragSourceListener
event
- the drag source eventpublic void dragDropEnd(java.awt.dnd.DragSourceDropEvent event)
dragDropEnd
in interface java.awt.dnd.DragSourceListener
event
- the drag source eventprotected void handleDragEvent(java.awt.dnd.DragSourceDragEvent event)
event
- the event that occurredprotected void cancelDragEvent(java.awt.dnd.DragSourceEvent event)
event
- the drag event that occurredprotected void handleDropEvent(java.awt.dnd.DragSourceDropEvent event)
event
- the actual drop event that occurredprotected void removeSelectedText()
protected void handleDropEvent(java.awt.dnd.DropTargetDropEvent event)
handleDropEvent
in class DropTargetPlugin
event
- the actual drop event that occurredprotected boolean isInSelection(int offset)
offset
- protected void updateDragCursor(java.awt.dnd.DragSourceEvent event, int dropAction)
event
- the event that occurreddropAction
- the current drop action