com.mucommander.ui.theme
Class ThemeManager

java.lang.Object
  extended by com.mucommander.ui.theme.ThemeManager

public class ThemeManager
extends java.lang.Object

Offers methods for accessing and modifying themes.

Author:
Nicolas Rinaudo

Method Summary
static void addCurrentThemeListener(ThemeListener listener)
          Adds the specified object to the list of registered current theme listeners.
static java.util.Iterator availableThemeNames()
           
static java.util.Iterator availableThemes()
           
static void deleteCustomTheme(java.lang.String name)
           
static Theme duplicateTheme(Theme theme)
           
static void exportTheme(int type, java.lang.String name, java.io.File file)
          Exports the specified theme to the specified output stream.
static void exportTheme(int type, java.lang.String name, java.io.OutputStream out)
          Exports the specified theme to the specified output stream.
static void exportTheme(Theme theme, java.io.File file)
          Exports the specified theme to the specified output stream.
static void exportTheme(Theme theme, java.io.OutputStream out)
          Exports the specified theme to the specified output stream.
static java.util.Vector getAvailableThemeNames()
           
static java.util.Vector getAvailableThemes()
           
static java.awt.Color getCurrentColor(int id)
           
static java.awt.Font getCurrentFont(int id)
           
static Theme getCurrentTheme()
           
static AbstractFile getCustomThemesFolder()
          Returns the path to the custom themes' folder.
static AbstractFile getUserThemeFile()
          Returns the path to the user's theme file.
static Theme importTheme(java.io.File file)
           
static Theme importTheme(ThemeData data, java.lang.String name)
           
static boolean isCurrentTheme(Theme theme)
          Returns true if the specified theme is the current one.
static void loadCurrentTheme()
          Loads the current theme.
static Theme overwriteUserTheme(ThemeData themeData)
           
static Theme readTheme(int type, java.lang.String name)
          Returns the requested theme.
static ThemeData readThemeData(java.io.File file)
          Reads theme data from the specified file.
static ThemeData readThemeData(java.io.InputStream in)
          Reads theme data from the specified input stream.
static void removeCurrentThemeListener(ThemeListener listener)
          Removes the specified object from the list of registered theme listeners.
static boolean renameCustomTheme(Theme theme, java.lang.String name)
           
static void saveCurrentTheme()
          Saves the current theme if necessary.
static boolean setCurrentColor(int id, java.awt.Color color)
          Updates the current theme with the specified color.
static boolean setCurrentFont(int id, java.awt.Font font)
          Updates the current theme with the specified font.
static void setCurrentTheme(Theme theme)
          Changes the current theme.
static void setUserThemeFile(AbstractFile file)
          Sets the path to the user theme file.
static void setUserThemeFile(java.io.File file)
          Sets the path to the user theme file.
static void setUserThemeFile(java.lang.String path)
          Sets the path to the user theme file.
static boolean willOverwriteUserTheme(int colorId, java.awt.Color color)
          Checks whether setting the specified color would require overwriting of the user theme.
static boolean willOverwriteUserTheme(int fontId, java.awt.Font font)
          Checks whether setting the specified font would require overwriting of the user theme.
static void writeTheme(Theme theme)
          Writes the content of the specified theme to its description file.
static void writeTheme(ThemeData data, int type, java.lang.String name)
          Writes the specified theme data over the theme described by type and name.
static void writeThemeData(ThemeData data, java.io.File file)
          Writes the content of the specified theme data to the specified file.
static void writeThemeData(ThemeData data, java.io.OutputStream out)
          Writes the content of the specified theme data to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadCurrentTheme

public static void loadCurrentTheme()
Loads the current theme.

This method goes through the following steps:


getAvailableThemes

public static java.util.Vector getAvailableThemes()

getAvailableThemeNames

public static java.util.Vector getAvailableThemeNames()

availableThemeNames

public static java.util.Iterator availableThemeNames()

availableThemes

public static java.util.Iterator availableThemes()

getUserThemeFile

public static AbstractFile getUserThemeFile()
                                     throws java.io.IOException
Returns the path to the user's theme file.

This method cannot guarantee the file's existence, and it's up to the caller to deal with the fact that the user might not actually have created a user theme.

This method's return value can be modified through setUserThemeFile(String). If this wasn't called, the default path will be used. This is generated by calling new java.io.File(PlatformManager.getPreferencesFolder(), USER_THEME_FILE_NAME).

Returns:
the path to the user's theme file.
Throws:
java.io.IOException - if an error occured while locating the default user theme file.
See Also:
setUserThemeFile(String)

setUserThemeFile

public static void setUserThemeFile(java.io.File file)
                             throws java.io.FileNotFoundException
Sets the path to the user theme file.

The specified file does not have to exist. If it does, however, it must be accessible.

Parameters:
file - path to the user theme file.
Throws:
java.io.FileNotFoundException - if file is not accessible.
See Also:
getUserThemeFile()

setUserThemeFile

public static void setUserThemeFile(AbstractFile file)
                             throws java.io.FileNotFoundException
Sets the path to the user theme file.

The specified file does not have to exist. If it does, however, it must be accessible.

