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

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8. import netscape.util.Vector;
  9.  
  10. public class Size implements Codable {
  11.    public int width;
  12.    public int height;
  13.    private static Vector _sizeCache = new Vector();
  14.    private static boolean _cacheSizes = true;
  15.    static final String WIDTH_KEY = "width";
  16.    static final String HEIGHT_KEY = "height";
  17.  
  18.    public Size() {
  19.    }
  20.  
  21.    public Size(int var1, int var2) {
  22.       this.width = var1;
  23.       this.height = var2;
  24.    }
  25.  
  26.    public Size(Size var1) {
  27.       this.width = var1.width;
  28.       this.height = var1.height;
  29.    }
  30.  
  31.    public boolean isEmpty() {
  32.       return this.width == 0 || this.height == 0;
  33.    }
  34.  
  35.    public String toString() {
  36.       return "(" + this.width + ", " + this.height + ")";
  37.    }
  38.  
  39.    public void sizeTo(int var1, int var2) {
  40.       this.width = var1;
  41.       this.height = var2;
  42.    }
  43.  
  44.    public void sizeBy(int var1, int var2) {
  45.       this.sizeTo(this.width + var1, this.height + var2);
  46.    }
  47.  
  48.    public void union(Size var1) {
  49.       if (this.width < var1.width) {
  50.          this.width = var1.width;
  51.       }
  52.  
  53.       if (this.height < var1.height) {
  54.          this.height = var1.height;
  55.       }
  56.  
  57.    }
  58.  
  59.    public boolean equals(Object var1) {
  60.       if (!(var1 instanceof Size)) {
  61.          return false;
  62.       } else {
  63.          Size var2 = (Size)var1;
  64.          return var2.width == this.width && var2.height == this.height;
  65.       }
  66.    }
  67.  
  68.    public int hashCode() {
  69.       return this.width ^ this.height;
  70.    }
  71.  
  72.    public void describeClassInfo(ClassInfo var1) {
  73.       var1.addClass("netscape.application.Size", 1);
  74.       var1.addField("width", (byte)8);
  75.       var1.addField("height", (byte)8);
  76.    }
  77.  
  78.    public void encode(Encoder var1) throws CodingException {
  79.       var1.encodeInt("width", this.width);
  80.       var1.encodeInt("height", this.height);
  81.    }
  82.  
  83.    public void decode(Decoder var1) throws CodingException {
  84.       this.width = var1.decodeInt("width");
  85.       this.height = var1.decodeInt("height");
  86.    }
  87.  
  88.    public void finishDecoding() throws CodingException {
  89.    }
  90.  
  91.    static Size newSize(int var0, int var1) {
  92.       Vector var3 = _sizeCache;
  93.       synchronized(var3){}
  94.  
  95.       Size var2;
  96.       label47: {
  97.          Size var5;
  98.          try {
  99.             if (_cacheSizes && !_sizeCache.isEmpty()) {
  100.                var2 = (Size)_sizeCache.removeLastElement();
  101.                break label47;
  102.             }
  103.  
  104.             var5 = new Size(var0, var1);
  105.          } catch (Throwable var7) {
  106.             throw var7;
  107.          }
  108.  
  109.          return var5;
  110.       }
  111.  
  112.       var2.sizeTo(var0, var1);
  113.       return var2;
  114.    }
  115.  
  116.    static Size newSize(Size var0) {
  117.       return var0 == null ? newSize(0, 0) : newSize(var0.width, var0.height);
  118.    }
  119.  
  120.    static Size newSize() {
  121.       return newSize(0, 0);
  122.    }
  123.  
  124.    static void returnSize(Size var0) {
  125.       if (_cacheSizes) {
  126.          Vector var1 = _sizeCache;
  127.          synchronized(var1){}
  128.  
  129.          try {
  130.             if (_sizeCache.count() < 30) {
  131.                _sizeCache.addElement(var0);
  132.             }
  133.          } catch (Throwable var3) {
  134.             throw var3;
  135.          }
  136.  
  137.       }
  138.    }
  139.  
  140.    static void returnSizes(Vector var0) {
  141.       if (var0 != null && _cacheSizes) {
  142.          int var1 = var0.count();
  143.  
  144.          while(var1-- > 0) {
  145.             returnSize((Size)var0.elementAt(var1));
  146.          }
  147.  
  148.          var0.removeAllElements();
  149.       }
  150.    }
  151.  
  152.    static void setShouldCacheSizes(boolean var0) {
  153.       Vector var1 = _sizeCache;
  154.       synchronized(var1){}
  155.  
  156.       try {
  157.          _cacheSizes = var0;
  158.          if (!_cacheSizes) {
  159.             _sizeCache.removeAllElements();
  160.          }
  161.       } catch (Throwable var3) {
  162.          throw var3;
  163.       }
  164.  
  165.    }
  166. }
  167.