home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / html / CSS$LengthUnit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.8 KB  |  75 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Hashtable;
  5.  
  6. class CSS$LengthUnit implements Serializable {
  7.    static Hashtable lengthMapping = new Hashtable(6);
  8.    short type;
  9.    float value;
  10.    static final short UNINITALIZED_LENGTH = 10;
  11.  
  12.    CSS$LengthUnit(String var1, short var2, float var3) {
  13.       this.parse(var1, var2, var3);
  14.    }
  15.  
  16.    void parse(String var1, short var2, float var3) {
  17.       this.type = var2;
  18.       this.value = var3;
  19.       int var4 = var1.length();
  20.       if (var4 > 0 && var1.charAt(var4 - 1) == '%') {
  21.          try {
  22.             this.value = Float.valueOf(var1.substring(0, var4 - 1)) / 100.0F;
  23.             this.type = 1;
  24.          } catch (NumberFormatException var11) {
  25.          }
  26.       }
  27.  
  28.       if (var4 >= 2) {
  29.          String var5 = var1.substring(var4 - 2, var4);
  30.          Float var6 = (Float)lengthMapping.get(var5);
  31.          if (var6 != null) {
  32.             try {
  33.                this.value = Float.valueOf(var1.substring(0, var4 - 2)) * var6;
  34.                this.type = 0;
  35.             } catch (NumberFormatException var10) {
  36.             }
  37.          } else if (!var5.equals("em") && !var5.equals("ex")) {
  38.             if (var1.equals("larger")) {
  39.                this.value = 2.0F;
  40.                this.type = 2;
  41.             } else if (var1.equals("smaller")) {
  42.                this.value = -2.0F;
  43.                this.type = 2;
  44.             } else {
  45.                try {
  46.                   this.value = Float.valueOf(var1);
  47.                   this.type = 0;
  48.                } catch (NumberFormatException var8) {
  49.                }
  50.             }
  51.          } else {
  52.             try {
  53.                this.value = Float.valueOf(var1.substring(0, var4 - 2));
  54.                this.type = 3;
  55.             } catch (NumberFormatException var9) {
  56.             }
  57.          }
  58.       }
  59.  
  60.    }
  61.  
  62.    public String toString() {
  63.       return this.type + " " + this.value;
  64.    }
  65.  
  66.    static {
  67.       lengthMapping.put("pt", new Float(1.0F));
  68.       lengthMapping.put("px", new Float(1.3F));
  69.       lengthMapping.put("mm", new Float(2.83464F));
  70.       lengthMapping.put("cm", new Float(28.3464F));
  71.       lengthMapping.put("pc", new Float(12.0F));
  72.       lengthMapping.put("in", new Float(72.0F));
  73.    }
  74. }
  75.