Constructors Summary |
---|
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act, FlavorMap fm)Creates a new DropTarget given the Component
to associate itself with, an int representing
the default acceptable action(s) to
support, a DropTargetListener
to handle event processing, a boolean indicating
if the DropTarget is currently accepting drops, and
a FlavorMap to use (or null for the default FlavorMap ).
The Component will receive drops only if it is enabled.
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) flavorMap = fm;
|
public DropTarget(Component c, int ops, DropTargetListener dtl, boolean act)Creates a DropTarget given the Component
to associate itself with, an int representing
the default acceptable action(s)
to support, a DropTargetListener
to handle event processing, and a boolean indicating
if the DropTarget is currently accepting drops.
The Component will receive drops only if it is enabled.
this(c, ops, dtl, act, null);
|
public DropTarget()Creates a DropTarget .
this(null, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null);
|
public DropTarget(Component c, DropTargetListener dtl)Creates a DropTarget given the Component
to associate itself with, and the DropTargetListener
to handle event processing.
The Component will receive drops only if it is enabled.
this(c, DnDConstants.ACTION_COPY_OR_MOVE, dtl, true, null);
|
public DropTarget(Component c, int ops, DropTargetListener dtl)Creates a DropTarget given the Component
to associate itself with, an int representing
the default acceptable action(s) to support, and a
DropTargetListener to handle event processing.
The Component will receive drops only if it is enabled.
this(c, ops, dtl, true);
|
Methods Summary |
---|
public synchronized void | addDropTargetListener(java.awt.dnd.DropTargetListener dtl)Adds a new DropTargetListener (UNICAST SOURCE).
if (dtl == null) return;
if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener");
if (dtListener == null)
dtListener = dtl;
else
throw new TooManyListenersException();
|
public void | addNotify(java.awt.peer.ComponentPeer peer)Notify the DropTarget that it has been associated with a Component
This method is usually called from java.awt.Component.addNotify() of
the Component associated with this DropTarget to notify the DropTarget
that a ComponentPeer has been associated with that Component.
Calling this method, other than to notify this DropTarget of the
association of the ComponentPeer with the Component may result in
a malfunction of the DnD system.
if (peer == componentPeer) return;
componentPeer = peer;
for (Component c = component;
c != null && peer instanceof LightweightPeer; c = c.getParent()) {
peer = c.getPeer();
}
if (peer instanceof DropTargetPeer) {
nativePeer = peer;
((DropTargetPeer)peer).addDropTarget(this);
} else {
nativePeer = null;
}
|
protected void | clearAutoscroll()clear autoscrolling
if (autoScroller != null) {
autoScroller.stop();
autoScroller = null;
}
|
protected java.awt.dnd.DropTarget$DropTargetAutoScroller | createDropTargetAutoScroller(java.awt.Component c, java.awt.Point p)/
/**
create an embedded autoscroller
return new DropTargetAutoScroller(c, p);
|
protected java.awt.dnd.DropTargetContext | createDropTargetContext()Creates the DropTargetContext associated with this DropTarget.
Subclasses may override this method to instantiate their own
DropTargetContext subclass.
This call is typically *only* called by the platform's
DropTargetContextPeer as a drag operation encounters this
DropTarget. Accessing the Context while no Drag is current
has undefined results.
return new DropTargetContext(this);
|
void | doSetDefaultActions(int ops)
actions = ops;
|
public synchronized void | dragEnter(java.awt.dnd.DropTargetDragEvent dtde)Calls dragEnter on the registered
DropTargetListener and passes it
the specified DropTargetDragEvent .
Has no effect if this DropTarget
is not active.
if (!active) return;
if (dtListener != null) {
dtListener.dragEnter(dtde);
} else
dtde.getDropTargetContext().setTargetActions(DnDConstants.ACTION_NONE);
initializeAutoscrolling(dtde.getLocation());
|
public synchronized void | dragExit(java.awt.dnd.DropTargetEvent dte)Calls dragExit on the registered
DropTargetListener and passes it
the specified DropTargetEvent .
Has no effect if this DropTarget
is not active.
This method itself does not throw any exception
for null parameter but for exceptions thrown by
the respective method of the listener.
if (!active) return;
if (dtListener != null && active) dtListener.dragExit(dte);
clearAutoscroll();
|
public synchronized void | dragOver(java.awt.dnd.DropTargetDragEvent dtde)Calls dragOver on the registered
DropTargetListener and passes it
the specified DropTargetDragEvent .
Has no effect if this DropTarget
is not active.
if (!active) return;
if (dtListener != null && active) dtListener.dragOver(dtde);
updateAutoscroll(dtde.getLocation());
|
public synchronized void | drop(java.awt.dnd.DropTargetDropEvent dtde)Calls drop on the registered
DropTargetListener and passes it
the specified DropTargetDropEvent
if this DropTarget is active.
clearAutoscroll();
if (dtListener != null && active)
dtListener.drop(dtde);
else { // we should'nt get here ...
dtde.rejectDrop();
}
|
public synchronized void | dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)Calls dropActionChanged on the registered
DropTargetListener and passes it
the specified DropTargetDragEvent .
Has no effect if this DropTarget
is not active.
if (!active) return;
if (dtListener != null) dtListener.dropActionChanged(dtde);
updateAutoscroll(dtde.getLocation());
|
public synchronized java.awt.Component | getComponent()Gets the Component associated
with this DropTarget .
return component;
|
public int | getDefaultActions()Gets an int representing the
current action(s) supported by this DropTarget .
return actions;
|
public java.awt.dnd.DropTargetContext | getDropTargetContext()Gets the DropTargetContext associated
with this DropTarget .
return dropTargetContext;
|
public java.awt.datatransfer.FlavorMap | getFlavorMap()Gets the FlavorMap
associated with this DropTarget .
If no FlavorMap has been set for this
DropTarget , it is associated with the default
FlavorMap .
return flavorMap;
|
protected void | initializeAutoscrolling(java.awt.Point p)initialize autoscrolling
if (component == null || !(component instanceof Autoscroll)) return;
autoScroller = createDropTargetAutoScroller(component, p);
|
public boolean | isActive()Reports whether or not
this DropTarget
is currently active (ready to accept drops).
return active;
|
private void | readObject(java.io.ObjectInputStream s)Deserializes this DropTarget . This method first performs
default deserialization for all non-transient fields. An
attempt is then made to deserialize this object's
DropTargetListener as well. This is first attempted by
deserializing the field dtListener , because, in releases
prior to 1.4, a non-transient field of this name stored the
DropTargetListener . If this fails, the next object in the
stream is used instead.
ObjectInputStream.GetField f = s.readFields();
try {
dropTargetContext =
(DropTargetContext)f.get("dropTargetContext", null);
} catch (IllegalArgumentException e) {
// Pre-1.4 support. 'dropTargetContext' was previoulsy transient
}
if (dropTargetContext == null) {
dropTargetContext = createDropTargetContext();
}
component = (Component)f.get("component", null);
actions = f.get("actions", DnDConstants.ACTION_COPY_OR_MOVE);
active = f.get("active", true);
// Pre-1.4 support. 'dtListener' was previously non-transient
try {
dtListener = (DropTargetListener)f.get("dtListener", null);
} catch (IllegalArgumentException e) {
// 1.4-compatible byte stream. 'dtListener' was written explicitly
dtListener = (DropTargetListener)s.readObject();
}
|
public synchronized void | removeDropTargetListener(java.awt.dnd.DropTargetListener dtl)Removes the current DropTargetListener (UNICAST SOURCE).
if (dtl != null && dtListener != null) {
if(dtListener.equals(dtl))
dtListener = null;
else
throw new IllegalArgumentException("listener mismatch");
}
|
public void | removeNotify(java.awt.peer.ComponentPeer peer)Notify the DropTarget that it has been disassociated from a Component
This method is usually called from java.awt.Component.removeNotify() of
the Component associated with this DropTarget to notify the DropTarget
that a ComponentPeer has been disassociated with that Component.
Calling this method, other than to notify this DropTarget of the
disassociation of the ComponentPeer from the Component may result in
a malfunction of the DnD system.
if (nativePeer != null)
((DropTargetPeer)nativePeer).removeDropTarget(this);
componentPeer = nativePeer = null;
|
public synchronized void | setActive(boolean isActive)Sets the DropTarget active if true ,
inactive if false .
if (isActive != active) {
active = isActive;
}
if (!active) clearAutoscroll();
|
public synchronized void | setComponent(java.awt.Component c)Note: this interface is required to permit the safe association
of a DropTarget with a Component in one of two ways, either:
component.setDropTarget(droptarget);
or droptarget.setComponent(component);
The Component will receive drops only if it is enabled.
if (component == c || component != null && component.equals(c))
return;
Component old;
ComponentPeer oldPeer = null;
if ((old = component) != null) {
clearAutoscroll();
component = null;
if (componentPeer != null) {
oldPeer = componentPeer;
removeNotify(componentPeer);
}
old.setDropTarget(null);
}
if ((component = c) != null) try {
c.setDropTarget(this);
} catch (Exception e) { // undo the change
if (old != null) {
old.setDropTarget(this);
addNotify(oldPeer);
}
}
|
public void | setDefaultActions(int ops)Sets the default acceptable actions for this DropTarget
getDropTargetContext().setTargetActions(ops & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE));
|
public void | setFlavorMap(java.awt.datatransfer.FlavorMap fm)Sets the FlavorMap associated
with this DropTarget .
flavorMap = fm == null ? SystemFlavorMap.getDefaultFlavorMap() : fm;
|
protected void | updateAutoscroll(java.awt.Point dragCursorLocn)update autoscrolling with current cursor locn
if (autoScroller != null) autoScroller.updateLocation(dragCursorLocn);
|
private void | writeObject(java.io.ObjectOutputStream s)Serializes this DropTarget . Performs default serialization,
and then writes out this object's DropTargetListener if and
only if it can be serialized. If not, null is written
instead.
s.defaultWriteObject();
s.writeObject(SerializationTester.test(dtListener)
? dtListener : null);
|