home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / DragSession.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  5.9 KB  |  249 lines

  1. package netscape.application;
  2.  
  3. public class DragSession {
  4.    String dataType;
  5.    Object data;
  6.    Image image;
  7.    int initialX;
  8.    int initialY;
  9.    int mouseDownX;
  10.    int mouseDownY;
  11.    int mouseX;
  12.    int mouseY;
  13.    DragSource source;
  14.    DragDestination destination;
  15.    DragView dragView;
  16.    int modifiers;
  17.    RootView rootView;
  18.    View sourceView;
  19.    View destinationView;
  20.    boolean isAccepting;
  21.    public static final int SHIFT_MASK = 1;
  22.    public static final int CONTROL_MASK = 2;
  23.    public static final int META_MASK = 4;
  24.    public static final int ALT_MASK = 8;
  25.  
  26.    public DragSession(DragSource var1, Image var2, int var3, int var4, int var5, int var6, String var7, Object var8, boolean var9) {
  27.       Point var10 = new Point();
  28.       Point var11 = new Point();
  29.       this.sourceView = var1.sourceView(this);
  30.       this.rootView = this.sourceView.rootView();
  31.       this.sourceView.convertToView((View)null, var3, var4, var10);
  32.       this.sourceView.convertToView((View)null, var5, var6, var11);
  33.       if (this.rootView.windowClipView() != null) {
  34.          this.rootView.convertPointToView(this.rootView.windowClipView(), var10, var10);
  35.          this.rootView.convertPointToView(this.rootView.windowClipView(), var11, var11);
  36.       }
  37.  
  38.       this.source = var1;
  39.       this.image = var2;
  40.       this.initialX = var10.x;
  41.       this.initialY = var10.y;
  42.       this.mouseDownX = var11.x;
  43.       this.mouseDownY = var11.y;
  44.       this.dataType = var7;
  45.       this.data = var8;
  46.       if (var9) {
  47.          this.dragView = new DragView(this);
  48.       }
  49.  
  50.    }
  51.  
  52.    public DragSession(DragSource var1, Image var2, int var3, int var4, int var5, int var6, String var7, Object var8) {
  53.       this(var1, var2, var3, var4, var5, var6, var7, var8, true);
  54.    }
  55.  
  56.    public Object data() {
  57.       return this.data;
  58.    }
  59.  
  60.    public void setData(Object var1) {
  61.       this.data = var1;
  62.    }
  63.  
  64.    public String dataType() {
  65.       return this.dataType;
  66.    }
  67.  
  68.    public void setDataType(String var1) {
  69.       this.dataType = var1;
  70.    }
  71.  
  72.    public DragSource source() {
  73.       return this.source;
  74.    }
  75.  
  76.    public DragDestination destination() {
  77.       return this.destination();
  78.    }
  79.  
  80.    public int dragModifiers() {
  81.       return this.modifiers;
  82.    }
  83.  
  84.    public boolean isShiftKeyDown() {
  85.       return (this.modifiers & 1) != 0;
  86.    }
  87.  
  88.    public boolean isControlKeyDown() {
  89.       return (this.modifiers & 2) != 0;
  90.    }
  91.  
  92.    public boolean isMetaKeyDown() {
  93.       return (this.modifiers & 4) != 0;
  94.    }
  95.  
  96.    public boolean isAltKeyDown() {
  97.       return (this.modifiers & 8) != 0;
  98.    }
  99.  
  100.    void updateModifiers(MouseEvent var1) {
  101.       this.modifiers = 0;
  102.       if (var1 != null) {
  103.          if (var1.isShiftKeyDown()) {
  104.             ++this.modifiers;
  105.          }
  106.  
  107.          if (var1.isControlKeyDown()) {
  108.             this.modifiers += 2;
  109.          }
  110.  
  111.          if (var1.isMetaKeyDown()) {
  112.             this.modifiers += 4;
  113.          }
  114.  
  115.          if (var1.isAltKeyDown()) {
  116.             this.modifiers += 8;
  117.          }
  118.  
  119.       }
  120.    }
  121.  
  122.    public void mouseDragged(MouseEvent var1) {
  123.       DragDestination var4 = null;
  124.       Point var6 = new Point(var1.x, var1.y);
  125.       if (this.dragView != null) {
  126.          this.dragView.convertPointToView((View)null, var6, var6);
  127.       }
  128.  
  129.       int var2 = var6.x;
  130.       int var3 = var6.y;
  131.       this.updateModifiers(var1);
  132.       View var5 = this.rootView.viewForMouse(var2, var3);
  133.       if (this.rootView.viewExcludedFromModalSession(var5)) {
  134.          var5 = null;
  135.       }
  136.  
  137.       if (var5 != null) {
  138.          Point var7 = Point.newPoint();
  139.          this.rootView.convertToView(var5, var2, var3, var7);
  140.  
  141.          for(var4 = var5.acceptsDrag(this, var7.x, var7.y); var4 == null && var5._superview != null; var4 = var5.acceptsDrag(this, var7.x, var7.y)) {
  142.             var7.x += var5.bounds.x;
  143.             var7.y += var5.bounds.y;
  144.             var5 = var5._superview;
  145.          }
  146.  
  147.          Point.returnPoint(var7);
  148.       }
  149.  
  150.       if (this.destination == null && var4 != null) {
  151.          this.destination = var4;
  152.          this.destinationView = var5;
  153.          this.isAccepting = this.destination.dragEntered(this);
  154.       } else if (this.destination != null && var4 == null) {
  155.          this.destination.dragExited(this);
  156.          this.destination = null;
  157.          this.destinationView = null;
  158.       } else if (this.destination != var4) {
  159.          this.destination.dragExited(this);
  160.          this.destination = var4;
  161.          this.destinationView = var5;
  162.          this.destination.dragEntered(this);
  163.       } else {
  164.          if (this.destination != null) {
  165.             this.isAccepting = this.destination.dragMoved(this);
  166.          }
  167.  
  168.       }
  169.    }
  170.  
  171.    public void mouseUp(MouseEvent var1) {
  172.       boolean var2 = false;
  173.       boolean var3 = false;
  174.  
  175.       try {
  176.          this.updateModifiers(var1);
  177.          if (this.destination != null && this.isAccepting) {
  178.             var2 = this.destination.dragDropped(this);
  179.          }
  180.  
  181.          if (var2) {
  182.             this.source.dragWasAccepted(this);
  183.          } else {
  184.             var3 = this.source.dragWasRejected(this);
  185.          }
  186.       } finally {
  187.          this.isAccepting = false;
  188.          if (this.dragView != null) {
  189.             if (var3) {
  190.                this.dragView.startAnimatingRejectedDrag();
  191.             } else {
  192.                this.dragView.stopDragging();
  193.             }
  194.          }
  195.  
  196.       }
  197.  
  198.    }
  199.  
  200.    public View destinationView() {
  201.       return this.destinationView;
  202.    }
  203.  
  204.    public Rect destinationBounds() {
  205.       if (this.destinationView == null) {
  206.          return null;
  207.       } else {
  208.          Rect var1 = this.absoluteBounds();
  209.          this.rootView.convertRectToView(this.destinationView, var1, var1);
  210.          return var1;
  211.       }
  212.    }
  213.  
  214.    public Rect absoluteBounds() {
  215.       Rect var1 = new Rect(0, 0, this.image.width(), this.image.height());
  216.       if (this.dragView != null) {
  217.          this.dragView.convertRectToView((View)null, var1, var1);
  218.       }
  219.  
  220.       return var1;
  221.    }
  222.  
  223.    public Point absoluteMousePoint() {
  224.       if (this.dragView != null) {
  225.          Point var1 = new Point(this.dragView._lastX, this.dragView._lastY);
  226.          this.dragView.superview().convertPointToView((View)null, var1, var1);
  227.          return var1;
  228.       } else {
  229.          return new Point(0, 0);
  230.       }
  231.    }
  232.  
  233.    public Point destinationMousePoint() {
  234.       if (this.destinationView == null) {
  235.          return null;
  236.       } else if (this.dragView != null) {
  237.          Point var1 = new Point(this.dragView._lastX, this.dragView._lastY);
  238.          this.dragView.superview().convertPointToView(this.destinationView, var1, var1);
  239.          return var1;
  240.       } else {
  241.          return new Point(0, 0);
  242.       }
  243.    }
  244.  
  245.    public boolean destinationIsAccepting() {
  246.       return this.isAccepting;
  247.    }
  248. }
  249.