Revision: 5883
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5883&view=rev
Author: manningr
Date: 2010-09-14 02:33:07 +0000 (Tue, 14 Sep 2010)
Log Message:
-----------
New LAF controller for the substance laf.
Modified Paths:
--------------
trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/LAFRegister.java
Added Paths:
-----------
trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLafData.java
trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeel.java
trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeelController.java
Modified: trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/LAFRegister.java
===================================================================
--- trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/LAFRegister.java 2010-09-13 22:49:59 UTC (rev 5882)
+++ trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/LAFRegister.java 2010-09-14 02:33:07 UTC (rev 5883)
@@ -1,4 +1,5 @@
package net.sourceforge.squirrel_sql.plugins.laf;
+
/*
* Copyright (C) 2001-2006 Colin Bell
* co...@us...
@@ -46,108 +47,84 @@
import net.sourceforge.squirrel_sql.fw.util.MyURLClassLoader;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+
/**
* Register of Look and Feels.
- *
- * @author <A HREF="mailto:co...@us...">Colin Bell</A>
+ *
+ * @author <A HREF="mailto:co...@us...">Colin Bell</A>
*/
class LAFRegister
{
private final static int FONT_KEYS_ARRAY_OTHER = 0;
+
private final static int FONT_KEYS_ARRAY_MENU = 1;
+
private final static int FONT_KEYS_ARRAY_STATIC = 2;
+
/** Logger for this class. */
private static ILogger s_log = LoggerController.createLogger(LAFRegister.class);
+
// TODO: What about these
// Viewport.font, ColorChooser.font, InternalFrame.font,
// OptionPane.font, "Panel.font",
// ScrollPane.font, DesktopIcon.font
- private final static String[][] FONT_KEYS = {
- // Editable Text
+ private final static String[][] FONT_KEYS =
{
- "EditorPane.font",
- "List.font",
- "TextArea.font",
- "TextField.font",
- "PasswordField.font",
- "Table.font",
- "TableHeader.font",
- "TextPane.font",
- "Tree.font",
- },
- // Menus
- {
- "CheckBoxMenuItem.acceleratorFont",
- "CheckBoxMenuItem.font",
- "Menu.acceleratorFont",
- "Menu.font",
- "MenuBar.font",
- "MenuItem.acceleratorFont",
- "MenuItem.font",
- "PopupMenu.font",
- "RadioButtonMenuItem.acceleratorFont",
- "RadioButtonMenuItem.font",
- },
- // Static text
- {
- "Button.font",
- "CheckBox.font",
- "ComboBox.font",
- "InternalFrame.titleFont",
- "Label.font",
- "ProgressBar.font",
- "RadioButton.font",
- "TabbedPane.font",
- "TitledBorder.font",
- "ToggleButton.font",
- "ToolBar.font",
- "ToolTip.font",
- },
- };
+ // Editable Text
+ { "EditorPane.font", "List.font", "TextArea.font", "TextField.font", "PasswordField.font",
+ "Table.font", "TableHeader.font", "TextPane.font", "Tree.font", },
+ // Menus
+ { "CheckBoxMenuItem.acceleratorFont", "CheckBoxMenuItem.font", "Menu.acceleratorFont",
+ "Menu.font", "MenuBar.font", "MenuItem.acceleratorFont", "MenuItem.font", "PopupMenu.font",
+ "RadioButtonMenuItem.acceleratorFont", "RadioButtonMenuItem.font", },
+ // Static text
+ { "Button.font", "CheckBox.font", "ComboBox.font", "InternalFrame.titleFont", "Label.font",
+ "ProgressBar.font", "RadioButton.font", "TabbedPane.font", "TitledBorder.font",
+ "ToggleButton.font", "ToolBar.font", "ToolTip.font", }, };
+
/** Application API. */
private IApplication _app;
+
/** Look and Feel plugin. */
private LAFPlugin _plugin;
+
/** Classloader for Look and Feel classes. */
private MyURLClassLoader _lafClassLoader;
+
/**
- * Collection of <TT>ILookAndFeelController</TT> objects keyed by
- * the Look and Feel class name.
+ * Collection of <TT>ILookAndFeelController</TT> objects keyed by the Look and Feel class name.
*/
- private Map<String, ILookAndFeelController> _lafControllers =
- new HashMap<String, ILookAndFeelController>();
+ private Map<String, ILookAndFeelController> _lafControllers =
+ new HashMap<String, ILookAndFeelController>();
+
/**
- * Default LAF controller. Used if a specialised one isn't available for
- * the LAF in _lafControllers.
- */
+ * Default LAF controller. Used if a specialised one isn't available for the LAF in _lafControllers.
+ */
private ILookAndFeelController _dftLAFController = new DefaultLookAndFeelController();
+
/** <UI defaults prior to us modifying them. */
private UIDefaults _origUIDefaults;
+
/**
- * Ctor. Load all Look and Feels from the Look and Feel folder. Set the
- * current Look and Feel to that specified in the application preferences.
- *
- * @param app Application API.
- * @param plugin The LAF plugin.
- *
- * @throws IllegalArgumentException
- * If <TT>IApplication</TT>, or <TT>LAFPlugin</TT> are <TT>null</TT>.
+ * Ctor. Load all Look and Feels from the Look and Feel folder. Set the current Look and Feel to that
+ * specified in the application preferences.
+ *
+ * @param app
+ * Application API.
+ * @param plugin
+ * The LAF plugin.
+ * @throws IllegalArgumentException
+ * If <TT>IApplication</TT>, or <TT>LAFPlugin</TT> are <TT>null</TT>.
*/
LAFRegister(IApplication app, LAFPlugin plugin) throws IllegalArgumentException
{
super();
- if (app == null)
- {
- throw new IllegalArgumentException("Null IApplication passed");
- }
- if (plugin == null)
- {
- throw new IllegalArgumentException("Null LAFPlugin passed");
- }
+ if (app == null) { throw new IllegalArgumentException("Null IApplication passed"); }
+ if (plugin == null) { throw new IllegalArgumentException("Null LAFPlugin passed"); }
_app = app;
_plugin = plugin;
// Save the current UI defaults.
- _origUIDefaults = (UIDefaults)UIManager.getDefaults().clone();
+ _origUIDefaults = (UIDefaults) UIManager.getDefaults().clone();
installLookAndFeels();
installLookAndFeelControllers(plugin);
try
@@ -168,35 +145,34 @@
s_log.error("Error updating application fonts", ex);
}
}
+
LAFPlugin getPlugin()
{
return _plugin;
}
+
/**
* Return the class loader used to load the Look and Feels.
*
- * @return the ClassLoader used to load the look and feels.
+ * @return the ClassLoader used to load the look and feels.
*/
ClassLoader getLookAndFeelClassLoader()
{
return _lafClassLoader;
}
+
/**
* Get a Look and Feel Controller for the passed L&F class name.
*
- * @param lafClassName Look and Feel class name to get controller for.
- *
- * @return L&F Controller.
- *
- * @throws IllegalArgumentException Thrown if <TT>null</TT>
- * <TT>lafClassName</TT> passed.
+ * @param lafClassName
+ * Look and Feel class name to get controller for.
+ * @return L&F Controller.
+ * @throws IllegalArgumentException
+ * Thrown if <TT>null</TT> <TT>lafClassName</TT> passed.
*/
ILookAndFeelController getLookAndFeelController(String lafClassName)
{
- if (lafClassName == null)
- {
- throw new IllegalArgumentException("lafClassName == null");
- }
+ if (lafClassName == null) { throw new IllegalArgumentException("lafClassName == null"); }
ILookAndFeelController ctrl = _lafControllers.get(lafClassName);
if (ctrl == null)
{
@@ -204,6 +180,7 @@
}
return ctrl;
}
+
/**
* Set the font that the application uses for statusbars.
*/
@@ -211,16 +188,15 @@
{
if (_plugin.getLAFPreferences().isStatusBarFontEnabled())
{
- _app.getFontInfoStore().setStatusBarFontInfo(
- _plugin.getLAFPreferences().getStatusBarFontInfo());
+ _app.getFontInfoStore().setStatusBarFontInfo(_plugin.getLAFPreferences().getStatusBarFontInfo());
}
}
+
/**
* Set the current Look and Feel to that specified in the app preferences.
*/
- void setLookAndFeel(boolean force)
- throws ClassNotFoundException, IllegalAccessException,
- InstantiationException, UnsupportedLookAndFeelException
+ void setLookAndFeel(boolean force) throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, UnsupportedLookAndFeelException
{
final LAFPreferences prefs = _plugin.getLAFPreferences();
final String lafClassName = prefs.getLookAndFeelClassName();
@@ -235,7 +211,7 @@
lafClass = Class.forName(lafClassName);
}
// Get the new Look and Feel object.
- final LookAndFeel laf = (LookAndFeel)lafClass.newInstance();
+ final LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
// If a different LAF to the current one has been requested then
// change to the requested LAF.
LookAndFeel curLaf = UIManager.getLookAndFeel();
@@ -244,7 +220,7 @@
{
ILookAndFeelController lafCont = getLookAndFeelController(lafClassName);
lafCont.aboutToBeInstalled(this, laf);
-
+
// Set Look and Feel.
if (_lafClassLoader != null)
{
@@ -255,17 +231,19 @@
{
UIManager.setLookAndFeel(laf);
}
-
+
lafCont.hasBeenInstalled(this, laf);
updateAllFrames();
}
}
+
void applyPreferences()
{
final LAFPreferences prefs = _plugin.getLAFPreferences();
JFrame.setDefaultLookAndFeelDecorated(prefs.getCanLAFSetBorder());
JDialog.setDefaultLookAndFeelDecorated(prefs.getCanLAFSetBorder());
}
+
/**
* Update the applications fonts.
*/
@@ -321,6 +299,7 @@
}
}
}
+
/**
* Update all open frames for the new Look and Feel info.
*/
@@ -336,6 +315,7 @@
}
}
}
+
/**
* Install Look and Feels from their jars.
*/
@@ -357,11 +337,11 @@
_lafClassLoader = new MyURLClassLoader(lafUrls.toArray(urls));
for (Iterator<String> it = lafs.keySet().iterator(); it.hasNext();)
{
- String className = it.next();
+ String className = it.next();
Class<?> lafClass = Class.forName(className, false, _lafClassLoader);
try
{
- LookAndFeel laf = (LookAndFeel)lafClass.newInstance();
+ LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
if (laf.isSupportedLookAndFeel())
{
LookAndFeelInfo info = new LookAndFeelInfo(laf.getName(), lafClass.getName());
@@ -379,16 +359,19 @@
s_log.error("Error occured trying to load Look and Feel classes", th);
}
}
+
/**
* Install the controllers for those LAFs that require them.
*
- * @param plugin The LAF plugin.
+ * @param plugin
+ * The LAF plugin.
*/
private void installLookAndFeelControllers(LAFPlugin plugin)
{
try
{
- _lafControllers.put(SkinLookAndFeelController.SKINNABLE_LAF_CLASS_NAME, new SkinLookAndFeelController(plugin));
+ _lafControllers.put(SkinLookAndFeelController.SKINNABLE_LAF_CLASS_NAME,
+ new SkinLookAndFeelController(plugin));
}
catch (Throwable ex)
{
@@ -418,25 +401,35 @@
}
try
{
- _lafControllers.put(TonicLookAndFeelController.TONIC_LAF_CLASS_NAME, new TonicLookAndFeelController(plugin));
+ _lafControllers.put(TonicLookAndFeelController.TONIC_LAF_CLASS_NAME, new TonicLookAndFeelController(
+ plugin));
}
catch (Throwable ex)
{
s_log.error("Error installing SkinLookAndFeelController", ex);
}
+ try
+ {
+ _lafControllers.put(SubstanceLookAndFeelController.SUBSTANCE_CLASS_NAME,
+ new SubstanceLookAndFeelController(plugin));
+ }
+ catch (Throwable ex)
+ {
+ s_log.error("Error installing SubstanceLookAndFeelController", ex);
+ }
+
// Initialize all the LAF controllers.
- for (Iterator<ILookAndFeelController> it =
- _lafControllers.values().iterator(); it.hasNext();)
+ for (Iterator<ILookAndFeelController> it = _lafControllers.values().iterator(); it.hasNext();)
{
it.next().initialize();
}
}
+
/**
- * Load the installation properties and return a <TT>Map</TT>
- * keyed by the class name of the LAF and containing a URL to the jar file
- * that contains the LAF.
+ * Load the installation properties and return a <TT>Map</TT> keyed by the class name of the LAF and
+ * containing a URL to the jar file that contains the LAF.
*
- * @return Map
+ * @return Map
*/
private Map<String, URL> loadInstallProperties()
{
@@ -453,13 +446,13 @@
if (className == null || className.length() == 0)
{
break;
- }
+ }
String jarName = rsrc.getString(LAFPluginResources.IKeys.JAR + i);
if (jarName == null || jarName.length() == 0)
{
break;
}
-
+
File file = new File(stdLafJarDir, jarName);
try
{
@@ -470,8 +463,7 @@
}
catch (IOException ex)
{
- s_log.error("Error occured reading Look and Feel jar: " +
- file.getAbsolutePath(), ex);
+ s_log.error("Error occured reading Look and Feel jar: " + file.getAbsolutePath(), ex);
}
}
catch (MissingResourceException ignore)
@@ -484,8 +476,7 @@
try
{
final File extraLafsDir = _plugin.getUsersExtraLAFFolder();
- File extraFile = new File(extraLafsDir,
- ILAFConstants.USER_EXTRA_LAFS_PROPS_FILE);
+ File extraFile = new File(extraLafsDir, ILAFConstants.USER_EXTRA_LAFS_PROPS_FILE);
BufferedInputStream is = new BufferedInputStream(new FileInputStream(extraFile));
try
{
@@ -497,7 +488,7 @@
if (className == null || className.length() == 0)
{
break;
- }
+ }
String jarName = props.getProperty(LAFPluginResources.IKeys.JAR + i);
if (jarName == null || jarName.length() == 0)
{
@@ -513,8 +504,7 @@
}
catch (IOException ex)
{
- s_log.error("Error occured reading Look and Feel jar: " +
- file.getAbsolutePath(), ex);
+ s_log.error("Error occured reading Look and Feel jar: " + file.getAbsolutePath(), ex);
}
}
}
Added: trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLafData.java
===================================================================
--- trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLafData.java (rev 0)
+++ trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLafData.java 2010-09-14 02:33:07 UTC (rev 5883)
@@ -0,0 +1,112 @@
+package net.sourceforge.squirrel_sql.plugins.laf;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.util.HashMap;
+import java.util.Set;
+import java.util.TreeSet;
+
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+
+import org.jvnet.substance.api.SubstanceSkin;
+import org.jvnet.substance.skin.AutumnSkin;
+import org.jvnet.substance.skin.BusinessBlackSteelSkin;
+import org.jvnet.substance.skin.BusinessBlueSteelSkin;
+import org.jvnet.substance.skin.BusinessSkin;
+import org.jvnet.substance.skin.ChallengerDeepSkin;
+import org.jvnet.substance.skin.CremeCoffeeSkin;
+import org.jvnet.substance.skin.CremeSkin;
+import org.jvnet.substance.skin.DustCoffeeSkin;
+import org.jvnet.substance.skin.DustSkin;
+import org.jvnet.substance.skin.EmeraldDuskSkin;
+import org.jvnet.substance.skin.MagmaSkin;
+import org.jvnet.substance.skin.MistAquaSkin;
+import org.jvnet.substance.skin.MistSilverSkin;
+import org.jvnet.substance.skin.ModerateSkin;
+import org.jvnet.substance.skin.NebulaBrickWallSkin;
+import org.jvnet.substance.skin.NebulaSkin;
+import org.jvnet.substance.skin.OfficeBlue2007Skin;
+import org.jvnet.substance.skin.OfficeSilver2007Skin;
+import org.jvnet.substance.skin.RavenGraphiteGlassSkin;
+import org.jvnet.substance.skin.RavenGraphiteSkin;
+import org.jvnet.substance.skin.RavenSkin;
+import org.jvnet.substance.skin.SaharaSkin;
+import org.jvnet.substance.skin.TwilightSkin;
+
+public class SubstanceLafData
+{
+
+ /** Logger for this class. */
+ private static ILogger s_log = LoggerController.createLogger(SubstanceLafData.class);
+
+ private HashMap<String, SubstanceSkin> lafMap = new HashMap<String, SubstanceSkin>();
+
+ public SubstanceLafData()
+ {
+ initLafMap();
+ }
+
+ private void initLafMap()
+ {
+ lafMap.put(AutumnSkin.NAME, new AutumnSkin());
+ lafMap.put(BusinessBlackSteelSkin.NAME, new BusinessBlackSteelSkin());
+ lafMap.put(BusinessBlueSteelSkin.NAME, new BusinessBlueSteelSkin());
+ lafMap.put(BusinessSkin.NAME, new BusinessSkin());
+ lafMap.put(ChallengerDeepSkin.NAME, new ChallengerDeepSkin());
+ lafMap.put(CremeCoffeeSkin.NAME, new CremeCoffeeSkin());
+ lafMap.put(CremeSkin.NAME, new CremeSkin());
+ lafMap.put(DustCoffeeSkin.NAME, new DustCoffeeSkin());
+ lafMap.put(DustSkin.NAME, new DustSkin());
+ lafMap.put(EmeraldDuskSkin.NAME, new EmeraldDuskSkin());
+ lafMap.put(MagmaSkin.NAME, new MagmaSkin());
+ lafMap.put(MistAquaSkin.NAME, new MistAquaSkin());
+ lafMap.put(MistSilverSkin.NAME, new MistSilverSkin());
+ lafMap.put(ModerateSkin.NAME, new ModerateSkin());
+ lafMap.put(NebulaBrickWallSkin.NAME, new NebulaBrickWallSkin());
+ lafMap.put(NebulaSkin.NAME, new NebulaSkin());
+ lafMap.put(OfficeBlue2007Skin.NAME, new OfficeBlue2007Skin());
+ lafMap.put(OfficeSilver2007Skin.NAME, new OfficeSilver2007Skin());
+ lafMap.put(RavenGraphiteGlassSkin.NAME, new RavenGraphiteGlassSkin());
+ lafMap.put(RavenGraphiteSkin.NAME, new RavenGraphiteSkin());
+ lafMap.put(RavenSkin.NAME, new RavenSkin());
+ lafMap.put(SaharaSkin.NAME, new SaharaSkin());
+ lafMap.put(TwilightSkin.NAME, new TwilightSkin());
+ }
+
+ public SubstanceSkin getSkinForName(String skinName)
+ {
+ SubstanceSkin skin = (SubstanceSkin) lafMap.get(skinName);
+ if (skin == null) {
+ if (s_log.isInfoEnabled()) {
+ s_log.info("Unable to locate Skin class for skinName ("+skinName+"). Using Autumn instead.");
+ }
+ skin = new AutumnSkin();
+ }
+ return skin;
+ }
+
+ public Set<String> getSubstanceSkins()
+ {
+ Set<String> result = new TreeSet<String>(lafMap.keySet());
+ return result;
+ }
+
+}
Added: trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeel.java
===================================================================
--- trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeel.java (rev 0)
+++ trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeel.java 2010-09-14 02:33:07 UTC (rev 5883)
@@ -0,0 +1,47 @@
+package net.sourceforge.squirrel_sql.plugins.laf;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import org.jvnet.substance.skin.AutumnSkin;
+
+/**
+ * This is simply a placeholder class that allows SQuirreL to populate the LAF chooser with the name
+ * "Substance". This is done because the Substance LAF doesn't have one skinnable LAF class, but rather
+ * defines a LAF class per "skin". There are many of these and they would clutter up the LAF chooser. So,
+ * rather than display a particular Substance LAF class to the user, this LAF sub-class has a generic name of
+ * "Substance". Even though technically, this is the "Autumn" skin, it is fine, because "Autumn" will be the
+ * first skin displayed in the skin chooser, when the Substance LAF is chosen. And change to the skin chooser
+ * will result in this LAF's setSkin method being called.
+ */
+public class SubstanceLookAndFeel extends org.jvnet.substance.SubstanceLookAndFeel
+{
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ protected SubstanceLookAndFeel()
+ {
+ super(new AutumnSkin());
+ super.name = "Substance";
+ }
+
+}
Added: trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeelController.java
===================================================================
--- trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeelController.java (rev 0)
+++ trunk/sql12/plugins/laf/src/main/java/net/sourceforge/squirrel_sql/plugins/laf/SubstanceLookAndFeelController.java 2010-09-14 02:33:07 UTC (rev 5883)
@@ -0,0 +1,224 @@
+package net.sourceforge.squirrel_sql.plugins.laf;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.swing.ComboBoxModel;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.LookAndFeel;
+import javax.swing.SwingConstants;
+
+import net.sourceforge.squirrel_sql.fw.id.IHasIdentifier;
+import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
+import net.sourceforge.squirrel_sql.fw.id.IntegerIdentifier;
+import net.sourceforge.squirrel_sql.fw.util.DuplicateObjectException;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.fw.xml.XMLObjectCache;
+
+import org.jvnet.substance.SubstanceLookAndFeel;
+import org.jvnet.substance.api.SubstanceSkin;
+
+/**
+ * Behaviour for the Skin Look and Feel.
+ *
+ * @author <A HREF="mailto:co...@us...">Colin Bell</A>
+ */
+public class SubstanceLookAndFeelController extends DefaultLookAndFeelController
+{
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(SubstanceLookAndFeelController.class);
+
+ /** Logger for this class. */
+ private static final ILogger s_log = LoggerController.createLogger(SubstanceLookAndFeelController.class);
+
+ /** Class name of the Skin class. */
+ public static final String SUBSTANCE_CLASS_NAME =
+ "net.sourceforge.squirrel_sql.plugins.laf.SubstanceLookAndFeel";
+
+ /** Preferences for this LAF. */
+ private SubstancePreferences _prefs;
+
+ private SubstanceLafData _lafData = new SubstanceLafData();
+
+ /**
+ * Ctor specifying the Look and Feel plugin.
+ *
+ * @param plugin
+ * The plugin that this controller is a part of.
+ */
+ SubstanceLookAndFeelController(LAFPlugin plugin) throws IOException
+ {
+ super();
+
+ XMLObjectCache cache = plugin.getSettingsCache();
+ Iterator<?> it = cache.getAllForClass(SubstancePreferences.class);
+ if (it.hasNext())
+ {
+ _prefs = (SubstancePreferences) it.next();
+ }
+ else
+ {
+ _prefs = new SubstancePreferences();
+ try
+ {
+ cache.add(_prefs);
+ }
+ catch (DuplicateObjectException ex)
+ {
+ s_log.error("SubstancePreferences object already in XMLObjectCache", ex);
+ }
+ }
+
+ }
+
+ /**
+ * This Look and Feel is about to be installed. Load the selected themepack.
+ */
+ public void aboutToBeInstalled(LAFRegister lafRegister, LookAndFeel laf)
+ {
+ final String skinName = _prefs.getSkinName();
+ SubstanceSkin skin = _lafData.getSkinForName(skinName);
+ SubstanceLookAndFeel.setSkin(skin);
+ }
+
+ /**
+ * This Look and Feel has just been installed.
+ */
+ public void hasBeenInstalled(LAFRegister lafRegister, LookAndFeel laf)
+ {
+ final String skinName = _prefs.getSkinName();
+ SubstanceSkin skin = _lafData.getSkinForName(skinName);
+ SubstanceLookAndFeel.setSkin(skin);
+ }
+
+ /**
+ * @see ILookAndFeelController#getPreferencesComponent()
+ */
+ public BaseLAFPreferencesPanelComponent getPreferencesComponent()
+ {
+ return new SubstanceSkinPrefsPanel(this);
+ }
+
+ private static final class SubstanceSkinPrefsPanel extends BaseLAFPreferencesPanelComponent
+ {
+ private static final long serialVersionUID = 1L;
+
+ interface SkinPrefsPanelI18n
+ {
+ // i18n[SubstanceLookAndFeelController.substanceSkinLabel=Substance Skin:]
+ String THEME_PACK = s_stringMgr.getString("SubstanceLookAndFeelController.substanceSkinLabel");
+ }
+
+ private SubstanceLookAndFeelController _ctrl;
+
+ private JComboBox _skinCmb = new JComboBox();
+
+ SubstanceSkinPrefsPanel(SubstanceLookAndFeelController ctrl)
+ {
+ super(new GridBagLayout());
+ _ctrl = ctrl;
+ createUserInterface();
+ }
+
+ private void createUserInterface()
+ {
+ final GridBagConstraints gbc = new GridBagConstraints();
+ gbc.anchor = GridBagConstraints.WEST;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.insets = new Insets(4, 4, 4, 4);
+
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ add(new JLabel(SkinPrefsPanelI18n.THEME_PACK, SwingConstants.RIGHT), gbc);
+
+ ++gbc.gridx;
+ add(_skinCmb, gbc);
+ }
+
+ /**
+ * @see BaseLAFPreferencesPanelComponent#loadPreferencesPanel()
+ */
+ public void loadPreferencesPanel()
+ {
+ super.loadPreferencesPanel();
+ Set<String> substanceThemes = _ctrl._lafData.getSubstanceSkins();
+ Object[] comboItems = new Object[substanceThemes.size()];
+ int count = 0;
+ for (String theme : substanceThemes)
+ {
+ comboItems[count++] = theme;
+ }
+ ComboBoxModel model = new DefaultComboBoxModel(comboItems);
+ _skinCmb.setModel(model);
+ _skinCmb.setSelectedItem(_ctrl._prefs.getSkinName());
+ if (_skinCmb.getSelectedIndex() == -1 && _skinCmb.getModel().getSize() > 0)
+ {
+ _skinCmb.setSelectedIndex(0);
+ }
+ }
+
+ /**
+ * @see BaseLAFPreferencesPanelComponent#applyChanges()
+ */
+ public boolean applyChanges()
+ {
+ super.applyChanges();
+ _ctrl._prefs.setSkinName((String) _skinCmb.getSelectedItem());
+ return true;
+ }
+ }
+
+ public static final class SubstancePreferences implements IHasIdentifier
+ {
+
+ private String _skinName;
+
+ private IntegerIdentifier _id = new IntegerIdentifier(1);
+
+ public String getSkinName()
+ {
+ return _skinName;
+ }
+
+ public void setSkinName(String value)
+ {
+ _skinName = value;
+ }
+
+ /**
+ * @return The unique identifier for this object.
+ */
+ public IIdentifier getIdentifier()
+ {
+ return _id;
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|