home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / java / awt / Font.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  3.9 KB  |  141 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.FontPeer;
  4. import java.io.IOException;
  5. import java.io.ObjectInputStream;
  6. import java.io.ObjectOutputStream;
  7. import java.io.Serializable;
  8.  
  9. public class Font implements Serializable {
  10.    public static final int PLAIN = 0;
  11.    public static final int BOLD = 1;
  12.    public static final int ITALIC = 2;
  13.    private transient int pData;
  14.    private transient String family;
  15.    protected String name;
  16.    protected int style;
  17.    protected int size;
  18.    transient FontPeer peer;
  19.    private static final long serialVersionUID = -4206021311591459213L;
  20.    private int fontSerializedDataVersion = 1;
  21.  
  22.    public FontPeer getPeer() {
  23.       return this.peer;
  24.    }
  25.  
  26.    private void initializeFont() {
  27.       SecurityManager.enablePrivilege("UniversalPropertyRead");
  28.       this.family = System.getProperty("awt.font." + this.name.toLowerCase(), this.name);
  29.       SecurityManager.revertPrivilege();
  30.       this.peer = Toolkit.getDefaultToolkit().getFontPeer(this.name, this.style);
  31.    }
  32.  
  33.    public Font(String var1, int var2, int var3) {
  34.       this.name = var1;
  35.       this.style = var2;
  36.       this.size = var3;
  37.       this.initializeFont();
  38.    }
  39.  
  40.    public String getFamily() {
  41.       return this.family;
  42.    }
  43.  
  44.    public String getName() {
  45.       return this.name;
  46.    }
  47.  
  48.    public int getStyle() {
  49.       return this.style;
  50.    }
  51.  
  52.    public int getSize() {
  53.       return this.size;
  54.    }
  55.  
  56.    public boolean isPlain() {
  57.       return this.style == 0;
  58.    }
  59.  
  60.    public boolean isBold() {
  61.       return (this.style & 1) != 0;
  62.    }
  63.  
  64.    public boolean isItalic() {
  65.       return (this.style & 2) != 0;
  66.    }
  67.  
  68.    public static Font getFont(String var0) {
  69.       return getFont(var0, (Font)null);
  70.    }
  71.  
  72.    public static Font decode(String var0) {
  73.       String var1 = var0;
  74.       int var2 = 12;
  75.       byte var3 = 0;
  76.       int var4 = var0.indexOf(45);
  77.       if (var4 >= 0) {
  78.          var1 = var0.substring(0, var4);
  79.          var0 = var0.substring(var4 + 1);
  80.          if ((var4 = var0.indexOf(45)) >= 0) {
  81.             if (var0.startsWith("bold-")) {
  82.                var3 = 1;
  83.             } else if (var0.startsWith("italic-")) {
  84.                var3 = 2;
  85.             } else if (var0.startsWith("bolditalic-")) {
  86.                var3 = 3;
  87.             }
  88.  
  89.             var0 = var0.substring(var4 + 1);
  90.          }
  91.  
  92.          try {
  93.             var2 = Integer.valueOf(var0);
  94.          } catch (NumberFormatException var5) {
  95.          }
  96.       }
  97.  
  98.       return new Font(var1, var3, var2);
  99.    }
  100.  
  101.    public static Font getFont(String var0, Font var1) {
  102.       SecurityManager.enablePrivilege("UniversalPropertyRead");
  103.       String var2 = System.getProperty(var0);
  104.       SecurityManager.revertPrivilege();
  105.       return var2 == null ? var1 : decode(var2);
  106.    }
  107.  
  108.    public int hashCode() {
  109.       return this.name.hashCode() ^ this.style ^ this.size;
  110.    }
  111.  
  112.    public boolean equals(Object var1) {
  113.       if (var1 instanceof Font) {
  114.          Font var2 = (Font)var1;
  115.          return this.size == var2.size && this.style == var2.style && this.name.equals(var2.name);
  116.       } else {
  117.          return false;
  118.       }
  119.    }
  120.  
  121.    public String toString() {
  122.       String var1;
  123.       if (this.isBold()) {
  124.          var1 = this.isItalic() ? "bolditalic" : "bold";
  125.       } else {
  126.          var1 = this.isItalic() ? "italic" : "plain";
  127.       }
  128.  
  129.       return this.getClass().getName() + "[family=" + this.family + ",name=" + this.name + ",style=" + var1 + ",size=" + this.size + "]";
  130.    }
  131.  
  132.    private void writeObject(ObjectOutputStream var1) throws ClassNotFoundException, IOException {
  133.       var1.defaultWriteObject();
  134.    }
  135.  
  136.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  137.       var1.defaultReadObject();
  138.       this.initializeFont();
  139.    }
  140. }
  141.