Find attached a patch which uses a series of strategies to initialise the Swing L&F. Currently it looks for a system Property "chainsaw.laf" with a classname, and uses that if set, otherwise defaults to the System Look and Feel. More strategy definitions are easy to plug-in.
I've tested this against the Metouia L&F @ http://mlf.sourceforge.net/ cheers, Paul Smith <<patch-chainsaw-laf-strategies.txt>>
*** Start.java 18 Mar 2003 13:33:32 -0000 1.5 --- Start.java 19 Mar 2003 00:01:16 -0000 *************** *** 49,70 **** package org.apache.log4j.chainsaw; - import org.apache.log4j.Level; - import org.apache.log4j.LogManager; - import org.apache.log4j.xml.DOMConfigurator; - import java.io.File; - import java.net.MalformedURLException; import java.net.URL; - import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; /** * Main initialization point of Chainsaw --- 49,69 ---- package org.apache.log4j.chainsaw; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import javax.swing.JFileChooser; + import javax.swing.UIManager; import javax.swing.filechooser.FileFilter; + import org.apache.log4j.Level; + import org.apache.log4j.LogManager; + import org.apache.log4j.xml.DOMConfigurator; + /** * Main initialization point of Chainsaw *************** *** 73,83 **** --- 72,174 ---- */ public class Start { private static final String LOG4J_CONFIG_FILE = "log4j.xml"; + private static final String CHAINSAW_LAF_PROPERTY = "chainsaw.laf"; public static void main(String[] args) { + initLookAndFeel(); initLog4J(); } + /** + * Initialises the Look and Feel, by using a Strategy Pattern + */ + private static void initLookAndFeel() { + new LookAndFeelStrategyChain().initLookAndFeel(); + } + + private static interface LookAndFeelStrategy { + public boolean initLookAndFeel(); + } + + /** + * A strategy chain that attempt to init the Swing L&F system by + * using a number of different methods in succession until it one + * reports that it worked ok + * @author Paul Smith + * @version 1.0 + */ + private static class LookAndFeelStrategyChain implements LookAndFeelStrategy { + + private LookAndFeelStrategyChain() { + /** @todo add any other method for initializing L&F */ + strategies.add(new SystemPropertyLookAndFeelStrategy()); + strategies.add(new DefaultLookAndFeelStrategy()); + } + + public boolean initLookAndFeel() + { + for (Iterator i = strategies.iterator(); i.hasNext(); ) { + LookAndFeelStrategy item = (LookAndFeelStrategy)i.next(); + if(item.initLookAndFeel()) { + return true; + } + } + return false; + } + + private Collection strategies = new ArrayList(); + } + + /** + * The default strategy just tries to get the System L&F and set that + * @author Paul Smith + */ + private static class DefaultLookAndFeelStrategy + implements LookAndFeelStrategy { + + public boolean initLookAndFeel() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + return true; + } + catch (Exception ex) { + + } + return false; // oh well! + } + } + + /** + * Looks for a System property "chainsaw.laf" and if set, + * attempts to set the L&F by using that property value as a class name, + * if any error occurs (e.g. can't find the class), then this strategy + * will return false to indicate failure + * @author Paul Smith + * @version 1.0 + */ + private static class SystemPropertyLookAndFeelStrategy + implements LookAndFeelStrategy { + + public boolean initLookAndFeel() { + String lookAndFeelProperty = System.getProperty(CHAINSAW_LAF_PROPERTY); + try { + if(lookAndFeelProperty != null + && lookAndFeelProperty.trim().length() > 0) { + UIManager.setLookAndFeel(lookAndFeelProperty); + return true; + } + } + catch (Exception ex) { + ex.printStackTrace(); + return false; + } + return false; + } + } + + /** + * Initialises the Log4j sub-system + */ private static void initLog4J() { /** initialise log4j **/ final FinderStrategies strategies = new FinderStrategies();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]