home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / awt / dnd / DragSourceContext.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.9 KB  |  195 lines

  1. package java.awt.dnd;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Cursor;
  5. import java.awt.Image;
  6. import java.awt.Point;
  7. import java.awt.datatransfer.Transferable;
  8. import java.awt.dnd.peer.DragSourceContextPeer;
  9. import java.util.TooManyListenersException;
  10.  
  11. public class DragSourceContext implements DragSourceListener {
  12.    protected static final int DEFAULT = 0;
  13.    protected static final int ENTER = 1;
  14.    protected static final int OVER = 2;
  15.    protected static final int CHANGED = 3;
  16.    private DragSource dragSource;
  17.    private DragSourceContextPeer peer;
  18.    private DragGestureEvent trigger;
  19.    private Cursor cursor;
  20.    private Component component;
  21.    private int actions;
  22.    private int currentDropAction;
  23.    private Image image;
  24.    private Point offset;
  25.    private Transferable transferable;
  26.    private DragSourceListener listener;
  27.    private boolean cursorDirty = true;
  28.  
  29.    public DragSourceContext(DragSourceContextPeer var1, DragGestureEvent var2, Cursor var3, Image var4, Point var5, Transferable var6, DragSourceListener var7) {
  30.       if ((this.peer = var1) == null) {
  31.          throw new NullPointerException("DragSourceContextPeer");
  32.       } else if ((this.trigger = var2) == null) {
  33.          throw new NullPointerException("Trigger");
  34.       } else if ((this.dragSource = var2.getDragSource()) == null) {
  35.          throw new NullPointerException("DragSource");
  36.       } else if ((this.component = var2.getComponent()) == null) {
  37.          throw new NullPointerException("Component");
  38.       } else if ((this.actions = var2.getSourceAsDragGestureRecognizer().getSourceActions()) == 0) {
  39.          throw new IllegalArgumentException("source actions");
  40.       } else if ((this.currentDropAction = var2.getDragAction()) == 0) {
  41.          throw new IllegalArgumentException("no drag action");
  42.       } else if (var6 == null) {
  43.          throw new NullPointerException("Transferable");
  44.       } else if (var7 == null) {
  45.          throw new NullPointerException("DragSourceListener");
  46.       } else if (this.image != null && var5 == null) {
  47.          throw new NullPointerException("offset");
  48.       } else {
  49.          this.cursor = var3;
  50.          this.image = var4;
  51.          this.offset = var5;
  52.          this.transferable = var6;
  53.          this.listener = var7;
  54.          this.updateCurrentCursor(this.currentDropAction, this.actions, 0);
  55.       }
  56.    }
  57.  
  58.    public DragSource getDragSource() {
  59.       return this.dragSource;
  60.    }
  61.  
  62.    public Component getComponent() {
  63.       return this.component;
  64.    }
  65.  
  66.    public DragGestureEvent getTrigger() {
  67.       return this.trigger;
  68.    }
  69.  
  70.    public int getSourceActions() {
  71.       return this.actions;
  72.    }
  73.  
  74.    public void setCursor(Cursor var1) {
  75.       if (this.cursor == null || !this.cursor.equals(var1)) {
  76.          this.cursorDirty = true;
  77.          this.cursor = var1;
  78.          if (this.peer != null) {
  79.             this.peer.setCursor(this.cursor);
  80.          }
  81.       }
  82.  
  83.    }
  84.  
  85.    public Cursor getCursor() {
  86.       return this.cursor;
  87.    }
  88.  
  89.    public synchronized void addDragSourceListener(DragSourceListener var1) throws TooManyListenersException {
  90.       if (var1 != null) {
  91.          if (this.equals(var1)) {
  92.             throw new IllegalArgumentException("DragSourceContext may not be its own listener");
  93.          } else if (this.listener != null) {
  94.             throw new TooManyListenersException();
  95.          } else {
  96.             this.listener = var1;
  97.          }
  98.       }
  99.    }
  100.  
  101.    public synchronized void removeDragSourceListener(DragSourceListener var1) {
  102.       if (this.listener != null && this.listener.equals(var1)) {
  103.          this.listener = null;
  104.       } else {
  105.          throw new IllegalArgumentException();
  106.       }
  107.    }
  108.  
  109.    public void transferablesFlavorsChanged() {
  110.       if (this.peer != null) {
  111.          this.peer.transferablesFlavorsChanged();
  112.       }
  113.  
  114.    }
  115.  
  116.    public synchronized void dragEnter(DragSourceDragEvent var1) {
  117.       if (this.listener != null) {
  118.          this.listener.dragEnter(var1);
  119.       }
  120.  
  121.       this.updateCurrentCursor(var1.getDropAction(), var1.getTargetActions(), 1);
  122.    }
  123.  
  124.    public synchronized void dragOver(DragSourceDragEvent var1) {
  125.       if (this.listener != null) {
  126.          this.listener.dragOver(var1);
  127.       }
  128.  
  129.       this.updateCurrentCursor(var1.getDropAction(), var1.getTargetActions(), 2);
  130.    }
  131.  
  132.    public synchronized void dragExit(DragSourceEvent var1) {
  133.       if (this.listener != null) {
  134.          this.listener.dragExit(var1);
  135.       }
  136.  
  137.       this.updateCurrentCursor(this.currentDropAction, 0, 0);
  138.    }
  139.  
  140.    public synchronized void dropActionChanged(DragSourceDragEvent var1) {
  141.       this.currentDropAction = var1.getDropAction();
  142.       if (this.listener != null) {
  143.          this.listener.dropActionChanged(var1);
  144.       }
  145.  
  146.       this.updateCurrentCursor(this.currentDropAction, var1.getTargetActions(), 3);
  147.    }
  148.  
  149.    public synchronized void dragDropEnd(DragSourceDropEvent var1) {
  150.       if (this.listener != null) {
  151.          this.listener.dragDropEnd(var1);
  152.       }
  153.  
  154.    }
  155.  
  156.    public Transferable getTransferable() {
  157.       return this.transferable;
  158.    }
  159.  
  160.    protected void updateCurrentCursor(int var1, int var2, int var3) {
  161.       if (this.cursorDirty && this.cursor != null) {
  162.          this.cursorDirty = false;
  163.       } else {
  164.          Object var4 = null;
  165.          switch (var3) {
  166.             default:
  167.                var2 = 0;
  168.             case 1:
  169.             case 2:
  170.             case 3:
  171.                int var5 = var1 & var2;
  172.                Cursor var6;
  173.                if (var5 == 0) {
  174.                   if ((var1 & 1073741824) == 1073741824) {
  175.                      var6 = DragSource.DefaultLinkNoDrop;
  176.                   } else if ((var1 & 2) == 2) {
  177.                      var6 = DragSource.DefaultMoveNoDrop;
  178.                   } else {
  179.                      var6 = DragSource.DefaultCopyNoDrop;
  180.                   }
  181.                } else if ((var5 & 1073741824) == 1073741824) {
  182.                   var6 = DragSource.DefaultLinkDrop;
  183.                } else if ((var5 & 2) == 2) {
  184.                   var6 = DragSource.DefaultMoveDrop;
  185.                } else {
  186.                   var6 = DragSource.DefaultCopyDrop;
  187.                }
  188.  
  189.                this.setCursor(var6);
  190.                this.cursorDirty = false;
  191.          }
  192.       }
  193.    }
  194. }
  195.