home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / java / awt / dnd / DropTarget.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.8 KB  |  270 lines

  1. package java.awt.dnd;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Point;
  5. import java.awt.datatransfer.FlavorMap;
  6. import java.awt.datatransfer.SystemFlavorMap;
  7. import java.awt.dnd.peer.DropTargetPeer;
  8. import java.awt.peer.ComponentPeer;
  9. import java.awt.peer.LightweightPeer;
  10. import java.io.Serializable;
  11. import java.util.TooManyListenersException;
  12.  
  13. public class DropTarget implements DropTargetListener, Serializable {
  14.    static final long serialVersionUID = -6283860791671019047L;
  15.    private static final FlavorMap defaultFlavorMap = SystemFlavorMap.getDefaultFlavorMap();
  16.    private transient DropTargetContext dropTargetContext;
  17.    private Component component;
  18.    private transient ComponentPeer componentPeer;
  19.    private transient ComponentPeer nativePeer;
  20.    int actions;
  21.    boolean active;
  22.    private transient DropTargetAutoScroller autoScroller;
  23.    private DropTargetListener dtListener;
  24.    private transient FlavorMap flavorMap;
  25.  
  26.    public DropTarget(Component var1, int var2, DropTargetListener var3, boolean var4, FlavorMap var5) {
  27.       this.actions = 3;
  28.       this.active = true;
  29.       this.flavorMap = defaultFlavorMap;
  30.       this.component = var1;
  31.       this.setDefaultActions(var2);
  32.       if (var3 != null) {
  33.          try {
  34.             this.addDropTargetListener(var3);
  35.          } catch (TooManyListenersException var7) {
  36.          }
  37.       }
  38.  
  39.       if (var1 != null) {
  40.          var1.setDropTarget(this);
  41.          this.setActive(var4);
  42.       }
  43.  
  44.       if (var5 != null) {
  45.          this.flavorMap = var5;
  46.       }
  47.  
  48.    }
  49.  
  50.    public DropTarget(Component var1, int var2, DropTargetListener var3, boolean var4) {
  51.       this(var1, var2, var3, var4, (FlavorMap)null);
  52.    }
  53.  
  54.    public DropTarget() {
  55.       this((Component)null, 3, (DropTargetListener)null, true, (FlavorMap)null);
  56.    }
  57.  
  58.    public DropTarget(Component var1, DropTargetListener var2) {
  59.       this(var1, 3, var2, true, (FlavorMap)null);
  60.    }
  61.  
  62.    public DropTarget(Component var1, int var2, DropTargetListener var3) {
  63.       this(var1, var2, var3, true);
  64.    }
  65.  
  66.    public synchronized void setComponent(Component var1) {
  67.       if (this.component != var1 && (this.component == null || !this.component.equals(var1))) {
  68.          ComponentPeer var3 = null;
  69.          Component var2;
  70.          if ((var2 = this.component) != null) {
  71.             this.clearAutoscroll();
  72.             this.component = null;
  73.             if (this.componentPeer != null) {
  74.                var3 = this.componentPeer;
  75.                this.removeNotify(this.componentPeer);
  76.             }
  77.  
  78.             var2.setDropTarget((DropTarget)null);
  79.          }
  80.  
  81.          if ((this.component = var1) != null) {
  82.             try {
  83.                var1.setDropTarget(this);
  84.             } catch (Exception var5) {
  85.                if (var2 != null) {
  86.                   var2.setDropTarget(this);
  87.                   this.addNotify(var3);
  88.                }
  89.             }
  90.          }
  91.  
  92.       }
  93.    }
  94.  
  95.    public synchronized Component getComponent() {
  96.       return this.component;
  97.    }
  98.  
  99.    public synchronized void setDefaultActions(int var1) {
  100.       this.actions = var1 & 1073741827;
  101.       if (this.dropTargetContext != null) {
  102.          this.dropTargetContext.setTargetActions(this.actions);
  103.       }
  104.  
  105.    }
  106.  
  107.    public synchronized int getDefaultActions() {
  108.       return this.actions;
  109.    }
  110.  
  111.    public synchronized void setActive(boolean var1) {
  112.       if (var1 != this.active) {
  113.          this.active = var1;
  114.       }
  115.  
  116.       if (!this.active) {
  117.          this.clearAutoscroll();
  118.       }
  119.  
  120.    }
  121.  
  122.    public synchronized boolean isActive() {
  123.       return this.active;
  124.    }
  125.  
  126.    public synchronized void addDropTargetListener(DropTargetListener var1) throws TooManyListenersException {
  127.       if (var1 != null) {
  128.          if (this.equals(var1)) {
  129.             throw new IllegalArgumentException("DropTarget may not be its own Listener");
  130.          } else if (this.dtListener == null) {
  131.             this.dtListener = var1;
  132.          } else {
  133.             throw new TooManyListenersException();
  134.          }
  135.       }
  136.    }
  137.  
  138.    public synchronized void removeDropTargetListener(DropTargetListener var1) {
  139.       if (var1 != null && this.dtListener != null) {
  140.          if (!this.dtListener.equals(var1)) {
  141.             throw new IllegalArgumentException("listener mismatch");
  142.          }
  143.  
  144.          this.dtListener = null;
  145.       }
  146.  
  147.    }
  148.  
  149.    public synchronized void dragEnter(DropTargetDragEvent var1) {
  150.       if (this.active) {
  151.          if (this.dtListener != null) {
  152.             this.dtListener.dragEnter(var1);
  153.          } else {
  154.             ((DropTargetEvent)var1).getDropTargetContext().setTargetActions(0);
  155.          }
  156.  
  157.          this.initializeAutoscrolling(var1.getLocation());
  158.       }
  159.    }
  160.  
  161.    public synchronized void dragOver(DropTargetDragEvent var1) {
  162.       if (this.active) {
  163.          if (this.dtListener != null && this.active) {
  164.             this.dtListener.dragOver(var1);
  165.          }
  166.  
  167.          this.updateAutoscroll(var1.getLocation());
  168.       }
  169.    }
  170.  
  171.    public void dropActionChanged(DropTargetDragEvent var1) {
  172.       if (this.active) {
  173.          if (this.dtListener != null) {
  174.             this.dtListener.dropActionChanged(var1);
  175.          }
  176.  
  177.          this.updateAutoscroll(var1.getLocation());
  178.       }
  179.    }
  180.  
  181.    public synchronized void dragExit(DropTargetEvent var1) {
  182.       if (this.active) {
  183.          if (this.dtListener != null && this.active) {
  184.             this.dtListener.dragExit(var1);
  185.          }
  186.  
  187.          this.clearAutoscroll();
  188.       }
  189.    }
  190.  
  191.    public synchronized void drop(DropTargetDropEvent var1) {
  192.       if (this.dtListener != null && this.active) {
  193.          this.dtListener.drop(var1);
  194.       } else {
  195.          var1.rejectDrop();
  196.       }
  197.  
  198.    }
  199.  
  200.    public FlavorMap getFlavorMap() {
  201.       return this.flavorMap;
  202.    }
  203.  
  204.    public void setFlavorMap(FlavorMap var1) {
  205.       this.flavorMap = var1 == null ? defaultFlavorMap : var1;
  206.    }
  207.  
  208.    public void addNotify(ComponentPeer var1) {
  209.       if (var1 != this.componentPeer) {
  210.          this.componentPeer = var1;
  211.  
  212.          for(Object var2 = this.component; var1 instanceof LightweightPeer; var2 = ((Component)var2).getParent()) {
  213.             var1 = ((Component)var2).getPeer();
  214.          }
  215.  
  216.          try {
  217.             ((DropTargetPeer)(this.nativePeer = var1)).addDropTarget(this);
  218.          } catch (ClassCastException var4) {
  219.             this.nativePeer = null;
  220.          }
  221.  
  222.       }
  223.    }
  224.  
  225.    public void removeNotify(ComponentPeer var1) {
  226.       if (this.nativePeer != null) {
  227.          ((DropTargetPeer)this.nativePeer).removeDropTarget(this);
  228.       }
  229.  
  230.       this.componentPeer = this.nativePeer = null;
  231.    }
  232.  
  233.    public DropTargetContext getDropTargetContext() {
  234.       if (this.dropTargetContext == null) {
  235.          this.dropTargetContext = this.createDropTargetContext();
  236.       }
  237.  
  238.       return this.dropTargetContext;
  239.    }
  240.  
  241.    protected DropTargetContext createDropTargetContext() {
  242.       return new DropTargetContext(this);
  243.    }
  244.  
  245.    protected DropTargetAutoScroller createDropTargetAutoScroller(Component var1, Point var2) {
  246.       return new DropTargetAutoScroller(var1, var2);
  247.    }
  248.  
  249.    protected void initializeAutoscrolling(Point var1) {
  250.       if (this.component != null && this.component instanceof Autoscroll) {
  251.          this.autoScroller = this.createDropTargetAutoScroller(this.component, var1);
  252.       }
  253.    }
  254.  
  255.    protected void updateAutoscroll(Point var1) {
  256.       if (this.autoScroller != null) {
  257.          this.autoScroller.updateLocation(var1);
  258.       }
  259.  
  260.    }
  261.  
  262.    protected void clearAutoscroll() {
  263.       if (this.autoScroller != null) {
  264.          this.autoScroller.stop();
  265.          this.autoScroller = null;
  266.       }
  267.  
  268.    }
  269. }
  270.