1 package org.columba.core.gui.util; 19 20 import java.awt.Font ; 21 import java.util.Observable ; 22 import java.util.Observer ; 23 24 import javax.swing.UIManager ; 25 import javax.swing.plaf.FontUIResource ; 26 27 import org.columba.core.config.Config; 28 import org.columba.core.xml.XmlElement; 29 30 31 49 public class FontProperties extends Observable implements Observer { 50 private static XmlElement fonts; 51 52 55 public FontProperties() { 56 XmlElement options = Config.getInstance().get("options").getElement("/options"); 57 XmlElement gui = options.getElement("gui"); 58 fonts = gui.getElement("fonts"); 59 60 if (fonts == null) { 61 fonts = gui.addSubElement("fonts"); 62 } 63 64 XmlElement mainFontElement = fonts.getElement("main"); 65 66 if (mainFontElement == null) { 67 mainFontElement = fonts.addSubElement("main"); 68 } 69 70 XmlElement textFontElement = fonts.getElement("text"); 71 72 if (textFontElement == null) { 73 textFontElement = fonts.addSubElement("text"); 74 } 75 76 fonts.addObserver(this); 78 } 79 80 86 public static Font getTextFont() { 87 return getFont("text"); 88 } 89 90 95 public static Font getMainFont() { 96 return getFont("main"); 97 } 98 99 106 protected static Font getFont(String id) { 107 XmlElement textFontElement = fonts.getElement(id); 108 109 if (textFontElement == null) { 110 textFontElement = fonts.addSubElement(id); 111 } 112 113 boolean overwrite = Boolean.valueOf(fonts.getAttribute("overwrite", 114 "true")).booleanValue(); 115 116 Font font = null; 117 String name = null; 118 String size = null; 119 120 if (!overwrite) { 121 name = "Default"; 122 size = "12"; 123 124 font = new Font (name, Font.PLAIN, Integer.parseInt(size)); 125 } else { 126 name = textFontElement.getAttribute("name", "Default"); 127 size = textFontElement.getAttribute("size", "12"); 128 129 font = new Font (name, Font.PLAIN, Integer.parseInt(size)); 130 } 131 132 return font; 133 } 134 135 142 public static void setFont() { 143 boolean overwrite = Boolean.valueOf(fonts.getAttribute("overwrite", 145 "true")).booleanValue(); 146 147 if (!overwrite) { 148 return; 149 } 150 151 FontUIResource mainFont = new FontUIResource (getFont("main")); 152 153 156 177 java.util.Enumeration keys = UIManager.getDefaults().keys(); 178 179 while (keys.hasMoreElements()) { 180 Object key = keys.nextElement(); 181 Object value = UIManager.get(key); 182 183 if (value instanceof javax.swing.plaf.FontUIResource ) { 184 UIManager.put(key, mainFont); 185 } 186 } 187 } 188 189 196 public void update(Observable arg0, Object arg1) { 197 } 198 } 199 | Popular Tags |