Mp3dings 
20100427

de.mospace.swing
Class LaFInstaller

java.lang.Object
  extended by de.mospace.swing.ExtensionInstaller
      extended by de.mospace.swing.LaFInstaller

public final class LaFInstaller
extends ExtensionInstaller

This class provides a convenient way to install new LookAndFeels in a Sun JRE. Given an archive with a LookAndFeel it will try to copy the jar file to a java extensions directory as per the system property java.ext.dirs or a client specified directory and add an entry to the property file swing.properties.
If the installation was succesfull, the LookAndFeel will be accessible through UIManager.getInstalledLookAndFeels() with the next invocation of the JVM. In particular, applications can let the user switch to the new LookAndFeel with a LookAndFeelMenu.

Author:
Moritz Ringler

Nested Class Summary
static class LaFInstaller.LaFPackage
          Description of the Class
 
Field Summary
 
Fields inherited from class de.mospace.swing.ExtensionInstaller
parent
 
Constructor Summary
LaFInstaller()
          Constructs a new LaFInstaller with a null parent component.
LaFInstaller(Component parent)
          Constructs a new LaFInstaller.
LaFInstaller(Component parent, File installdir, File lafProperties)
           
 
Method Summary
static boolean canInstall()
          Returns whether we can install new LookAndFeels.
static boolean canInstall(File props)
          Returns whether we can install new LookAndFeels.
 boolean installExtension(File jarFile)
          Calling this method on a LafInstaller will cause an UnsupportedOperationException.
 boolean installExtension(File zip, String extjars)
          Calling this method on a LafInstaller will cause an UnsupportedOperationException.
 boolean installLaF(LaFInstaller.LaFPackage laf)
          Tries to install the specified LookAndFeel and returns whether the installation was successful.
 boolean installLaF(LaFInstaller.LaFPackage laf, ClassLoaderProvider clp)
           
static void main(String[] argv)
          Allows direct invocation of the LaFInstaller from the command line.
 LaFInstaller.LaFPackage pickLaF(LaFInstaller.LaFPackage[] lafs)
          Asks the user to pick one of several LookAndFeels.
 LaFInstaller.LaFPackage queryLaF()
          Aks the user to specify an archive wich will be searched for LookAndFeels as per LaFInstaller.LaFPackage.fromJar(java.io.File) and LaFInstaller.LaFPackage.fromZip(java.io.File).
 void updateUIManagerInstalledLafs()
          Updates UIManagers installedLookAndFeels with the current state of installedlafs.
static void warnCannotInstall(Component pparent, File iprops)
          Checks whether we can install new LookAndFeels and displays a dialog with an error message if not.
 
Methods inherited from class de.mospace.swing.ExtensionInstaller
ask, canWrite, getFallbackTargetDirectory, getTargetDirectory, getWritableExtensionDirectory, installExtension, installExtension, isTemporary, queryFile, setFallbackTargetDirectory, setTargetDirectory, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LaFInstaller

public LaFInstaller()
Constructs a new LaFInstaller with a null parent component.


LaFInstaller

public LaFInstaller(Component parent)
Constructs a new LaFInstaller.

Parameters:
parent - The parent component to use for dialogs. Can be null

LaFInstaller

public LaFInstaller(Component parent,
                    File installdir,
                    File lafProperties)
Method Detail

main

public static void main(String[] argv)
                 throws IOException
Allows direct invocation of the LaFInstaller from the command line.

Parameters:
argv - No arguments are expected.
Throws:
IOException - if an I/O error occurred during modification of swing.properties.

canInstall

public static boolean canInstall(File props)
Returns whether we can install new LookAndFeels.

Returns:
a boolean indicating whether we can modify the swing.properties file.

canInstall

public static boolean canInstall()
Returns whether we can install new LookAndFeels.

Returns:
a boolean indicating whether we can modify the swing.properties file.

warnCannotInstall

public static void warnCannotInstall(Component pparent,
                                     File iprops)
Checks whether we can install new LookAndFeels and displays a dialog with an error message if not.

Parameters:
pparent - Description of the Parameter

queryLaF

public LaFInstaller.LaFPackage queryLaF()
Aks the user to specify an archive wich will be searched for LookAndFeels as per LaFInstaller.LaFPackage.fromJar(java.io.File) and LaFInstaller.LaFPackage.fromZip(java.io.File). If no LaF is found displays a warning message and returns. If more than one LookandFeel is found asks the user to pick one.

Returns:
the LookAndFeel specified by the user or null if no LookAndFeel has been found, the user cancelled a dialog or an I/O error occurred.

pickLaF

public LaFInstaller.LaFPackage pickLaF(LaFInstaller.LaFPackage[] lafs)
Asks the user to pick one of several LookAndFeels.

Parameters:
lafs - the LookAndFeels to choose from.
Returns:
the selected LookAndFeel or null if the user cancelled the dialog.

installLaF

public boolean installLaF(LaFInstaller.LaFPackage laf)
                   throws IOException
Tries to install the specified LookAndFeel and returns whether the installation was successful. More specifically, installs the jar file returned by laf.getJar() to this installer's target directory and modifies swing.properties to include the LookAndFeel referenced by jar.

Parameters:
laf - The LookAndFeel to install. May be null.
Returns:
whether the jar file was copied and swing.properties was modified to include the new LookAndFeel.
Throws:
IOException - when an error occurs during modification of swing.properties .

installLaF

public boolean installLaF(LaFInstaller.LaFPackage laf,
                          ClassLoaderProvider clp)
                   throws IOException
Throws:
IOException

installExtension

public boolean installExtension(File jarFile)
Calling this method on a LafInstaller will cause an UnsupportedOperationException. Use installLaF(de.mospace.swing.LaFInstaller.LaFPackage) if you want to install a LookAndFeel or a generic ExtensionInstaller if you want to install a different kind of extension.

Overrides:
installExtension in class ExtensionInstaller
Parameters:
jarFile - ...
Returns:
...
Throws:
UnsupportedOperationException

installExtension

public boolean installExtension(File zip,
                                String extjars)
Calling this method on a LafInstaller will cause an UnsupportedOperationException. Use installLaF(de.mospace.swing.LaFInstaller.LaFPackage) if you want to install a LookAndFeel or a generic ExtensionInstaller if you want to install a different kind of extension.

Overrides:
installExtension in class ExtensionInstaller
Parameters:
zip - ...
extjars - ...
Returns:
...
Throws:
UnsupportedOperationException

updateUIManagerInstalledLafs

public void updateUIManagerInstalledLafs()
Updates UIManagers installedLookAndFeels with the current state of installedlafs.


Mp3dings 
20100427