From dc79f593c85267db340e09c23d4e7c4b6d35043b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 21 May 2008 06:49:36 +0000 Subject: [PATCH] install known look & feels before starting git-svn-id: http://trooper/svn/projects/jSite/trunk@919 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/jsite/main/Main.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/net/pterodactylus/jsite/main/Main.java b/src/net/pterodactylus/jsite/main/Main.java index 0c157a8..1ee88a0 100644 --- a/src/net/pterodactylus/jsite/main/Main.java +++ b/src/net/pterodactylus/jsite/main/Main.java @@ -21,6 +21,9 @@ package net.pterodactylus.jsite.main; import java.io.File; +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; + import net.pterodactylus.jsite.core.CoreImpl; import net.pterodactylus.jsite.core.NodeManager; import net.pterodactylus.jsite.core.ProjectManager; @@ -52,6 +55,9 @@ 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"; @@ -77,4 +83,26 @@ public class Main { core.start(); } + /** + * Tries to load the class with the given name and includes the look & feel + * in the UIManager, if it exists. + * + * @param name + * The name of the look & feel + * @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. */ + } + } + } -- 2.7.4