home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 August / maximum-cd-2000-08.iso / TeVeoLive / data1.cab / Program_Files / slider.jar / teveo / CustomSlider.class (.txt) next >
Encoding:
Java Class File  |  2000-03-06  |  5.4 KB  |  267 lines

  1. package teveo;
  2.  
  3. import java.awt.AWTEventMulticaster;
  4. import java.awt.Adjustable;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.Point;
  10. import java.awt.Rectangle;
  11. import java.awt.event.AdjustmentListener;
  12. import java.awt.image.ImageObserver;
  13.  
  14. public class CustomSlider extends Component implements Adjustable {
  15.    private transient AdjustmentListener adjustmentListener;
  16.    private int blockIncr;
  17.    private int min;
  18.    private int max;
  19.    private int orientation;
  20.    private int unitIncr;
  21.    private int val;
  22.    private int visAmount;
  23.    private transient Image bgImage;
  24.    private transient Image thumbImage;
  25.    private Point minPos;
  26.    private Point maxPos;
  27.    private Point thumbPos;
  28.    private boolean isDrag;
  29.  
  30.    public CustomSlider(Image var1, Image var2) {
  31.       this(var1, var2, 0);
  32.    }
  33.  
  34.    public CustomSlider(Image var1, Image var2, int var3) {
  35.       this.blockIncr = 10;
  36.       this.min = 0;
  37.       this.max = 100;
  38.       this.orientation = 0;
  39.       this.unitIncr = 1;
  40.       this.val = 0;
  41.       this.visAmount = 0;
  42.       this.thumbPos = new Point();
  43.       this.bgImage = var1;
  44.       this.thumbImage = var2;
  45.       Dimension var4 = this.getSize();
  46.       super.setSize(var4.width, var4.height);
  47.       if (var3 == 1) {
  48.          this.orientation = 1;
  49.          this.minPos = new Point(0, 0);
  50.          this.maxPos = new Point(var4.width - (this.thumbImage == null ? 0 : this.thumbImage.getWidth((ImageObserver)null)) - 1, 0);
  51.       } else {
  52.          this.orientation = 0;
  53.          this.minPos = new Point(0, 0);
  54.          this.maxPos = new Point(0, var4.height - (this.thumbImage == null ? 0 : this.thumbImage.getHeight((ImageObserver)null)) - 1);
  55.       }
  56.  
  57.       this.setValue(0);
  58.       ((Component)this).addMouseListener(new 1(this));
  59.       ((Component)this).addMouseMotionListener(new 2(this));
  60.    }
  61.  
  62.    // $FF: synthetic method
  63.    static boolean access$0(CustomSlider var0) {
  64.       return var0.isDrag;
  65.    }
  66.  
  67.    // $FF: synthetic method
  68.    static void access$1(CustomSlider var0, boolean var1) {
  69.       var0.isDrag = var1;
  70.    }
  71.  
  72.    // $FF: synthetic method
  73.    static Point access$2(CustomSlider var0) {
  74.       return var0.thumbPos;
  75.    }
  76.  
  77.    // $FF: synthetic method
  78.    static AdjustmentListener access$3(CustomSlider var0) {
  79.       return var0.adjustmentListener;
  80.    }
  81.  
  82.    // $FF: synthetic method
  83.    static Image access$4(CustomSlider var0) {
  84.       return var0.thumbImage;
  85.    }
  86.  
  87.    // $FF: synthetic method
  88.    static Point access$5(CustomSlider var0) {
  89.       return var0.minPos;
  90.    }
  91.  
  92.    // $FF: synthetic method
  93.    static Point access$6(CustomSlider var0) {
  94.       return var0.maxPos;
  95.    }
  96.  
  97.    // $FF: synthetic method
  98.    static int access$7(CustomSlider var0) {
  99.       return var0.min;
  100.    }
  101.  
  102.    // $FF: synthetic method
  103.    static int access$8(CustomSlider var0) {
  104.       return var0.max;
  105.    }
  106.  
  107.    public void addAdjustmentListener(AdjustmentListener var1) {
  108.       this.adjustmentListener = AWTEventMulticaster.add(this.adjustmentListener, var1);
  109.    }
  110.  
  111.    public int getBlockIncrement() {
  112.       return this.blockIncr;
  113.    }
  114.  
  115.    public int getMaximum() {
  116.       return this.max;
  117.    }
  118.  
  119.    public int getMinimum() {
  120.       return this.min;
  121.    }
  122.  
  123.    public Dimension getMinimumSize() {
  124.       return this.getSize();
  125.    }
  126.  
  127.    public int getOrientation() {
  128.       return this.orientation;
  129.    }
  130.  
  131.    public Dimension getPreferredSize() {
  132.       return this.getSize();
  133.    }
  134.  
  135.    public Dimension getSize() {
  136.       return this.bgImage == null ? super.getSize() : new Dimension(this.bgImage.getWidth((ImageObserver)null), this.bgImage.getHeight((ImageObserver)null));
  137.    }
  138.  
  139.    public int getTravelRange() {
  140.       int var1 = 0;
  141.       if (this.orientation == 0) {
  142.          var1 = this.maxPos.x - this.minPos.x;
  143.       } else if (this.orientation == 1) {
  144.          var1 = this.maxPos.y - this.minPos.y;
  145.       }
  146.  
  147.       return var1;
  148.    }
  149.  
  150.    public int getUnitIncrement() {
  151.       return this.unitIncr;
  152.    }
  153.  
  154.    public int getValue() {
  155.       return this.val;
  156.    }
  157.  
  158.    public int getVisibleAmount() {
  159.       return this.visAmount;
  160.    }
  161.  
  162.    protected boolean isInThumb(Point var1) {
  163.       Rectangle var2 = new Rectangle(this.thumbPos.x, this.thumbPos.y, this.thumbImage.getWidth((ImageObserver)null), this.thumbImage.getHeight((ImageObserver)null));
  164.       return var2.contains(var1);
  165.    }
  166.  
  167.    public void paint(Graphics var1) {
  168.       this.update(var1);
  169.    }
  170.  
  171.    public void removeAdjustmentListener(AdjustmentListener var1) {
  172.       this.adjustmentListener = AWTEventMulticaster.remove(this.adjustmentListener, var1);
  173.    }
  174.  
  175.    public void setBlockIncrement(int var1) {
  176.       this.blockIncr = Math.max(var1, this.getUnitIncrement());
  177.    }
  178.  
  179.    public void setMaximum(int var1) {
  180.       this.max = var1;
  181.    }
  182.  
  183.    public void setMinimum(int var1) {
  184.       this.min = var1;
  185.    }
  186.  
  187.    public void setSize(int var1, int var2) {
  188.    }
  189.  
  190.    public void setSize(Dimension var1) {
  191.       this.setSize(var1.width, var1.height);
  192.    }
  193.  
  194.    protected void setThumbPos(Point var1) {
  195.       if (this.orientation == 0) {
  196.          if (var1.x < this.minPos.x) {
  197.             var1.x = this.minPos.x;
  198.          } else if (var1.x > this.maxPos.x) {
  199.             var1.x = this.maxPos.x;
  200.          }
  201.  
  202.          if (var1.y != this.minPos.y) {
  203.             var1.y = this.minPos.y;
  204.          }
  205.       } else if (this.orientation == 1) {
  206.          if (var1.y < this.minPos.y) {
  207.             var1.y = this.minPos.y;
  208.          } else if (var1.y > this.maxPos.y) {
  209.             var1.y = this.maxPos.y;
  210.          }
  211.  
  212.          if (var1.x != this.minPos.x) {
  213.             var1.x = this.minPos.x;
  214.          }
  215.       }
  216.  
  217.       this.thumbPos = var1;
  218.       ((Component)this).repaint();
  219.    }
  220.  
  221.    public void setTravel(Point var1, Point var2) {
  222.       this.minPos = var1;
  223.       this.maxPos = var2;
  224.    }
  225.  
  226.    public void setUnitIncrement(int var1) {
  227.       this.unitIncr = Math.min(var1, this.getBlockIncrement());
  228.    }
  229.  
  230.    public void setValue(int var1) {
  231.       if (var1 < this.min) {
  232.          var1 = this.min;
  233.       } else if (var1 > this.max) {
  234.          var1 = this.max;
  235.       }
  236.  
  237.       var1 -= var1 % this.unitIncr;
  238.       this.val = var1;
  239.       Point var2 = new Point();
  240.       int var3 = this.max - this.min;
  241.       int var4 = this.getTravelRange();
  242.       switch (this.orientation) {
  243.          case 0:
  244.             var2.x = this.minPos.x + var4 * this.val / var3;
  245.             var2.y = this.minPos.y;
  246.             break;
  247.          case 1:
  248.             var2.y = this.minPos.y + var4 * this.val / var3;
  249.             var2.x = this.minPos.x;
  250.             break;
  251.          default:
  252.             return;
  253.       }
  254.  
  255.       this.setThumbPos(var2);
  256.    }
  257.  
  258.    public void setVisibleAmount(int var1) {
  259.       this.visAmount = var1;
  260.    }
  261.  
  262.    public void update(Graphics var1) {
  263.       var1.drawImage(this.bgImage, 0, 0, (ImageObserver)null);
  264.       var1.drawImage(this.thumbImage, this.thumbPos.x, this.thumbPos.y, (ImageObserver)null);
  265.    }
  266. }
  267.