1 23 24 package org.infoglue.deliver.util.graphics; 25 26 35 41 42 44 45 import java.awt.Font ; 46 import java.util.Hashtable ; 47 48 public class FontSaver 49 { 50 51 private static Hashtable h; 52 53 60 61 public static Font create (String name, int style, int size) 62 { 63 if (h == null) 64 h = new Hashtable (101,.75f); 65 66 FontKey fontKey = new FontKey(name, style, size); 67 Font prevFont = (Font )h.get(fontKey); 68 69 if (prevFont != null) 70 return prevFont; 71 72 Font newFont = new Font (name, style, size); 73 74 h.put(fontKey, newFont); 75 76 return newFont; 77 } 78 79 } 80 81 82 86 87 class FontKey 88 { 89 90 97 98 public FontKey (String name, int style, int size) 99 { 100 this.name = name; 101 this.style = style; 102 this.size = size; 103 } 104 105 public boolean equals(Object obj) 106 { 107 if ( obj instanceof FontKey ) 108 { 109 FontKey fontKey = (FontKey)obj; 110 return(size == fontKey.size) && (style == fontKey.style) && name.equals(fontKey.name); 111 } 112 return false; 113 } 114 115 118 119 public int hashCode() 120 { 121 return name.hashCode() ^ style ^ size; 122 } 123 124 127 128 protected String name; 129 130 134 135 protected int style; 136 137 140 141 protected int size; 142 143 } | Popular Tags |