home *** CD-ROM | disk | FTP | other *** search
- package java.awt.dnd;
-
- import java.awt.Component;
- import java.awt.Cursor;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.datatransfer.Transferable;
- import java.awt.dnd.peer.DragSourceContextPeer;
- import java.util.TooManyListenersException;
-
- public class DragSourceContext implements DragSourceListener {
- protected static final int DEFAULT = 0;
- protected static final int ENTER = 1;
- protected static final int OVER = 2;
- protected static final int CHANGED = 3;
- private DragSource dragSource;
- private DragSourceContextPeer peer;
- private DragGestureEvent trigger;
- private Cursor cursor;
- private Component component;
- private int actions;
- private int currentDropAction;
- private Image image;
- private Point offset;
- private Transferable transferable;
- private DragSourceListener listener;
- private boolean cursorDirty = true;
-
- public DragSourceContext(DragSourceContextPeer var1, DragGestureEvent var2, Cursor var3, Image var4, Point var5, Transferable var6, DragSourceListener var7) {
- if ((this.peer = var1) == null) {
- throw new NullPointerException("DragSourceContextPeer");
- } else if ((this.trigger = var2) == null) {
- throw new NullPointerException("Trigger");
- } else if ((this.dragSource = var2.getDragSource()) == null) {
- throw new NullPointerException("DragSource");
- } else if ((this.component = var2.getComponent()) == null) {
- throw new NullPointerException("Component");
- } else if ((this.actions = var2.getSourceAsDragGestureRecognizer().getSourceActions()) == 0) {
- throw new IllegalArgumentException("source actions");
- } else if ((this.currentDropAction = var2.getDragAction()) == 0) {
- throw new IllegalArgumentException("no drag action");
- } else if (var6 == null) {
- throw new NullPointerException("Transferable");
- } else if (var7 == null) {
- throw new NullPointerException("DragSourceListener");
- } else if (this.image != null && var5 == null) {
- throw new NullPointerException("offset");
- } else {
- this.cursor = var3;
- this.image = var4;
- this.offset = var5;
- this.transferable = var6;
- this.listener = var7;
- this.updateCurrentCursor(this.currentDropAction, this.actions, 0);
- }
- }
-
- public DragSource getDragSource() {
- return this.dragSource;
- }
-
- public Component getComponent() {
- return this.component;
- }
-
- public DragGestureEvent getTrigger() {
- return this.trigger;
- }
-
- public int getSourceActions() {
- return this.actions;
- }
-
- public void setCursor(Cursor var1) {
- if (this.cursor == null || !this.cursor.equals(var1)) {
- this.cursorDirty = true;
- this.cursor = var1;
- if (this.peer != null) {
- this.peer.setCursor(this.cursor);
- }
- }
-
- }
-
- public Cursor getCursor() {
- return this.cursor;
- }
-
- public synchronized void addDragSourceListener(DragSourceListener var1) throws TooManyListenersException {
- if (var1 != null) {
- if (this.equals(var1)) {
- throw new IllegalArgumentException("DragSourceContext may not be its own listener");
- } else if (this.listener != null) {
- throw new TooManyListenersException();
- } else {
- this.listener = var1;
- }
- }
- }
-
- public synchronized void removeDragSourceListener(DragSourceListener var1) {
- if (this.listener != null && this.listener.equals(var1)) {
- this.listener = null;
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- public void transferablesFlavorsChanged() {
- if (this.peer != null) {
- this.peer.transferablesFlavorsChanged();
- }
-
- }
-
- public synchronized void dragEnter(DragSourceDragEvent var1) {
- if (this.listener != null) {
- this.listener.dragEnter(var1);
- }
-
- this.updateCurrentCursor(var1.getDropAction(), var1.getTargetActions(), 1);
- }
-
- public synchronized void dragOver(DragSourceDragEvent var1) {
- if (this.listener != null) {
- this.listener.dragOver(var1);
- }
-
- this.updateCurrentCursor(var1.getDropAction(), var1.getTargetActions(), 2);
- }
-
- public synchronized void dragExit(DragSourceEvent var1) {
- if (this.listener != null) {
- this.listener.dragExit(var1);
- }
-
- this.updateCurrentCursor(this.currentDropAction, 0, 0);
- }
-
- public synchronized void dropActionChanged(DragSourceDragEvent var1) {
- this.currentDropAction = var1.getDropAction();
- if (this.listener != null) {
- this.listener.dropActionChanged(var1);
- }
-
- this.updateCurrentCursor(this.currentDropAction, var1.getTargetActions(), 3);
- }
-
- public synchronized void dragDropEnd(DragSourceDropEvent var1) {
- if (this.listener != null) {
- this.listener.dragDropEnd(var1);
- }
-
- }
-
- public Transferable getTransferable() {
- return this.transferable;
- }
-
- protected void updateCurrentCursor(int var1, int var2, int var3) {
- if (this.cursorDirty && this.cursor != null) {
- this.cursorDirty = false;
- } else {
- Object var4 = null;
- switch (var3) {
- default:
- var2 = 0;
- case 1:
- case 2:
- case 3:
- int var5 = var1 & var2;
- Cursor var6;
- if (var5 == 0) {
- if ((var1 & 1073741824) == 1073741824) {
- var6 = DragSource.DefaultLinkNoDrop;
- } else if ((var1 & 2) == 2) {
- var6 = DragSource.DefaultMoveNoDrop;
- } else {
- var6 = DragSource.DefaultCopyNoDrop;
- }
- } else if ((var5 & 1073741824) == 1073741824) {
- var6 = DragSource.DefaultLinkDrop;
- } else if ((var5 & 2) == 2) {
- var6 = DragSource.DefaultMoveDrop;
- } else {
- var6 = DragSource.DefaultCopyDrop;
- }
-
- this.setCursor(var6);
- this.cursorDirty = false;
- }
- }
- }
- }
-