1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.theme;
21
22 import java.awt.Component;
23 import java.awt.Font;
24
25 import javax.swing.plaf.FontUIResource;
26 import javax.swing.*;
27
28 import org.xnap.*;
29 import org.xnap.gui.component.FontChooserDialog;
30 import org.xnap.util.Preferences;
31
32 /***
33 * This class provides a theme that makes use of a custom font. A font chooser
34 * is provided as the configuration dialog.
35 */
36 public class DefaultTheme extends AbstractTheme {
37
38
39
40
41
42 private Object[] properties;
43
44
45
46 public DefaultTheme(String name)
47 {
48 super(name);
49 }
50
51 public DefaultTheme()
52 {
53 this(XNap.tr("Default"));
54 }
55
56
57
58 public boolean isConfigurable()
59 {
60 return true;
61 }
62
63 public Font getFont()
64 {
65 return Preferences.getInstance().getFont("defaultThemeFont");
66 }
67
68 public Object[] getProperties()
69 {
70 if (properties == null) {
71 properties = createProperties(new FontUIResource(getFont()));
72 }
73 return properties;
74 }
75
76 /***
77 * Installs the theme. Sets the UIManager defaults.
78 *
79 * @see #getProperties()
80 */
81 public void install()
82 {
83 UIManager.getDefaults().putDefaults(getProperties());
84 }
85
86 public void setFont(Font newValue)
87 {
88 Preferences.getInstance().set("defaultThemeFont", newValue);
89 properties = createProperties(new FontUIResource(getFont()));
90 }
91
92 public boolean showConfigurationDialog(Component parent)
93 {
94 Font f = FontChooserDialog.showDialog(parent, getFont());
95 if (f != null) {
96 setFont(f);
97 return true;
98 }
99
100 return false;
101 }
102
103 }