home *** CD-ROM | disk | FTP | other *** search
- package java.awt.dnd;
-
- import java.awt.Component;
- import java.awt.Point;
- import java.awt.datatransfer.FlavorMap;
- import java.awt.datatransfer.SystemFlavorMap;
- import java.awt.dnd.peer.DropTargetPeer;
- import java.awt.peer.ComponentPeer;
- import java.awt.peer.LightweightPeer;
- import java.io.Serializable;
- import java.util.TooManyListenersException;
-
- public class DropTarget implements DropTargetListener, Serializable {
- static final long serialVersionUID = -6283860791671019047L;
- private static final FlavorMap defaultFlavorMap = SystemFlavorMap.getDefaultFlavorMap();
- private transient DropTargetContext dropTargetContext;
- private Component component;
- private transient ComponentPeer componentPeer;
- private transient ComponentPeer nativePeer;
- int actions;
- boolean active;
- private transient DropTargetAutoScroller autoScroller;
- private DropTargetListener dtListener;
- private transient FlavorMap flavorMap;
-
- public DropTarget(Component var1, int var2, DropTargetListener var3, boolean var4, FlavorMap var5) {
- this.actions = 3;
- this.active = true;
- this.flavorMap = defaultFlavorMap;
- this.component = var1;
- this.setDefaultActions(var2);
- if (var3 != null) {
- try {
- this.addDropTargetListener(var3);
- } catch (TooManyListenersException var7) {
- }
- }
-
- if (var1 != null) {
- var1.setDropTarget(this);
- this.setActive(var4);
- }
-
- if (var5 != null) {
- this.flavorMap = var5;
- }
-
- }
-
- public DropTarget(Component var1, int var2, DropTargetListener var3, boolean var4) {
- this(var1, var2, var3, var4, (FlavorMap)null);
- }
-
- public DropTarget() {
- this((Component)null, 3, (DropTargetListener)null, true, (FlavorMap)null);
- }
-
- public DropTarget(Component var1, DropTargetListener var2) {
- this(var1, 3, var2, true, (FlavorMap)null);
- }
-
- public DropTarget(Component var1, int var2, DropTargetListener var3) {
- this(var1, var2, var3, true);
- }
-
- public synchronized void setComponent(Component var1) {
- if (this.component != var1 && (this.component == null || !this.component.equals(var1))) {
- ComponentPeer var3 = null;
- Component var2;
- if ((var2 = this.component) != null) {
- this.clearAutoscroll();
- this.component = null;
- if (this.componentPeer != null) {
- var3 = this.componentPeer;
- this.removeNotify(this.componentPeer);
- }
-
- var2.setDropTarget((DropTarget)null);
- }
-
- if ((this.component = var1) != null) {
- try {
- var1.setDropTarget(this);
- } catch (Exception var5) {
- if (var2 != null) {
- var2.setDropTarget(this);
- this.addNotify(var3);
- }
- }
- }
-
- }
- }
-
- public synchronized Component getComponent() {
- return this.component;
- }
-
- public synchronized void setDefaultActions(int var1) {
- this.actions = var1 & 1073741827;
- if (this.dropTargetContext != null) {
- this.dropTargetContext.setTargetActions(this.actions);
- }
-
- }
-
- public synchronized int getDefaultActions() {
- return this.actions;
- }
-
- public synchronized void setActive(boolean var1) {
- if (var1 != this.active) {
- this.active = var1;
- }
-
- if (!this.active) {
- this.clearAutoscroll();
- }
-
- }
-
- public synchronized boolean isActive() {
- return this.active;
- }
-
- public synchronized void addDropTargetListener(DropTargetListener var1) throws TooManyListenersException {
- if (var1 != null) {
- if (this.equals(var1)) {
- throw new IllegalArgumentException("DropTarget may not be its own Listener");
- } else if (this.dtListener == null) {
- this.dtListener = var1;
- } else {
- throw new TooManyListenersException();
- }
- }
- }
-
- public synchronized void removeDropTargetListener(DropTargetListener var1) {
- if (var1 != null && this.dtListener != null) {
- if (!this.dtListener.equals(var1)) {
- throw new IllegalArgumentException("listener mismatch");
- }
-
- this.dtListener = null;
- }
-
- }
-
- public synchronized void dragEnter(DropTargetDragEvent var1) {
- if (this.active) {
- if (this.dtListener != null) {
- this.dtListener.dragEnter(var1);
- } else {
- ((DropTargetEvent)var1).getDropTargetContext().setTargetActions(0);
- }
-
- this.initializeAutoscrolling(var1.getLocation());
- }
- }
-
- public synchronized void dragOver(DropTargetDragEvent var1) {
- if (this.active) {
- if (this.dtListener != null && this.active) {
- this.dtListener.dragOver(var1);
- }
-
- this.updateAutoscroll(var1.getLocation());
- }
- }
-
- public void dropActionChanged(DropTargetDragEvent var1) {
- if (this.active) {
- if (this.dtListener != null) {
- this.dtListener.dropActionChanged(var1);
- }
-
- this.updateAutoscroll(var1.getLocation());
- }
- }
-
- public synchronized void dragExit(DropTargetEvent var1) {
- if (this.active) {
- if (this.dtListener != null && this.active) {
- this.dtListener.dragExit(var1);
- }
-
- this.clearAutoscroll();
- }
- }
-
- public synchronized void drop(DropTargetDropEvent var1) {
- if (this.dtListener != null && this.active) {
- this.dtListener.drop(var1);
- } else {
- var1.rejectDrop();
- }
-
- }
-
- public FlavorMap getFlavorMap() {
- return this.flavorMap;
- }
-
- public void setFlavorMap(FlavorMap var1) {
- this.flavorMap = var1 == null ? defaultFlavorMap : var1;
- }
-
- public void addNotify(ComponentPeer var1) {
- if (var1 != this.componentPeer) {
- this.componentPeer = var1;
-
- for(Object var2 = this.component; var1 instanceof LightweightPeer; var2 = ((Component)var2).getParent()) {
- var1 = ((Component)var2).getPeer();
- }
-
- try {
- ((DropTargetPeer)(this.nativePeer = var1)).addDropTarget(this);
- } catch (ClassCastException var4) {
- this.nativePeer = null;
- }
-
- }
- }
-
- public void removeNotify(ComponentPeer var1) {
- if (this.nativePeer != null) {
- ((DropTargetPeer)this.nativePeer).removeDropTarget(this);
- }
-
- this.componentPeer = this.nativePeer = null;
- }
-
- public DropTargetContext getDropTargetContext() {
- if (this.dropTargetContext == null) {
- this.dropTargetContext = this.createDropTargetContext();
- }
-
- return this.dropTargetContext;
- }
-
- protected DropTargetContext createDropTargetContext() {
- return new DropTargetContext(this);
- }
-
- protected DropTargetAutoScroller createDropTargetAutoScroller(Component var1, Point var2) {
- return new DropTargetAutoScroller(var1, var2);
- }
-
- protected void initializeAutoscrolling(Point var1) {
- if (this.component != null && this.component instanceof Autoscroll) {
- this.autoScroller = this.createDropTargetAutoScroller(this.component, var1);
- }
- }
-
- protected void updateAutoscroll(Point var1) {
- if (this.autoScroller != null) {
- this.autoScroller.updateLocation(var1);
- }
-
- }
-
- protected void clearAutoscroll() {
- if (this.autoScroller != null) {
- this.autoScroller.stop();
- this.autoScroller = null;
- }
-
- }
- }
-