001: /*
002: * DefaultLookAndFeel.java
003: *
004: * Copyright (C) 2000-2003 Peter Graves
005: * $Id: DefaultLookAndFeel.java,v 1.7 2003/07/27 00:03:43 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.Color;
025: import java.awt.Font;
026: import java.awt.FontMetrics;
027: import java.awt.Toolkit;
028: import javax.swing.BorderFactory;
029: import javax.swing.UIDefaults;
030: import javax.swing.UIManager;
031: import javax.swing.plaf.ColorUIResource;
032: import javax.swing.plaf.FontUIResource;
033: import javax.swing.plaf.metal.DefaultMetalTheme;
034: import javax.swing.plaf.metal.MetalLookAndFeel;
035:
036: public final class DefaultLookAndFeel extends DefaultMetalTheme {
037: private static final Preferences preferences = Editor.preferences();
038:
039: private final ColorUIResource primary1 = new ColorUIResource(0, 0,
040: 0); // Black.
041:
042: private FontUIResource plainFont;
043:
044: public static void setLookAndFeel() {
045: // This is the default.
046: String lookAndFeelClassName = "javax.swing.plaf.metal.MetalLookAndFeel";
047:
048: Editor.lookAndFeel = preferences
049: .getStringProperty(Property.LOOK_AND_FEEL);
050:
051: if (Editor.lookAndFeel == null) {
052: if (Platform.isPlatformMacOSX())
053: Editor.lookAndFeel = "Aqua";
054: }
055:
056: if (Editor.lookAndFeel != null) {
057: // User has indicated a preference.
058: if (Editor.lookAndFeel.equals("Metal")) {
059: ; // Default look and feel, but don't do customizations.
060: } else if (Editor.lookAndFeel.equals("Motif")) {
061: lookAndFeelClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
062: } else if (Editor.lookAndFeel.equals("Windows")) {
063: lookAndFeelClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
064: } else if (Editor.lookAndFeel.equals("Aqua")) {
065: lookAndFeelClassName = "com.apple.mrj.swing.MacLookAndFeel";
066: // Jun 21 2002 7:16 AM
067: // Using the menu bar at the top of the screen (and having it
068: // actually work) seems to require some further unknown
069: // magic...
070: //System.setProperty("com.apple.macos.useScreenMenuBar", "true");
071: } else {
072: // Not recognized. Revert to default behavior.
073: Editor.lookAndFeel = null;
074: }
075: }
076: if (Editor.lookAndFeel == null) {
077: // Default customizations.
078: MetalLookAndFeel.setCurrentTheme(new DefaultLookAndFeel());
079: UIManager.put("Tree.collapsedIcon", Utilities
080: .getIconFromFile("collapsed.png"));
081: UIManager.put("Tree.expandedIcon", Utilities
082: .getIconFromFile("expanded.png"));
083: } else {
084: MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
085: }
086: try {
087: UIManager.setLookAndFeel(lookAndFeelClassName);
088: } catch (Exception e) {
089: }
090: // We want to do this in any case.
091: UIManager.put("ToolBarUI", "org.armedbear.j.ToolBarUI");
092: UIManager.put("ButtonUI", "org.armedbear.j.ButtonUI");
093: UIManager.put("LabelUI", "org.armedbear.j.LabelUI");
094: }
095:
096: private DefaultLookAndFeel() {
097: String name = preferences
098: .getStringProperty(Property.DIALOG_FONT_NAME);
099: int size = preferences
100: .getIntegerProperty(Property.DIALOG_FONT_SIZE);
101: Font font = new Font(name, Font.PLAIN, size);
102: plainFont = new FontUIResource(font);
103: }
104:
105: public void addCustomEntriesToTable(UIDefaults table) {
106: table.put("Button.border", BorderFactory
107: .createRaisedBevelBorder());
108: table.put("TextField.border", BorderFactory
109: .createLoweredBevelBorder());
110: table.put("SplitPaneUI",
111: "javax.swing.plaf.basic.BasicSplitPaneUI");
112: table.put("ScrollBarUI", "org.armedbear.j.ScrollBarUI");
113: table.put("TreeUI", "javax.swing.plaf.basic.BasicTreeUI");
114: table.put("SplitPane.dividerSize", new Integer(3));
115: table.put("ScrollBar.background", new Color(0xe0e0e0));
116: table.put("ScrollBar.foreground", new Color(0xc0c0c0));
117: table.put("ScrollBar.track", new Color(0xe0e0e0));
118: table.put("ScrollBar.trackHighlight", Color.black);
119: table.put("ScrollBar.thumb", new Color(0xc0c0c0));
120: table.put("ScrollBar.thumbHighlight", Color.white);
121: table.put("ScrollBar.thumbDarkShadow", Color.black);
122: table.put("ScrollBar.thumbShadow", new Color(0x808080));
123: table.put("ScrollBar.width", new Integer(16));
124: table.put("Button.textIconGap", new Integer(1));
125: table.put("ToolTipUI", "org.armedbear.j.ToolTipUI");
126: }
127:
128: protected ColorUIResource getPrimary1() {
129: return primary1;
130: }
131:
132: public FontUIResource getControlTextFont() {
133: return plainFont;
134: }
135:
136: public FontUIResource getSystemTextFont() {
137: return plainFont;
138: }
139:
140: public FontUIResource getUserTextFont() {
141: return plainFont;
142: }
143:
144: public FontUIResource getMenuTextFont() {
145: return plainFont;
146: }
147:
148: public FontUIResource getWindowTitleFont() {
149: return plainFont;
150: }
151:
152: public FontUIResource getSubTextFont() {
153: return plainFont;
154: }
155: }
|