com.miginfocom.theme
Class Themes

java.lang.Object
  extended by com.miginfocom.theme.Themes

public class Themes
extends java.lang.Object

Handles loading and saving of themes and is a container for looking up themes with a context.


Method Summary
static Theme getTheme(java.lang.String context)
          Returns an instance of the Theme with the specified context.
static boolean hasTheme(java.lang.String context)
          Returns if an instance of the Theme with the specified context already is created.
static Theme loadTheme(java.io.InputStream in, java.lang.String context, boolean validate, boolean isZipped)
          Reads a com.miginfocom.theme from an input stream, normally a file or an URL.
static Theme loadTheme(java.lang.String filename, java.lang.String context, boolean validate)
          Reads a com.miginfocom.theme from disk.
static Theme loadTheme(java.net.URL url, java.lang.String context, boolean validate)
          Reads a com.miginfocom.theme from an URL.
static void saveTheme(Theme theme, java.io.OutputStream os, boolean zipIt)
          Saves the com.miginfocom.theme to a file uning a XMLEncoder to produce XML.
static void saveTheme(Theme theme, java.lang.String filename, boolean zipIt)
          Make a OutputStream to the file and call saveTheme(Theme, java.io.OutputStream, boolean).
static Theme setTheme(java.lang.String context, Theme theme)
          Associates the com.miginfocom.theme with the context overwriting any ond
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTheme

public static Theme getTheme(java.lang.String context)
Returns an instance of the Theme with the specified context.

Parameters:
context - The context that is used as a key to find a com.miginfocom.theme. null is allowed.
Returns:
An instance of the Theme that is found with the supplied context above. Never null. throws a IllegalArgumentException if the context isn't found.

setTheme

public static Theme setTheme(java.lang.String context,
                             Theme theme)
Associates the com.miginfocom.theme with the context overwriting any ond

Parameters:
context - The context to assicoate the com.miginfocom.theme with. May be null.
theme - The com.miginfocom.theme. If null the com.miginfocom.theme is cleared for that context.
Returns:
The old com.miginfocom.theme associated with the context or null if none.

hasTheme

public static boolean hasTheme(java.lang.String context)
Returns if an instance of the Theme with the specified context already is created.

Parameters:
context - The context that is used as a key to find a com.miginfocom.theme. null is allowed and considered the default "global" instance if there is only one, which is normal. The context can for instance be the datePicker that is using the com.miginfocom.theme. This is a good approach if there are many DatePickers with different themes.
Returns:
An instance of the Theme that is found with the supplied context above. Never null.

loadTheme

public static Theme loadTheme(java.lang.String filename,
                              java.lang.String context,
                              boolean validate)
                       throws java.io.IOException
Reads a com.miginfocom.theme from disk. File may be zipped.

Parameters:
filename - The file name to load the com.miginfocom.theme from. E.g. "C:/MyTheme.dpt"
context - The context that the com.miginfocom.theme should be associated with in the contained list. null is the "global" context and can be used.
validate - If true the loaded com.miginfocom.theme is validated and a ValidateException is thrown if any of the keys are not validated ok.
Returns:
A com.miginfocom.theme, never null.
Throws:
java.io.IOException
See Also:
getTheme(java.lang.String)

loadTheme

public static Theme loadTheme(java.net.URL url,
                              java.lang.String context,
                              boolean validate)
                       throws java.io.IOException
Reads a com.miginfocom.theme from an URL. Stream may be zipped.

Parameters:
url - The URL to read from.
context - The context that the com.miginfocom.theme should be associated with in the contained list. null is the "global" context and can be used.
validate - If true the loaded com.miginfocom.theme is validated and a ValidateException is thrown if any of the keys are not validated ok.
Returns:
A com.miginfocom.theme, never null.
Throws:
java.io.IOException

loadTheme

public static Theme loadTheme(java.io.InputStream in,
                              java.lang.String context,
                              boolean validate,
                              boolean isZipped)
                       throws java.io.IOException
Reads a com.miginfocom.theme from an input stream, normally a file or an URL. If a com.miginfocom.theme already exists for 'context' that com.miginfocom.theme is changed instead of creating a new one. The stream can be ziped, this is handled automatically.

Parameters:
in - For example a FileInputStream or new URL(...).openStream() Will be wrapped in a BufferedInputStream if not already buffered.

Will not be closed in this method.

context - The context that the com.miginfocom.theme should be associated with in the contained list. null is the "global" context and can be used.
validate - If true the loaded com.miginfocom.theme is validated and a ValidateException is thrown if any of the keys are not validated ok.
isZipped - If in doesn't support mark/reset there is no way to test if the stream is zipped. If so this value will be used. If the stream does support mark/reset the value is gotten from the stream and this argument is not used.
Returns:
The new or changed com.miginfocom.theme, never null.
Throws:
java.io.IOException

saveTheme

public static void saveTheme(Theme theme,
                             java.lang.String filename,
                             boolean zipIt)
                      throws java.io.IOException
Make a OutputStream to the file and call saveTheme(Theme, java.io.OutputStream, boolean).

Parameters:
theme - The com.miginfocom.theme to save.
filename - Then filename to save the file to.
zipIt - If det to true the output stream is ziped with level 9.
Throws:
java.io.IOException
See Also:
Encoder.setExceptionListener(java.beans.ExceptionListener)

saveTheme

public static void saveTheme(Theme theme,
                             java.io.OutputStream os,
                             boolean zipIt)
                      throws java.io.IOException
Saves the com.miginfocom.theme to a file uning a XMLEncoder to produce XML. If there were recovarabe exceptions caught from the XMLEncoder, the are printed to System.err.
IOUtil.addDelegates(java.beans.XMLEncoder) will be called to add delegates to save the values in the Theme. Add custom delegates to IOUtil to support more types to save.

Parameters:
theme - The com.miginfocom.theme to save.
os - The output stream to save to.
zipIt - If set to true the output stream is ziped with level 9.
Throws:
java.io.IOException
See Also:
Encoder.setExceptionListener(java.beans.ExceptionListener)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.