Parameters:
file - path to the user theme file.
Throws:
java.lang.IllegalArgumentException - if file exists but is not accessible.
java.io.FileNotFoundException
See Also:
getUserThemeFile()

setUserThemeFile

public static void setUserThemeFile(java.lang.String path)
                             throws java.io.FileNotFoundException
Sets the path to the user theme file.

The specified file does not have to exist. If it does, however, it must be accessible.

Parameters:
path - path to the user theme file.
Throws:
java.io.FileNotFoundException - if path is not accessible.
See Also:
getUserThemeFile()

getCustomThemesFolder

public static AbstractFile getCustomThemesFolder()
                                          throws java.io.IOException
Returns the path to the custom themes' folder.

This method guarantees that the returned file actually exists.

Returns:
the path to the custom themes' folder.
Throws:
java.io.IOException - if an error occured while locating the default user themes folder.

deleteCustomTheme

public static void deleteCustomTheme(java.lang.String name)
                              throws java.io.IOException
Throws:
java.io.IOException

renameCustomTheme

public static boolean renameCustomTheme(Theme theme,
                                        java.lang.String name)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeThemeData

public static void writeThemeData(ThemeData data,
                                  java.io.OutputStream out)
                           throws java.io.IOException
Writes the content of the specified theme data to the specified output stream.

This method differs from exportTheme(Theme,OutputStream) in that it will write the theme data only, skipping comments and other metadata.

Parameters:
data - theme data to write.
out - where to write the theme data.
Throws:
java.io.IOException - if an I/O related error occurs.
See Also:
exportTheme(Theme,OutputStream), exportTheme(Theme,File), writeThemeData(ThemeData,File).

writeThemeData

public static void writeThemeData(ThemeData data,
                                  java.io.File file)
                           throws java.io.IOException
Writes the content of the specified theme data to the specified file.

This method differs from exportTheme(Theme,File) in that it will write the theme data only, skipping comments and other metadata.

Parameters:
data - theme data to write.
file - file in which to write the theme data.
Throws:
java.io.IOException - if an I/O related error occurs.
See Also:
exportTheme(Theme,OutputStream), exportTheme(Theme,File), writeThemeData(ThemeData,OutputStream).

writeTheme

public static void writeTheme(Theme theme)
                       throws java.io.IOException
Writes the content of the specified theme to its description file.

Parameters:
theme - theme to write.
Throws:
java.io.IOException - if any I/O related error occurs.
java.lang.IllegalArgumentException - if theme is a predefined theme.
See Also:
writeTheme(ThemeData,int,String)

writeTheme

public static void writeTheme(ThemeData data,
                              int type,
                              java.lang.String name)
                       throws java.io.IOException
Writes the specified theme data over the theme described by type and name.

Note that this method doesn't check whether this will overwrite an existing theme.

If type equals Theme.USER_THEME, name will be ignored.

Parameters:
data - data to write.
type - type of the theme that is being written.
name - name of the theme that is being written.
Throws:
java.io.IOException - if any I/O related error occurs.
java.lang.IllegalArgumentException - if theme is a predefined theme.
See Also:
writeTheme(Theme)

exportTheme

public static void exportTheme(int type,
                               java.lang.String name,
                               java.io.OutputStream out)
                        throws java.io.IOException
Exports the specified theme to the specified output stream.

If type is equal to Theme.USER_THEME, the name argument will be ignored as there is only one user theme.

This method differs from writeThemeData(ThemeData,OutputStream) in that it doesn't only copy the theme's data, but the whole content of the theme file, including comments. It also requires the theme file to exist.

Parameters:
type - type of the theme to export.
name - name of the theme to export.
out - where to write the theme.
Throws:
java.io.IOException - if any I/O related error occurs.
See Also:
exportTheme(int,String,File), writeThemeData(ThemeData,OutputStream)

exportTheme

public static void exportTheme(int type,
                               java.lang.String name,
                               java.io.File file)
                        throws java.io.IOException
Exports the specified theme to the specified output stream.

If type is equal to Theme.USER_THEME, the name argument will be ignored as there is only one user theme.

This method differs from writeThemeData(ThemeData,File) in that it doesn't only copy the theme's data, but the whole content of the theme file, including comments.

Parameters:
type - type of the theme to export.
name - name of the theme to export.
file - where to write the theme.
Throws:
java.io.IOException - if any I/O related error occurs
See Also:
exportTheme(int,String,OutputStream), writeThemeData(ThemeData,File).

exportTheme

public static void exportTheme(Theme theme,
                               java.io.OutputStream out)
                        throws java.io.IOException
Exports the specified theme to the specified output stream.

This is a convenience method only and is strictly equivalent to calling exportTheme(theme.getType(), theme.getName(), out);

Parameters:
theme - theme to export.
out - where to write the theme.
Throws:
java.io.IOException - if any I/O related error occurs.

exportTheme

public static void exportTheme(Theme theme,
                               java.io.File file)
                        throws java.io.IOException
Exports the specified theme to the specified output stream.

This is a convenience method only and is strictly equivalent to calling exportTheme(theme.getType(), theme.getName(), file);

