wyvern.util
Class SkinManager

java.lang.Object
  extended bywyvern.util.SkinManager

public final class SkinManager
extends java.lang.Object

Sets up a custom Look & Feel for the application.

Version:
1.0, Jan 30, 2003
Author:
Steve Yegge

Method Summary
static void addSkinsDirectory(java.lang.String path)
          Adds a directory for looking for themes.
static void addUpdateComponent(java.awt.Component c)
          Adds a component to be updated when we revalidate.
static java.util.Vector getAvailableSkins()
          Returns a list of available skins by searching the default skins directory, plus user-specified directories.
static java.lang.String getClassFromDisplayName(java.lang.String display)
          Returns the fully qualified java classname for a LookAndFeel implementation, given its display name.
static java.lang.String getCurrentLookAndFeel()
          Returns the display name of the look & feel (LookAndFeel or SkinLookAndFeel theme pack) that we're running.
static java.lang.String getDisplayName(java.lang.String path)
          Returns the display name for a theme or LookAndFeel class.
static java.lang.String getThemeDisplayName(java.lang.String path)
          Returns a user-visible name for a theme.
static void initLookAndFeel()
          Tries to set a custom Swing look & feel, based on the configuration settings passed to setProperties().
static java.lang.String processJAR(java.lang.String entry)
          Looks up info about one of our JAR LAF files in mapedit.ini or client.ini.
static void removeAllUpdateComponents()
          Removes the entire list of update components.
static void removeUpdateComponent(java.awt.Component c)
          Removes a component that's not needed to be updated anymore.
static void revalidateUI()
          Revalidates the tree, forcing everything to switch to the new UI.
static void setPlatformDefaultLookAndFeel()
          Attempts to set the default, system-specific look and feel for the current platform.
static void setProperties(java.util.Properties props)
          Sets the configuration properties for the SkinManager.
static boolean switchLookAndFeel(java.lang.String path)
          Switches to either a LookAndFeel or a SkinLookAndFeel + theme.
static boolean switchTheme(java.lang.String path)
          Loads and uses the specified SkinLookAndFeel theme pack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setProperties

public static void setProperties(java.util.Properties props)
Sets the configuration properties for the SkinManager.

The configuration for this class is data-driven from properties in .ini files - for now, just client.ini and mapedit.ini. The application can pass in a Properties object to this method. The SkinManager looks at the following properties, in this order:

Parameters:
props - a Properties file containing any of the properties listed above

addSkinsDirectory

public static void addSkinsDirectory(java.lang.String path)
Adds a directory for looking for themes.

Parameters:
path - a directory to add to the search path

addUpdateComponent

public static void addUpdateComponent(java.awt.Component c)
Adds a component to be updated when we revalidate. Usually passing the root frame in is fine, but we sometimes have stuff that doesn't get caught by that.


removeUpdateComponent

public static void removeUpdateComponent(java.awt.Component c)
Removes a component that's not needed to be updated anymore.


removeAllUpdateComponents

public static void removeAllUpdateComponents()
Removes the entire list of update components.


initLookAndFeel

public static void initLookAndFeel()
Tries to set a custom Swing look & feel, based on the configuration settings passed to setProperties(). If some settings weren't provided, we use internal defaults.


getAvailableSkins

public static java.util.Vector getAvailableSkins()
Returns a list of available skins by searching the default skins directory, plus user-specified directories. You might want to call Util.markBusy() around this call.

Returns:
a list of paths to theme packs to choose from, or null if none were found.

switchLookAndFeel

public static boolean switchLookAndFeel(java.lang.String path)
Switches to either a LookAndFeel or a SkinLookAndFeel + theme.

Parameters:
path - any of the following:
  • a display name that we got back from getAvailableSkins()
  • a theme-pack name from the skins dir, e.g. "aquathemepack.zip"
  • a theme-pack resource path (i.e. non-skins directory)
  • a fully-qualified LookAndFeel classname of a class that needs to be in the jvm classpath already.
If path ends with ".zip" it's assumed to be a theme pack for the SkinLookAndFeel; otherwise it's considered a LookAndFeel fully-qualified classname.
Returns:
true if we succeeded in switching to the passed theme or LookAndFeel.

switchTheme

public static boolean switchTheme(java.lang.String path)
Loads and uses the specified SkinLookAndFeel theme pack. It's up to the application to save this setting.

Parameters:
path - the resource-path to the theme pack, such as "/wyvern/skins/aquathemepack.zip".
Returns:
true if we were successful

revalidateUI

public static void revalidateUI()
Revalidates the tree, forcing everything to switch to the new UI. Necessary after switching skins.


setPlatformDefaultLookAndFeel

public static void setPlatformDefaultLookAndFeel()
Attempts to set the default, system-specific look and feel for the current platform.

Returns:
true if we succeeded

getDisplayName

public static java.lang.String getDisplayName(java.lang.String path)
Returns the display name for a theme or LookAndFeel class. The only way we can get these is by having them set manually in an initfile for the application that's using them. The app has to pass it in to us via setProperties(). We just look in the properties list to see if the app has set the name.

You can set two types of names in the config properties:

We scan for the LAF display names in setProperties(), and we add the theme names to our cache when someone calls getAvailableSkins().

Returns:
the user-visible name, or null if not found

getThemeDisplayName

public static java.lang.String getThemeDisplayName(java.lang.String path)
Returns a user-visible name for a theme.

Parameters:
path - the resource path for a theme, for Wyvern.loadResource()
Returns:
the display name, or just the passed path if we couldn't decode the display name. Example: "/wyvern/skins/aquathemepack.zip"

getClassFromDisplayName

public static java.lang.String getClassFromDisplayName(java.lang.String display)
Returns the fully qualified java classname for a LookAndFeel implementation, given its display name. The display names are the author-chosen names of the LAFs.

Returns:
a ".zip" path, meaning it's a theme pack, or the fully-qualified classname of a LookAndFeel implementation. Can return null if we don't know what this name is.

processJAR

public static java.lang.String processJAR(java.lang.String entry)
Looks up info about one of our JAR LAF files in mapedit.ini or client.ini.

Parameters:
entry - the ini-file entry:
Returns:
the display name, or null if it's not a valid LAF. Remembers the mapping of display name to classname, so we can instantiate it when the user clicks on the display name.

getCurrentLookAndFeel

public static java.lang.String getCurrentLookAndFeel()
Returns the display name of the look & feel (LookAndFeel or SkinLookAndFeel theme pack) that we're running.

Returns:
the LAF/theme display name, suitable for showing to the user. You can call getClassFromDisplayName on it to get the classname or theme-pack name. Returns null if we haven't set a LAF through the SkinManager.