home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / awt / Font.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  3.4 KB  |  117 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.       SecurityManager.setScopePermission();
  15.       this.family = System.getProperty("awt.font." + name.toLowerCase(), name);
  16.       this.name = name;
  17.       this.style = style;
  18.       this.size = size;
  19.    }
  20.  
  21.    public String getFamily() {
  22.       return this.family;
  23.    }
  24.  
  25.    public String getName() {
  26.       return this.name;
  27.    }
  28.  
  29.    public int getStyle() {
  30.       return this.style;
  31.    }
  32.  
  33.    public int getSize() {
  34.       return this.size;
  35.    }
  36.  
  37.    public boolean isPlain() {
  38.       return this.style == 0;
  39.    }
  40.  
  41.    public boolean isBold() {
  42.       return (this.style & 1) != 0;
  43.    }
  44.  
  45.    public boolean isItalic() {
  46.       return (this.style & 2) != 0;
  47.    }
  48.  
  49.    public void finalize() {
  50.       this.dispose();
  51.    }
  52.  
  53.    public synchronized native void dispose();
  54.  
  55.    public static Font getFont(String nm) {
  56.       return getFont(nm, (Font)null);
  57.    }
  58.  
  59.    public static Font getFont(String nm, Font font) {
  60.       String str = System.getProperty(nm);
  61.       if (str == null) {
  62.          return font;
  63.       } else {
  64.          String fontName = str;
  65.          int fontSize = 12;
  66.          int fontStyle = 0;
  67.          int i = str.indexOf(45);
  68.          if (i >= 0) {
  69.             fontName = str.substring(0, i);
  70.             str = str.substring(i + 1);
  71.             if ((i = str.indexOf(45)) >= 0) {
  72.                if (str.startsWith("bold-")) {
  73.                   fontStyle = 1;
  74.                } else if (str.startsWith("italic-")) {
  75.                   fontStyle = 2;
  76.                } else if (str.startsWith("bolditalic-")) {
  77.                   fontStyle = 3;
  78.                }
  79.  
  80.                str = str.substring(i + 1);
  81.             }
  82.  
  83.             try {
  84.                fontSize = Integer.valueOf(str);
  85.             } catch (NumberFormatException var7) {
  86.             }
  87.          }
  88.  
  89.          return new Font(fontName, fontStyle, fontSize);
  90.       }
  91.    }
  92.  
  93.    public int hashCode() {
  94.       return this.name.hashCode() ^ this.style ^ this.size;
  95.    }
  96.  
  97.    public boolean equals(Object obj) {
  98.       if (obj instanceof Font) {
  99.          Font font = (Font)obj;
  100.          return this.size == font.size && this.style == font.style && this.name.equals(font.name);
  101.       } else {
  102.          return false;
  103.       }
  104.    }
  105.  
  106.    public String toString() {
  107.       String strStyle;
  108.       if (this.isBold()) {
  109.          strStyle = this.isItalic() ? "bolditalic" : "bold";
  110.       } else {
  111.          strStyle = this.isItalic() ? "italic" : "plain";
  112.       }
  113.  
  114.       return this.getClass().getName() + "[family=" + this.family + ",name=" + this.name + ",style=" + strStyle + ",size=" + this.size + "]";
  115.    }
  116. }
  117.