prepare custom look & feel loading for maybe later
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 21 May 2008 17:05:53 +0000 (17:05 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 21 May 2008 17:05:53 +0000 (17:05 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@921 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/main/Main.java

index 1ee88a0..151c6b1 100644 (file)
@@ -20,6 +20,8 @@
 package net.pterodactylus.jsite.main;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.swing.UIManager;
 import javax.swing.UIManager.LookAndFeelInfo;
@@ -55,9 +57,6 @@ public class Main {
        private void start() {
                Logging.setup("jSite");
 
-               /* include a couple known Look & Feels. */
-               maybeAddLookAndFeel("Substance", "org.jvnet.substance.SubstanceLookAndFeel");
-
                CoreImpl core = new CoreImpl();
 
                String configDirectory = System.getProperty("user.home") + File.separator + ".jSite";
@@ -92,17 +91,30 @@ public class Main {
         * @param className
         *            The name of the look & feel’s main class
         */
-       private void maybeAddLookAndFeel(String name, String className) {
-               try {
-                       Class.forName(className);
-                       LookAndFeelInfo[] installedLookAndFeelds = UIManager.getInstalledLookAndFeels();
-                       LookAndFeelInfo[] newLookAndFeels = new LookAndFeelInfo[installedLookAndFeelds.length + 1];
-                       System.arraycopy(installedLookAndFeelds, 0, newLookAndFeels, 0, installedLookAndFeelds.length);
-                       newLookAndFeels[installedLookAndFeelds.length] = new UIManager.LookAndFeelInfo(name, className);
-                       UIManager.setInstalledLookAndFeels(newLookAndFeels);
-               } catch (ClassNotFoundException e) {
-                       /* okay, it doesn't exist, ignore. */
+       @SuppressWarnings("unused")
+       private void addLookAndFeel(String name, String className) {
+               addLookAndFeels(new LookAndFeelInfo(name, className));
+       }
+
+       /**
+        * Tries to load each look & feel and adds it to the list of installed look &
+        * feels.
+        * 
+        * @see UIManager#setInstalledLookAndFeels(LookAndFeelInfo[])
+        * @param lookAndFeelInfos
+        *            The look & feels to add
+        */
+       private void addLookAndFeels(LookAndFeelInfo... lookAndFeelInfos) {
+               List<LookAndFeelInfo> allLookAndFeelInfos = Arrays.asList(UIManager.getInstalledLookAndFeels());
+               for (LookAndFeelInfo lookAndFeelInfo: lookAndFeelInfos) {
+                       try {
+                               Class.forName(lookAndFeelInfo.getClassName());
+                               allLookAndFeelInfos.add(lookAndFeelInfo);
+                       } catch (ClassNotFoundException e) {
+                               /* okay, it doesn't exist, ignore. */
+                       }
                }
+               UIManager.setInstalledLookAndFeels(allLookAndFeelInfos.toArray(new LookAndFeelInfo[0]));
        }
 
 }