home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / SpinnerNumberModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.4 KB  |  145 lines

  1. package javax.swing;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public class SpinnerNumberModel extends AbstractSpinnerModel implements Serializable {
  6.    private Number stepSize;
  7.    private Number value;
  8.    private Comparable minimum;
  9.    private Comparable maximum;
  10.  
  11.    public SpinnerNumberModel(Number var1, Comparable var2, Comparable var3, Number var4) {
  12.       if (var1 != null && var4 != null) {
  13.          if ((var2 == null || var2.compareTo(var1) <= 0) && (var3 == null || var3.compareTo(var1) >= 0)) {
  14.             this.value = var1;
  15.             this.minimum = var2;
  16.             this.maximum = var3;
  17.             this.stepSize = var4;
  18.          } else {
  19.             throw new IllegalArgumentException("(minimum <= value <= maximum) is false");
  20.          }
  21.       } else {
  22.          throw new IllegalArgumentException("value and stepSize must be non-null");
  23.       }
  24.    }
  25.  
  26.    public SpinnerNumberModel(int var1, int var2, int var3, int var4) {
  27.       this(new Integer(var1), new Integer(var2), new Integer(var3), new Integer(var4));
  28.    }
  29.  
  30.    public SpinnerNumberModel(double var1, double var3, double var5, double var7) {
  31.       this(new Double(var1), new Double(var3), new Double(var5), new Double(var7));
  32.    }
  33.  
  34.    public SpinnerNumberModel() {
  35.       this(new Integer(0), (Comparable)null, (Comparable)null, new Integer(1));
  36.    }
  37.  
  38.    public void setMinimum(Comparable var1) {
  39.       if (var1 == null) {
  40.          if (this.minimum == null) {
  41.             return;
  42.          }
  43.       } else if (var1.equals(this.minimum)) {
  44.          return;
  45.       }
  46.  
  47.       this.minimum = var1;
  48.       this.fireStateChanged();
  49.    }
  50.  
  51.    public Comparable getMinimum() {
  52.       return this.minimum;
  53.    }
  54.  
  55.    public void setMaximum(Comparable var1) {
  56.       if (var1 == null) {
  57.          if (this.maximum == null) {
  58.             return;
  59.          }
  60.       } else if (var1.equals(this.maximum)) {
  61.          return;
  62.       }
  63.  
  64.       this.maximum = var1;
  65.       this.fireStateChanged();
  66.    }
  67.  
  68.    public Comparable getMaximum() {
  69.       return this.maximum;
  70.    }
  71.  
  72.    public void setStepSize(Number var1) {
  73.       if (var1 == null) {
  74.          throw new IllegalArgumentException("null stepSize");
  75.       } else {
  76.          if (!var1.equals(this.stepSize)) {
  77.             this.stepSize = var1;
  78.             this.fireStateChanged();
  79.          }
  80.  
  81.       }
  82.    }
  83.  
  84.    public Number getStepSize() {
  85.       return this.stepSize;
  86.    }
  87.  
  88.    private Number incrValue(int var1) {
  89.       Object var2;
  90.       if (!(this.value instanceof Float) && !(this.value instanceof Double)) {
  91.          long var5 = this.value.longValue() + this.stepSize.longValue() * (long)var1;
  92.          if (this.value instanceof Long) {
  93.             var2 = new Long(var5);
  94.          } else if (this.value instanceof Integer) {
  95.             var2 = new Integer((int)var5);
  96.          } else if (this.value instanceof Short) {
  97.             var2 = new Short((short)((int)var5));
  98.          } else {
  99.             var2 = new Byte((byte)((int)var5));
  100.          }
  101.       } else {
  102.          double var3 = this.value.doubleValue() + this.stepSize.doubleValue() * (double)var1;
  103.          if (this.value instanceof Double) {
  104.             var2 = new Double(var3);
  105.          } else {
  106.             var2 = new Float(var3);
  107.          }
  108.       }
  109.  
  110.       if (this.maximum != null && this.maximum.compareTo(var2) < 0) {
  111.          return null;
  112.       } else {
  113.          return (Number)(this.minimum != null && this.minimum.compareTo(var2) > 0 ? null : var2);
  114.       }
  115.    }
  116.  
  117.    public Object getNextValue() {
  118.       return this.incrValue(1);
  119.    }
  120.  
  121.    public Object getPreviousValue() {
  122.       return this.incrValue(-1);
  123.    }
  124.  
  125.    public Number getNumber() {
  126.       return this.value;
  127.    }
  128.  
  129.    public Object getValue() {
  130.       return this.value;
  131.    }
  132.  
  133.    public void setValue(Object var1) {
  134.       if (var1 != null && var1 instanceof Number) {
  135.          if (!var1.equals(this.value)) {
  136.             this.value = (Number)var1;
  137.             this.fireStateChanged();
  138.          }
  139.  
  140.       } else {
  141.          throw new IllegalArgumentException("illegal value");
  142.       }
  143.    }
  144. }
  145.