001: package net.sourceforge.squirrel_sql.plugins.laf;
002:
003: /*
004: * Copyright (C) 2003 Colin Bell
005: * colbell@users.sourceforge.net
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 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: import java.util.Iterator;
022: import java.util.Vector;
023:
024: import javax.swing.*;
025: import javax.swing.plaf.metal.DefaultMetalTheme;
026: import javax.swing.plaf.metal.MetalLookAndFeel;
027: import javax.swing.plaf.metal.MetalTheme;
028:
029: import net.sourceforge.squirrel_sql.fw.util.DuplicateObjectException;
030: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
031: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
032: import net.sourceforge.squirrel_sql.fw.xml.XMLObjectCache;
033: import net.sourceforge.squirrel_sql.client.Version;
034:
035: /**
036: * Behaviour for the jGoodies Plastic Look and Feel. It also takes
037: * responsibility for the metal Look and Feel.
038: *
039: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
040: */
041: class MetalLookAndFeelController extends AbstractPlasticController {
042: /** Logger for this class. */
043: private static ILogger s_log = LoggerController
044: .createLogger(MetalLookAndFeelController.class);
045:
046: static final String METAL_LAF_CLASS_NAME = MetalLookAndFeel.class
047: .getName();
048:
049: private String[] _extraThemeClassNames = new String[0];
050:
051: /** Preferences for this LAF. */
052: private MetalThemePreferences _prefs;
053:
054: private MetalTheme _defaultMetalTheme;
055:
056: /**
057: * Ctor specifying the Look and Feel plugin and register.
058: *
059: * @param plugin The plugin that this controller is a part of.
060: * @param lafRegister LAF register.
061: */
062: MetalLookAndFeelController(LAFPlugin plugin, LAFRegister lafRegister) {
063:
064: super (plugin, lafRegister);
065: if (Version.isJDK14()) {
066: _extraThemeClassNames = new String[] {
067: ////////////////////////////////////////////////////////////////////
068: // These classes have no package see swingsetthemes.jar
069: "AquaTheme", "CharcoalTheme", "ContrastTheme",
070: "EmeraldTheme", "RubyTheme",
071: //
072: ///////////////////////////////////////////////////////////////////
073:
074: /////////////////////////////////////////////////////////////////////////////
075: // This theme was presented to SQuirreL by Karsten Lentzsch of jgoodies.com.
076: // It is SQuirreL's default theme if the LAF plugin is not used.
077: // Here we make the AllBluesBoldMetalTheme also available within the LAF plugin.
078: // Thanks a lot Karsten.
079: "net.sourceforge.squirrel_sql.client.gui.laf.AllBluesBoldMetalTheme"
080: //
081: ////////////////////////////////////////////////////////////////////////////
082: };
083: } else {
084: _extraThemeClassNames = new String[] {
085: "javax.swing.plaf.metal.OceanTheme", // Only available with JDK 1.5
086: ////////////////////////////////////////////////////////////////////
087: // These classes have no package see swingsetthemes.jar
088: "AquaTheme", "CharcoalTheme", "ContrastTheme",
089: "EmeraldTheme", "RubyTheme",
090: //
091: ///////////////////////////////////////////////////////////////////
092:
093: /////////////////////////////////////////////////////////////////////////////
094: // This theme was presented to SQuirreL by Karsten Lentzsch of jgoodies.com.
095: // It is SQuirreL's default theme if the LAF plugin is not used.
096: // Here we make the AllBluesBoldMetalTheme also available within the LAF plugin.
097: // Thanks a lot Karsten.
098: "net.sourceforge.squirrel_sql.client.gui.laf.AllBluesBoldMetalTheme"
099: //
100: ////////////////////////////////////////////////////////////////////////////
101:
102: };
103: }
104:
105: _defaultMetalTheme = new DefaultMetalTheme();
106:
107: XMLObjectCache cache = plugin.getSettingsCache();
108: Iterator<?> it = cache
109: .getAllForClass(MetalThemePreferences.class);
110: if (it.hasNext()) {
111: _prefs = (MetalThemePreferences) it.next();
112: } else {
113: _prefs = new MetalThemePreferences();
114: try {
115: cache.add(_prefs);
116: } catch (DuplicateObjectException ex) {
117: s_log
118: .error(
119: "MetalThemePreferences object already in XMLObjectCache",
120: ex);
121: }
122: }
123: }
124:
125: /**
126: * Retrieve extra themes for this Look and Feel.
127: *
128: * @return The default metal theme.
129: */
130: MetalTheme[] getExtraThemes() {
131: ClassLoader cl = getLAFRegister().getLookAndFeelClassLoader();
132:
133: Vector<MetalTheme> ret = new Vector<MetalTheme>();
134:
135: boolean defaultThemeIsIncluded = false;
136:
137: for (int i = 0; i < _extraThemeClassNames.length; ++i) {
138: try {
139: Class<?> clazz = Class.forName(
140: _extraThemeClassNames[i], false, cl);
141: ret.add((MetalTheme) clazz.newInstance());
142:
143: if (null != _defaultMetalTheme
144: && _extraThemeClassNames[i]
145: .equals(_defaultMetalTheme.getClass()
146: .getName())) {
147: defaultThemeIsIncluded = true;
148: }
149: } catch (Throwable th) {
150: s_log.error("Error loading theme "
151: + _extraThemeClassNames[i], th);
152: }
153: }
154:
155: if (false == defaultThemeIsIncluded) {
156: ret.add(_defaultMetalTheme);
157: }
158:
159: return ret.toArray(new MetalTheme[ret.size()]);
160: }
161:
162: void installCurrentTheme(LookAndFeel laf, MetalTheme theme) {
163: // This works only on JDK 1.5
164: // With JDK 1.4.x fonts will be bold for all SwingSet themes.
165: // See also SwingSet2 demos in JDK 1.4 and JDK 1.5
166: UIManager.put("swing.boldMetal", Boolean.FALSE);
167:
168: MetalLookAndFeel.setCurrentTheme(theme);
169: }
170:
171: /**
172: * Retrieve the name of the current theme.
173: *
174: * @return Name of the current theme.
175: */
176: String getCurrentThemeName() {
177: return _prefs.getThemeName();
178: }
179:
180: /**
181: * Set the current theme name.
182: *
183: * @param name name of the current theme.
184: */
185: void setCurrentThemeName(String name) {
186: _prefs.setThemeName(name);
187: }
188:
189: /**
190: * Preferences for the Metal LAF. Subclassed purely to give it a
191: * different data type when stored in the plugin preferences so that it
192: * doesn't get mixed up with preferences for other subclasses of
193: * AbstractPlasticController
194: */
195: public static final class MetalThemePreferences extends
196: AbstractPlasticController.ThemePreferences {
197: }
198: }
|