KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > DefaultLookAndFeel


1 /*
2  * DefaultLookAndFeel.java
3  *
4  * Copyright (C) 2000-2003 Peter Graves
5  * $Id: DefaultLookAndFeel.java,v 1.7 2003/07/27 00:03:43 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.awt.Color JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.FontMetrics JavaDoc;
27 import java.awt.Toolkit JavaDoc;
28 import javax.swing.BorderFactory JavaDoc;
29 import javax.swing.UIDefaults JavaDoc;
30 import javax.swing.UIManager JavaDoc;
31 import javax.swing.plaf.ColorUIResource JavaDoc;
32 import javax.swing.plaf.FontUIResource JavaDoc;
33 import javax.swing.plaf.metal.DefaultMetalTheme JavaDoc;
34 import javax.swing.plaf.metal.MetalLookAndFeel JavaDoc;
35
36 public final class DefaultLookAndFeel extends DefaultMetalTheme JavaDoc
37 {
38     private static final Preferences preferences = Editor.preferences();
39
40     private final ColorUIResource JavaDoc primary1 = new ColorUIResource JavaDoc(0, 0, 0); // Black.
41

42     private FontUIResource JavaDoc plainFont;
43
44     public static void setLookAndFeel()
45     {
46         // This is the default.
47
String JavaDoc lookAndFeelClassName =
48             "javax.swing.plaf.metal.MetalLookAndFeel";
49
50         Editor.lookAndFeel =
51             preferences.getStringProperty(Property.LOOK_AND_FEEL);
52
53         if (Editor.lookAndFeel == null) {
54             if (Platform.isPlatformMacOSX())
55                 Editor.lookAndFeel = "Aqua";
56         }
57
58         if (Editor.lookAndFeel != null) {
59             // User has indicated a preference.
60
if (Editor.lookAndFeel.equals("Metal")) {
61                 ; // Default look and feel, but don't do customizations.
62
} else if (Editor.lookAndFeel.equals("Motif")) {
63                 lookAndFeelClassName =
64                     "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
65             } else if (Editor.lookAndFeel.equals("Windows")) {
66                 lookAndFeelClassName =
67                     "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
68             } else if (Editor.lookAndFeel.equals("Aqua")) {
69                 lookAndFeelClassName = "com.apple.mrj.swing.MacLookAndFeel";
70                 // Jun 21 2002 7:16 AM
71
// Using the menu bar at the top of the screen (and having it
72
// actually work) seems to require some further unknown
73
// magic...
74
//System.setProperty("com.apple.macos.useScreenMenuBar", "true");
75
} else {
76                 // Not recognized. Revert to default behavior.
77
Editor.lookAndFeel = null;
78             }
79         }
80         if (Editor.lookAndFeel == null) {
81             // Default customizations.
82
MetalLookAndFeel.setCurrentTheme(new DefaultLookAndFeel());
83             UIManager.put("Tree.collapsedIcon",
84                           Utilities.getIconFromFile("collapsed.png"));
85             UIManager.put("Tree.expandedIcon",
86                           Utilities.getIconFromFile("expanded.png"));
87         } else {
88             MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme JavaDoc());
89         }
90         try {
91             UIManager.setLookAndFeel(lookAndFeelClassName);
92         }
93         catch (Exception JavaDoc e) {}
94         // We want to do this in any case.
95
UIManager.put("ToolBarUI", "org.armedbear.j.ToolBarUI");
96         UIManager.put("ButtonUI", "org.armedbear.j.ButtonUI");
97         UIManager.put("LabelUI", "org.armedbear.j.LabelUI");
98     }
99
100     private DefaultLookAndFeel()
101     {
102         String JavaDoc name = preferences.getStringProperty(Property.DIALOG_FONT_NAME);
103         int size = preferences.getIntegerProperty(Property.DIALOG_FONT_SIZE);
104         Font JavaDoc font = new Font JavaDoc(name, Font.PLAIN, size);
105         plainFont = new FontUIResource JavaDoc(font);
106     }
107
108     public void addCustomEntriesToTable(UIDefaults JavaDoc table)
109     {
110         table.put("Button.border", BorderFactory.createRaisedBevelBorder());
111         table.put("TextField.border", BorderFactory.createLoweredBevelBorder());
112         table.put("SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI");
113         table.put("ScrollBarUI", "org.armedbear.j.ScrollBarUI");
114         table.put("TreeUI", "javax.swing.plaf.basic.BasicTreeUI");
115         table.put("SplitPane.dividerSize", new Integer JavaDoc(3));
116         table.put("ScrollBar.background", new Color JavaDoc(0xe0e0e0));
117         table.put("ScrollBar.foreground", new Color JavaDoc(0xc0c0c0));
118         table.put("ScrollBar.track", new Color JavaDoc(0xe0e0e0));
119         table.put("ScrollBar.trackHighlight", Color.black);
120         table.put("ScrollBar.thumb", new Color JavaDoc(0xc0c0c0));
121         table.put("ScrollBar.thumbHighlight", Color.white);
122         table.put("ScrollBar.thumbDarkShadow", Color.black);
123         table.put("ScrollBar.thumbShadow", new Color JavaDoc(0x808080));
124         table.put("ScrollBar.width", new Integer JavaDoc(16));
125         table.put("Button.textIconGap", new Integer JavaDoc(1));
126         table.put("ToolTipUI", "org.armedbear.j.ToolTipUI");
127     }
128
129     protected ColorUIResource JavaDoc getPrimary1()
130     {
131         return primary1;
132     }
133
134     public FontUIResource JavaDoc getControlTextFont()
135     {
136         return plainFont;
137     }
138
139     public FontUIResource JavaDoc getSystemTextFont()
140     {
141         return plainFont;
142     }
143
144     public FontUIResource JavaDoc getUserTextFont()
145     {
146         return plainFont;
147     }
148
149     public FontUIResource JavaDoc getMenuTextFont()
150     {
151         return plainFont;
152     }
153
154     public FontUIResource JavaDoc getWindowTitleFont()
155     {
156         return plainFont;
157     }
158
159     public FontUIResource JavaDoc getSubTextFont()
160     {
161         return plainFont;
162     }
163 }
164
Popular Tags