001: package net.sourceforge.squirrel_sql.plugins.laf;
002:
003: /*
004: * Copyright (C) 2006 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.awt.GridBagConstraints;
022: import java.awt.GridBagLayout;
023: import java.awt.Insets;
024: import java.io.IOException;
025: import java.util.Iterator;
026:
027: import javax.swing.JCheckBox;
028: import javax.swing.LookAndFeel;
029: import javax.swing.UIManager;
030:
031: import net.sourceforge.squirrel_sql.fw.id.IHasIdentifier;
032: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
033: import net.sourceforge.squirrel_sql.fw.id.IntegerIdentifier;
034: import net.sourceforge.squirrel_sql.fw.util.DuplicateObjectException;
035: import net.sourceforge.squirrel_sql.fw.util.StringManager;
036: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
037: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
038: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
039: import net.sourceforge.squirrel_sql.fw.xml.XMLObjectCache;
040:
041: /**
042: * Behaviour for the Tonic Look and Feel.
043: *
044: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
045: */
046: public class TonicLookAndFeelController extends
047: DefaultLookAndFeelController {
048: private static final StringManager s_stringMgr = StringManagerFactory
049: .getStringManager(TonicLookAndFeelController.class);
050:
051: /** Logger for this class. */
052: private static final ILogger s_log = LoggerController
053: .createLogger(TonicLookAndFeelController.class);
054:
055: /** Class name of the Tonic Look and Feel. */
056: public static final String TONIC_LAF_CLASS_NAME = "com.digitprop.tonic.TonicLookAndFeel";
057:
058: /** Preferences for this LAF. */
059: private TonicPreferences _prefs;
060:
061: /**
062: * Ctor specifying the Look and Feel plugin.
063: *
064: * @param plugin The plugin that this controller is a part of.
065: */
066: TonicLookAndFeelController(LAFPlugin plugin) throws IOException {
067: super ();
068:
069: XMLObjectCache cache = plugin.getSettingsCache();
070: Iterator<?> it = cache.getAllForClass(TonicPreferences.class);
071: if (it.hasNext()) {
072: _prefs = (TonicPreferences) it.next();
073: } else {
074: _prefs = new TonicPreferences();
075: try {
076: cache.add(_prefs);
077: } catch (DuplicateObjectException ex) {
078: s_log
079: .error(
080: "TonicPreferences object already in XMLObjectCache",
081: ex);
082: }
083: }
084: }
085:
086: /**
087: * This Look and Feel is about to be installed.
088: */
089: public void aboutToBeInstalled(LAFRegister lafRegister,
090: LookAndFeel laf) {
091: }
092:
093: /**
094: * This Look and Feel has just been installed.
095: */
096: public void hasBeenInstalled(LAFRegister lafRegister,
097: LookAndFeel laf) {
098: UIManager.getDefaults().put("TabbedPane.thickBorders",
099: Boolean.valueOf(_prefs.getUseTabbedPaneThickBorders()));
100: }
101:
102: /**
103: * @see ILookAndFeelController#getPreferencesComponent()
104: */
105: public BaseLAFPreferencesPanelComponent getPreferencesComponent() {
106: return new TonicPrefsPanel(this );
107: }
108:
109: private static final class TonicPrefsPanel extends
110: BaseLAFPreferencesPanelComponent {
111: private static final long serialVersionUID = 1L;
112:
113: /**
114: * This interface defines locale specific strings. This should be
115: * replaced with a property file.
116: */
117: interface SkinPrefsPanelI18n {
118: // i18n[laf.skinThemPack=Theme Pack:]
119: //String THEME_PACK = s_stringMgr.getString("laf.skinThemPack");
120: // i18n[laf.skinThemePackDir=Theme Pack Directory:]
121: //String THEMEPACK_LOC = s_stringMgr.getString("laf.skinThemePackDir");
122: }
123:
124: private TonicLookAndFeelController _ctrl;
125: private JCheckBox _useThickBordersChk = new JCheckBox(
126: s_stringMgr.getString("laf.tonicUseThickBorders"));
127:
128: TonicPrefsPanel(TonicLookAndFeelController ctrl) {
129: super (new GridBagLayout());
130: _ctrl = ctrl;
131: createUserInterface();
132: }
133:
134: private void createUserInterface() {
135: final GridBagConstraints gbc = new GridBagConstraints();
136: gbc.anchor = GridBagConstraints.WEST;
137: gbc.fill = GridBagConstraints.HORIZONTAL;
138: gbc.insets = new Insets(4, 4, 4, 4);
139:
140: gbc.gridx = 0;
141: gbc.gridy = 0;
142: add(_useThickBordersChk, gbc);
143: }
144:
145: /**
146: * @see BaseLAFPreferencesPanelComponent#loadPreferencesPanel()
147: */
148: public void loadPreferencesPanel() {
149: super .loadPreferencesPanel();
150: _useThickBordersChk.setSelected(_ctrl._prefs
151: .getUseTabbedPaneThickBorders());
152: }
153:
154: /**
155: * @see BaseLAFPreferencesPanelComponent#applyChanges()
156: */
157: public boolean applyChanges() {
158: super .applyChanges();
159: _ctrl._prefs
160: .setUseTabbedPaneThickBorders(_useThickBordersChk
161: .isSelected());
162:
163: // Force the LAF to be set even if Tonic is the current one. This
164: // allows changes to take affect.
165: return true;
166: }
167: }
168:
169: public static final class TonicPreferences implements
170: IHasIdentifier {
171: private boolean _useTabbedPaneThickBorders = false;
172: private IntegerIdentifier _id = new IntegerIdentifier(1);
173:
174: public boolean getUseTabbedPaneThickBorders() {
175: return _useTabbedPaneThickBorders;
176: }
177:
178: public void setUseTabbedPaneThickBorders(boolean value) {
179: _useTabbedPaneThickBorders = value;
180: }
181:
182: /**
183: * @return The unique identifier for this object.
184: */
185: public IIdentifier getIdentifier() {
186: return _id;
187: }
188: }
189: }
|