home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / awt / Font.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.7 KB  |  137 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.       this.family = System.getProperty("awt.font." + this.name.toLowerCase(), this.name);
  28.       this.peer = Toolkit.getDefaultToolkit().getFontPeer(this.name, this.style);
  29.    }
  30.  
  31.    public Font(String var1, int var2, int var3) {
  32.       this.name = var1;
  33.       this.style = var2;
  34.       this.size = var3;
  35.       this.initializeFont();
  36.    }
  37.  
  38.    public String getFamily() {
  39.       return this.family;
  40.    }
  41.  
  42.    public String getName() {
  43.       return this.name;
  44.    }
  45.  
  46.    public int getStyle() {
  47.       return this.style;
  48.    }
  49.  
  50.    public int getSize() {
  51.       return this.size;
  52.    }
  53.  
  54.    public boolean isPlain() {
  55.       return this.style == 0;
  56.    }
  57.  
  58.    public boolean isBold() {
  59.       return (this.style & 1) != 0;
  60.    }
  61.  
  62.    public boolean isItalic() {
  63.       return (this.style & 2) != 0;
  64.    }
  65.  
  66.    public static Font getFont(String var0) {
  67.       return getFont(var0, (Font)null);
  68.    }
  69.  
  70.    public static Font decode(String var0) {
  71.       String var1 = var0;
  72.       int var2 = 12;
  73.       byte var3 = 0;
  74.       int var4 = var0.indexOf(45);
  75.       if (var4 >= 0) {
  76.          var1 = var0.substring(0, var4);
  77.          var0 = var0.substring(var4 + 1);
  78.          if ((var4 = var0.indexOf(45)) >= 0) {
  79.             if (var0.startsWith("bold-")) {
  80.                var3 = 1;
  81.             } else if (var0.startsWith("italic-")) {
  82.                var3 = 2;
  83.             } else if (var0.startsWith("bolditalic-")) {
  84.                var3 = 3;
  85.             }
  86.  
  87.             var0 = var0.substring(var4 + 1);
  88.          }
  89.  
  90.          try {
  91.             var2 = Integer.valueOf(var0);
  92.          } catch (NumberFormatException var5) {
  93.          }
  94.       }
  95.  
  96.       return new Font(var1, var3, var2);
  97.    }
  98.  
  99.    public static Font getFont(String var0, Font var1) {
  100.       String var2 = System.getProperty(var0);
  101.       return var2 == null ? var1 : decode(var2);
  102.    }
  103.  
  104.    public int hashCode() {
  105.       return this.name.hashCode() ^ this.style ^ this.size;
  106.    }
  107.  
  108.    public boolean equals(Object var1) {
  109.       if (var1 instanceof Font) {
  110.          Font var2 = (Font)var1;
  111.          return this.size == var2.size && this.style == var2.style && this.name.equals(var2.name);
  112.       } else {
  113.          return false;
  114.       }
  115.    }
  116.  
  117.    public String toString() {
  118.       String var1;
  119.       if (this.isBold()) {
  120.          var1 = this.isItalic() ? "bolditalic" : "bold";
  121.       } else {
  122.          var1 = this.isItalic() ? "italic" : "plain";
  123.       }
  124.  
  125.       return this.getClass().getName() + "[family=" + this.family + ",name=" + this.name + ",style=" + var1 + ",size=" + this.size + "]";
  126.    }
  127.  
  128.    private void writeObject(ObjectOutputStream var1) throws ClassNotFoundException, IOException {
  129.       var1.defaultWriteObject();
  130.    }
  131.  
  132.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  133.       var1.defaultReadObject();
  134.       this.initializeFont();
  135.    }
  136. }
  137.