KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > client > util > FontManager


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.client.util;
21
22 import java.awt.*;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.FileNotFoundException JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 import javax.swing.UIManager JavaDoc;
28 import javax.swing.plaf.FontUIResource JavaDoc;
29
30 public class FontManager
31 {
32     public static void setDefaultFont(Font font){
33         Font bold12 = font.deriveFont(Font.BOLD, 12);
34         Font plain12 = font.deriveFont(Font.PLAIN, 12);
35         Font plain10 = font.deriveFont(Font.PLAIN, 10);
36         
37         //bold 12
38
String JavaDoc[] properties = new String JavaDoc[]{"Button.font", "CheckBox.font",
39                 "CheckBoxMenuItem.font", "ComboBox.font",
40                 "DesktopIcon.font", "InternalFrame.font",
41                 "Label.font", "Menu.font ",
42                 "MenuBar.font", "MenuItem.font",
43                 "ProgressBar.font", "RadioButton.font",
44                 "RadioButtonMenuItem.font", "TabbedPane.font",
45                 "TitledBorder.font", "ToggleButton.font", "ToolBar.font"};
46         for(int i=0;i<properties.length;i++)
47             UIManager.put(properties[i], new FontUIResource JavaDoc(bold12));
48         
49         //plain 12
50
properties = new String JavaDoc[]{"ColorChooser.font", "EditorPane.font",
51                 "List.font", "OptionPane.font",
52                 "Panel.font", "PasswordField.font",
53                 "PopupMenu.font", "ScrollPane.font",
54                 "Table.font", "TableHeader.font",
55                 "TextArea.font", "TextField.font",
56                 "TextPane.font", "ToolTip.font",
57                 "Tree.font", "Viewport.font"};
58         for(int i=0;i<properties.length;i++)
59             UIManager.put(properties[i], new FontUIResource JavaDoc(plain12));
60         
61         //plain 10
62
properties = new String JavaDoc[]{"Menu.acceleratorFont",
63                 "MenuItem.acceleratorFont", "RadioButtonMenuItem.acceleratorFont"};
64         for(int i=0;i<properties.length;i++)
65             UIManager.put(properties[i], new FontUIResource JavaDoc(plain10));
66     }
67     
68     public static void setDefaultFont(String JavaDoc fileName)
69     throws FileNotFoundException JavaDoc, FontFormatException, IOException JavaDoc
70     {
71         Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream JavaDoc(fileName));
72         setDefaultFont(font);
73     }
74 }
Popular Tags