home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / java / awt / Font.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-08  |  3.2 KB  |  110 lines

  1. package java.awt;
  2.  
  3. public class Font {
  4.    public static final int PLAIN = 0;
  5.    public static final int BOLD = 1;
  6.    public static final int ITALIC = 2;
  7.    private int pData;
  8.    private String family;
  9.    protected String name;
  10.    protected int style;
  11.    protected int size;
  12.  
  13.    public Font(String name, int style, int size) {
  14.       this.family = System.getProperty("awt.font." + name.toLowerCase(), name);
  15.       this.name = name;
  16.       this.style = style;
  17.       this.size = size;
  18.    }
  19.  
  20.    public String getFamily() {
  21.       return this.family;
  22.    }
  23.  
  24.    public String getName() {
  25.       return this.name;
  26.    }
  27.  
  28.    public int getStyle() {
  29.       return this.style;
  30.    }
  31.  
  32.    public int getSize() {
  33.       return this.size;
  34.    }
  35.  
  36.    public boolean isPlain() {
  37.       return this.style == 0;
  38.    }
  39.  
  40.    public boolean isBold() {
  41.       return (this.style & 1) != 0;
  42.    }
  43.  
  44.    public boolean isItalic() {
  45.       return (this.style & 2) != 0;
  46.    }
  47.  
  48.    public static Font getFont(String nm) {
  49.       return getFont(nm, (Font)null);
  50.    }
  51.  
  52.    public static Font getFont(String nm, Font font) {
  53.       String str = System.getProperty(nm);
  54.       if (str == null) {
  55.          return font;
  56.       } else {
  57.          String fontName = str;
  58.          int fontSize = 12;
  59.          int fontStyle = 0;
  60.          int i = str.indexOf(45);
  61.          if (i >= 0) {
  62.             fontName = str.substring(0, i);
  63.             str = str.substring(i + 1);
  64.             if ((i = str.indexOf(45)) >= 0) {
  65.                if (str.startsWith("bold-")) {
  66.                   fontStyle = 1;
  67.                } else if (str.startsWith("italic-")) {
  68.                   fontStyle = 2;
  69.                } else if (str.startsWith("bolditalic-")) {
  70.                   fontStyle = 3;
  71.                }
  72.  
  73.                str = str.substring(i + 1);
  74.             }
  75.  
  76.             try {
  77.                fontSize = Integer.valueOf(str);
  78.             } catch (NumberFormatException var7) {
  79.             }
  80.          }
  81.  
  82.          return new Font(fontName, fontStyle, fontSize);
  83.       }
  84.    }
  85.  
  86.    public int hashCode() {
  87.       return this.name.hashCode() ^ this.style ^ this.size;
  88.    }
  89.  
  90.    public boolean equals(Object obj) {
  91.       if (obj instanceof Font) {
  92.          Font font = (Font)obj;
  93.          return this.size == font.size && this.style == font.style && this.name.equals(font.name);
  94.       } else {
  95.          return false;
  96.       }
  97.    }
  98.  
  99.    public String toString() {
  100.       String strStyle;
  101.       if (this.isBold()) {
  102.          strStyle = this.isItalic() ? "bolditalic" : "bold";
  103.       } else {
  104.          strStyle = this.isItalic() ? "italic" : "plain";
  105.       }
  106.  
  107.       return this.getClass().getName() + "[family=" + this.family + ",name=" + this.name + ",style=" + strStyle + ",size=" + this.size + "]";
  108.    }
  109. }
  110.