1 30 31 package com.jgoodies.looks; 32 33 import java.awt.Font ; 34 35 import javax.swing.UIDefaults ; 36 import javax.swing.UIManager ; 37 import javax.swing.plaf.FontUIResource ; 38 39 48 49 public final class FontUtils { 50 51 private FontUtils() { 52 } 54 55 56 68 public static boolean useSystemFontSettings() { 69 String systemFonts = LookUtils 70 .getSystemProperty(Options.USE_SYSTEM_FONTS_KEY); 71 if ("false".equalsIgnoreCase(systemFonts)) 72 return false; 73 74 Object value = UIManager.get(Options.USE_SYSTEM_FONTS_APP_KEY); 75 return !Boolean.FALSE.equals(value); 76 } 77 78 79 80 94 public static void initFontDefaults(UIDefaults table, 95 Object controlFont, Object controlBoldFont, Object fixedControlFont, 96 Object menuFont, Object messageFont, Object toolTipFont, Object windowFont) { 97 98 102 Object [] defaults = { 103 "Button.font", controlFont, 104 "CheckBox.font", controlFont, 105 "ColorChooser.font", controlFont, 106 "ComboBox.font", controlFont, 107 "EditorPane.font", controlFont, 108 "FormattedTextField.font", controlFont, 109 "Label.font", controlFont, 110 "List.font", controlFont, 111 "Panel.font", controlFont, 112 "PasswordField.font", controlFont, 113 "ProgressBar.font", controlFont, 114 "RadioButton.font", controlFont, 115 "ScrollPane.font", controlFont, 116 "Spinner.font", controlFont, 117 "TabbedPane.font", controlFont, 118 "Table.font", controlFont, 119 "TableHeader.font", controlFont, 120 "TextField.font", controlFont, 121 "TextPane.font", controlFont, 122 "ToolBar.font", controlFont, 123 "ToggleButton.font", controlFont, 124 "Tree.font", controlFont, 125 "Viewport.font", controlFont, 126 127 "InternalFrame.titleFont", windowFont, "OptionPane.font", messageFont, 129 "OptionPane.messageFont", messageFont, 130 "OptionPane.buttonFont", messageFont, 131 "Spinner.font", fixedControlFont, 132 "TextArea.font", fixedControlFont, 133 "TitledBorder.font", controlBoldFont, 134 "ToolTip.font", toolTipFont, 135 }; 136 table.putDefaults(defaults); 137 138 if (menuFont != null) { 139 Object [] menuDefaults = { 140 "CheckBoxMenuItem.font", menuFont, 141 "CheckBoxMenuItem.acceleratorFont", menuFont, "Menu.font", menuFont, 143 "Menu.acceleratorFont", menuFont, 144 "MenuBar.font", menuFont, 145 "MenuItem.font", menuFont, 146 "MenuItem.acceleratorFont", menuFont, 147 "PopupMenu.font", menuFont, 148 "RadioButtonMenuItem.font", menuFont, 149 "RadioButtonMenuItem.acceleratorFont", menuFont, }; 151 table.putDefaults(menuDefaults); 152 } 153 } 154 155 156 174 public static Font getMenuFont(UIDefaults table, FontSizeHints hints) { 175 String fontDescription = LookUtils.getSystemProperty(Options.MENU_FONT_KEY); 177 if (fontDescription != null) { 178 return Font.decode(fontDescription); 179 } 180 181 Font menuFont= table.getFont("Menu.font"); 182 if (menuFont.getName().equals("Tahoma")) { 183 float size = menuFont.getSize() + hints.menuFontSizeDelta(); 184 float minSize = hints.menuFontSize(); 185 menuFont = menuFont.deriveFont(Math.max(minSize, size)); 186 } 187 188 return new FontUIResource (menuFont); 189 } 190 191 192 210 public static Font getControlFont(UIDefaults table, FontSizeHints hints) { 211 String fontDescription = LookUtils.getSystemProperty(Options.CONTROL_FONT_KEY); 213 if (fontDescription != null) { 214 return Font.decode(fontDescription); 215 } 216 217 Font controlFont; 218 222 String fontKey = LookUtils.IS_JAVA_1_4_0 223 ? "Label.font" 224 : "OptionPane.font"; 225 controlFont = table.getFont(fontKey); 226 if (controlFont.getName().equals("Tahoma")) { 227 float oldSize = controlFont.getSize(); 228 float minSize = hints.controlFontSize(); 229 float size = oldSize + hints.controlFontSizeDelta(); 230 controlFont = controlFont.deriveFont(Math.max(minSize, size)); 231 } 232 return new FontUIResource (controlFont); 236 } 237 238 239 } | Popular Tags |