Parameters:
theme - theme to export.
file - where to write the theme.
Throws:
java.io.IOException - if any I/O related error occurs.

duplicateTheme

public static Theme duplicateTheme(Theme theme)
                            throws java.io.IOException,
                                   java.lang.Exception
Throws:
java.io.IOException
java.lang.Exception

importTheme

public static Theme importTheme(ThemeData data,
                                java.lang.String name)
                         throws java.io.IOException,
                                java.lang.Exception
Throws:
java.io.IOException
java.lang.Exception

importTheme

public static Theme importTheme(java.io.File file)
                         throws java.io.IOException,
                                java.lang.Exception
Throws:
java.io.IOException
java.lang.Exception

readTheme

public static Theme readTheme(int type,
                              java.lang.String name)
                       throws java.lang.Exception
Returns the requested theme.

Parameters:
type - type of theme to retrieve.
name - name of the theme to retrieve.
Returns:
the requested theme.
Throws:
java.lang.Exception

readThemeData

public static ThemeData readThemeData(java.io.InputStream in)
                               throws java.lang.Exception
Reads theme data from the specified input stream.

Parameters:
in - where to read the theme data from.
Returns:
the resulting theme data.
Throws:
java.lang.Exception - if an I/O or syntax error occurs.

readThemeData

public static ThemeData readThemeData(java.io.File file)
                               throws java.lang.Exception
Reads theme data from the specified file.

Parameters:
file - where to read the theme data from.
Returns:
the resulting theme data.
Throws:
java.lang.Exception - if an I/O or syntax error occurs.

saveCurrentTheme

public static void saveCurrentTheme()
                             throws java.io.IOException
Saves the current theme if necessary.

Throws:
java.io.IOException

getCurrentTheme

public static Theme getCurrentTheme()

setCurrentTheme

public static void setCurrentTheme(Theme theme)
Changes the current theme.

This method will change the current theme and trigger all the proper events.

Parameters:
theme - theme to use as the current theme.
Throws:
java.lang.IllegalArgumentException - thrown if the specified theme could not be loaded.

getCurrentFont

public static java.awt.Font getCurrentFont(int id)

getCurrentColor

public static java.awt.Color getCurrentColor(int id)

overwriteUserTheme

public static Theme overwriteUserTheme(ThemeData themeData)
                                throws java.io.IOException
Throws:
java.io.IOException

willOverwriteUserTheme

public static boolean willOverwriteUserTheme(int fontId,
                                             java.awt.Font font)
Checks whether setting the specified font would require overwriting of the user theme.

Parameters:
fontId - identifier of the font to set.
font - value for the specified font.
Returns:
true if applying the specified font will overwrite the user theme, false otherwise.

willOverwriteUserTheme

public static boolean willOverwriteUserTheme(int colorId,
                                             java.awt.Color color)
Checks whether setting the specified color would require overwriting of the user theme.

Parameters:
colorId - identifier of the color to set.
color - value for the specified color.
Returns:
true if applying the specified color will overwrite the user theme, false otherwise.

setCurrentFont

public static boolean setCurrentFont(int id,
                                     java.awt.Font font)
Updates the current theme with the specified font.

This method might require to overwrite the user theme: custom and predefined themes are read only. In order to modify them, the ThemeManager must overwrite the user theme with the current theme and then set the font.
If necessary, this can be checked beforehand by a call to willOverwriteUserTheme(int,Font).

Parameters:
id - identifier of the font to set.
font - font to set.

setCurrentColor

public static boolean setCurrentColor(int id,
                                      java.awt.Color color)
Updates the current theme with the specified color.

This method might require to overwrite the user theme: custom and predefined themes are read only. In order to modify them, the ThemeManager must overwrite the user theme with the current theme and then set the color.
If necessary, this can be checked beforehand by a call to willOverwriteUserTheme(int,Color).

Parameters:
id - identifier of the color to set.
color - color to set.

isCurrentTheme

public static boolean isCurrentTheme(Theme theme)
Returns true if the specified theme is the current one.

Parameters:
theme - theme to check.
Returns:
true if the specified theme is the current one, false otherwise.

addCurrentThemeListener

public static void addCurrentThemeListener(ThemeListener listener)
Adds the specified object to the list of registered current theme listeners.

Any object registered through this method will received color and font events whenever the current theme changes.

Note that these events will not necessarily be fired as a result of a direct theme change: if, for example, the current theme is using look&feel dependant values and the current look&feel changes, the corresponding events will be passed to registered listeners.

Listeners are stored as weak references, to make sure that the API doesn't keep ghost copies of objects whose usefulness is long since past. This forces callers to make sure they keep a copy of the listener's instance: if they do not, the instance will be weakly linked and garbage collected out of existence.

Parameters:
listener - new current theme listener.

removeCurrentThemeListener

public static void removeCurrentThemeListener(ThemeListener listener)
Removes the specified object from the list of registered theme listeners.

Note that since listeners are stored as weak references, calling this method is not strictly necessary. As soon as a listener instance is not referenced anymore, it will automatically be caught and destroyed by the garbage collector.

Parameters:
listener - current theme listener to remove.


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard