home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / Autoscroller.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  2.3 KB  |  64 lines

  1. package javax.swing;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.event.InputEvent;
  7. import java.awt.event.MouseAdapter;
  8. import java.awt.event.MouseEvent;
  9. import java.io.IOException;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.Serializable;
  13.  
  14. class Autoscroller extends MouseAdapter implements Serializable {
  15.    transient MouseEvent event;
  16.    transient Timer timer;
  17.    JComponent component;
  18.  
  19.    Autoscroller(JComponent var1) {
  20.       if (var1 == null) {
  21.          throw new IllegalArgumentException("component must be non null");
  22.       } else {
  23.          this.component = var1;
  24.          this.timer = new Timer(100, new AutoScrollTimerAction(this));
  25.          this.component.addMouseListener(this);
  26.       }
  27.    }
  28.  
  29.    public void mouseDragged(MouseEvent var1) {
  30.       Rectangle var2 = this.component.getVisibleRect();
  31.       boolean var3 = var2.contains(var1.getX(), var1.getY());
  32.       if (var3) {
  33.          if (this.timer.isRunning()) {
  34.             this.stop();
  35.          }
  36.       } else {
  37.          Point var4 = this.component.getLocationOnScreen();
  38.          this.event = new MouseEvent(this.component, ((AWTEvent)var1).getID(), ((InputEvent)var1).getWhen(), ((InputEvent)var1).getModifiers(), var1.getX() + var4.x, var1.getY() + var4.y, var1.getClickCount(), var1.isPopupTrigger());
  39.          if (!this.timer.isRunning()) {
  40.             this.timer.start();
  41.          }
  42.       }
  43.  
  44.    }
  45.  
  46.    public void mouseReleased(MouseEvent var1) {
  47.       this.stop();
  48.    }
  49.  
  50.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  51.       var1.defaultReadObject();
  52.       this.timer = new Timer(100, new AutoScrollTimerAction(this));
  53.    }
  54.  
  55.    void stop() {
  56.       this.timer.stop();
  57.       this.event = null;
  58.    }
  59.  
  60.    private void writeObject(ObjectOutputStream var1) throws IOException {
  61.       var1.defaultWriteObject();
  62.    }
  63. }
  64.