home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / DragView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  3.8 KB  |  140 lines

  1. package netscape.application;
  2.  
  3. class DragView extends InternalWindow {
  4.    int animationCount;
  5.    int animationDeltaX;
  6.    int animationDeltaY;
  7.    boolean _animatingBack;
  8.    boolean _wasAccepted;
  9.    Timer timer;
  10.    DragSession session;
  11.  
  12.    public DragView() {
  13.    }
  14.  
  15.    public DragView(DragSession var1) {
  16.       ((InternalWindow)this).setBounds(var1.initialX, var1.initialY, var1.image.width(), var1.image.height());
  17.       this.session = var1;
  18.       super._lastX = var1.mouseDownX;
  19.       super._lastY = var1.mouseDownY;
  20.       ((InternalWindow)this).setType(0);
  21.       ((InternalWindow)this).setTransparent(var1.image.isTransparent());
  22.       ((InternalWindow)this).contentView().setTransparent(true);
  23.       ((InternalWindow)this).setLayer(400);
  24.       super._dragStart = true;
  25.       ((InternalWindow)this).setRootView(var1.rootView);
  26.       ((InternalWindow)this).show();
  27.       ((View)this).rootView().setMouseView(this);
  28.       ((View)this).draw();
  29.    }
  30.  
  31.    public void performCommand(String var1, Object var2) {
  32.       if ("animateRejectedDrag".equals(var1)) {
  33.          this.animateRejectedDrag();
  34.       } else {
  35.          super.performCommand(var1, var2);
  36.       }
  37.    }
  38.  
  39.    private void animateRejectedDrag() {
  40.       if (this.animationCount <= 0) {
  41.          this.timer.stop();
  42.          this.timer = null;
  43.          this._animatingBack = false;
  44.          this.animationCount = 0;
  45.          this.animationDeltaX = 0;
  46.          this.animationDeltaY = 0;
  47.          this.stopDragging();
  48.       } else {
  49.          --this.animationCount;
  50.          int var1 = super._lastX - (this.animationDeltaX + super.bounds.x);
  51.          int var2 = super._lastY - (this.animationDeltaY + super.bounds.y);
  52.          MouseEvent var3 = new MouseEvent(0L, -2, var1, var2, 0);
  53.          this.mouseDragged(var3);
  54.       }
  55.    }
  56.  
  57.    void startAnimatingRejectedDrag() {
  58.       this._animatingBack = true;
  59.       if (super._lastX - this.session.mouseDownX != 0 && super._lastY - this.session.mouseDownY != 0) {
  60.          float var1 = (float)(super._lastX - this.session.mouseDownX);
  61.          float var2 = (float)(super._lastY - this.session.mouseDownY);
  62.          int var3;
  63.          int var4;
  64.          if (var1 > var2) {
  65.             var3 = 1 + (int)(Math.abs(var2) / 5.0F);
  66.             var4 = (int)(Math.abs(var2) / (float)var3);
  67.             var1 /= Math.abs(var2);
  68.             if (var2 < 0.0F) {
  69.                var2 = -1.0F;
  70.             } else {
  71.                var2 = 1.0F;
  72.             }
  73.          } else if (var2 > var1) {
  74.             var3 = 1 + (int)(Math.abs(var1) / 5.0F);
  75.             var4 = (int)(Math.abs(var1) / (float)var3);
  76.             var2 /= Math.abs(var1);
  77.             if (var1 < 0.0F) {
  78.                var1 = -1.0F;
  79.             } else {
  80.                var1 = 1.0F;
  81.             }
  82.          } else {
  83.             var4 = 0;
  84.             var3 = 0;
  85.          }
  86.  
  87.          if (var4 > 0) {
  88.             this.animationCount = var4;
  89.             this.animationDeltaX = (int)((float)var3 * var1);
  90.             this.animationDeltaY = (int)((float)var3 * var2);
  91.             this.timer = new Timer(this, "animateRejectedDrag", 25);
  92.             this.timer.start();
  93.          } else {
  94.             this._animatingBack = false;
  95.             this.stopDragging();
  96.          }
  97.       } else {
  98.          this._animatingBack = false;
  99.          this.stopDragging();
  100.       }
  101.    }
  102.  
  103.    public boolean canBecomeMain() {
  104.       return false;
  105.    }
  106.  
  107.    public boolean canBecomeDocument() {
  108.       return false;
  109.    }
  110.  
  111.    public void mouseDragged(MouseEvent var1) {
  112.       super.mouseDragged(var1);
  113.       if (!this._animatingBack) {
  114.          this.session.mouseDragged(var1);
  115.       }
  116.  
  117.    }
  118.  
  119.    void stopDragging() {
  120.       if (((InternalWindow)this).isVisible()) {
  121.          ((InternalWindow)this).hide();
  122.          ((View)this).setBuffered(false);
  123.          super.rootView.redraw(super.bounds);
  124.       }
  125.    }
  126.  
  127.    public void mouseUp(MouseEvent var1) {
  128.       super.mouseUp(var1);
  129.       this.session.mouseUp(var1);
  130.    }
  131.  
  132.    public void drawView(Graphics var1) {
  133.       this.session.image.drawAt(var1, 0, 0);
  134.    }
  135.  
  136.    public View viewForMouse(int var1, int var2) {
  137.       return null;
  138.    }
  139. }
  140.