com.alee.managers.settings
Class ComponentSettingsManager

java.lang.Object
  extended by com.alee.managers.settings.ComponentSettingsManager

public class ComponentSettingsManager
extends java.lang.Object

This SettingsManager sub-manager registers and processes component settings auto-save/restore them on any changes within or outside of that component.

This manager should never be called directly (except the case when you register new SettingsProcessor or if you know what you are doing) to avoid any unexpected component behavior.

Author:
Mikle Garin
See Also:
How to use SettingsManager, SettingsManager, SettingsManager

Field Summary
static java.lang.String COMPONENT_SETTINGS_PROCESSOR_KEY
          Keys used to store custom data in JComponent.
protected static boolean initialized
          Whether ComponentSettingsManager is initialized or not.
protected static java.util.Map<java.lang.Class,java.lang.Class> settingsProcessorClasses
          Registered settings processor classes.
protected static java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<SettingsProcessor>> settingsProcessors
          Registered component settings processors.
protected static boolean throwExceptions
          Whether throw exceptions on inappropriate actions or not.
 
Constructor Summary
ComponentSettingsManager()
           
 
Method Summary
protected static SettingsProcessor createSettingsProcessor(SettingsProcessorData data)
          Returns new SettingsProcessor instance for the specified SettingsProcessorData.
protected static java.lang.Class findSuitableSettingsProcessor(java.lang.Class componentType)
          Returns settings processor class for the specified component type.
static void initializeManager()
          Initializes ComponentSettingsManager.
static boolean isComponentSupported(java.lang.Class<? extends javax.swing.JComponent> componentType)
          Returns whether the specified component is supported or not.
static boolean isComponentSupported(javax.swing.JComponent component)
          Returns whether the specified component is supported or not.
static boolean isThrowExceptions()
          Returns whether exceptions are thrown on inappropriate actions or not.
static void loadSettings(javax.swing.JComponent component)
          Loads saved settings into the component if it is registered.
static void registerComponent(javax.swing.JComponent component, SettingsProcessor settingsProcessor)
          Registers component using the specified SettingsProcessor.
static void registerComponent(SettingsProcessorData data)
          Registers component using the specified SettingsProcessorData.
static
<T extends SettingsProcessor>
void
registerSettingsProcessor(java.lang.Class<? extends javax.swing.JComponent> componentType, java.lang.Class<T> settingsProcessor)
          Registers specified settings processor class for the specified component type.
static void saveSettings()
          Saves all registered components settings.
static void saveSettings(javax.swing.JComponent component)
          Saves component settings.
static void setThrowExceptions(boolean throwExceptions)
          Sets whether throw exceptions on inappropriate actions or not.
static void unregisterComponent(javax.swing.JComponent component)
          Unregisters component from settings auto-save.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_SETTINGS_PROCESSOR_KEY

public static final java.lang.String COMPONENT_SETTINGS_PROCESSOR_KEY
Keys used to store custom data in JComponent.

See Also:
Constant Field Values

settingsProcessorClasses

protected static final java.util.Map<java.lang.Class,java.lang.Class> settingsProcessorClasses
Registered settings processor classes.


settingsProcessors

protected static final java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<SettingsProcessor>> settingsProcessors
Registered component settings processors.


throwExceptions

protected static boolean throwExceptions
Whether throw exceptions on inappropriate actions or not.


initialized

protected static boolean initialized
Whether ComponentSettingsManager is initialized or not.

Constructor Detail

ComponentSettingsManager

public ComponentSettingsManager()
Method Detail

initializeManager

public static void initializeManager()
Initializes ComponentSettingsManager.


isThrowExceptions

public static boolean isThrowExceptions()
Returns whether exceptions are thrown on inappropriate actions or not.

Returns:
true if exceptions are thrown on inappropriate actions, false otherwise

setThrowExceptions

public static void setThrowExceptions(boolean throwExceptions)
Sets whether throw exceptions on inappropriate actions or not.

Parameters:
throwExceptions - whether throw exceptions on inappropriate actions or not

isComponentSupported

public static boolean isComponentSupported(javax.swing.JComponent component)
Returns whether the specified component is supported or not.

Parameters:
component - component
Returns:
true if the specified component is supported, false otherwise

isComponentSupported

public static boolean isComponentSupported(java.lang.Class<? extends javax.swing.JComponent> componentType)
Returns whether the specified component is supported or not.

Parameters:
componentType - component type
Returns:
true if the specified component is supported, false otherwise

registerSettingsProcessor

public static <T extends SettingsProcessor> void registerSettingsProcessor(java.lang.Class<? extends javax.swing.JComponent> componentType,
                                                                           java.lang.Class<T> settingsProcessor)
Registers specified settings processor class for the specified component type.

Type Parameters:
T - settings processor type
Parameters:
componentType - component type
settingsProcessor - settings processor class

findSuitableSettingsProcessor

protected static java.lang.Class findSuitableSettingsProcessor(java.lang.Class componentType)
Returns settings processor class for the specified component type.

Parameters:
componentType - component type
Returns:
settings processor class for the specified component type

createSettingsProcessor

protected static SettingsProcessor createSettingsProcessor(SettingsProcessorData data)
Returns new SettingsProcessor instance for the specified SettingsProcessorData.

Parameters:
data - SettingsProcessorData
Returns:
new SettingsProcessor instance for the specified SettingsProcessorData

registerComponent

public static void registerComponent(SettingsProcessorData data)
Registers component using the specified SettingsProcessorData. Any old SettingsProcessor for that component will be unregistered if operation is successful.

Parameters:
data - SettingsProcessorData

registerComponent

public static void registerComponent(javax.swing.JComponent component,
                                     SettingsProcessor settingsProcessor)
Registers component using the specified SettingsProcessor. Any old SettingsProcessor for that component will be unregistered if operation is successful.

Parameters:
component - component to register
settingsProcessor - component settings processor

loadSettings

public static void loadSettings(javax.swing.JComponent component)
Loads saved settings into the component if it is registered.

Parameters:
component - component registered for settings auto-save

saveSettings

public static void saveSettings()
Saves all registered components settings.


saveSettings

public static void saveSettings(javax.swing.JComponent component)
Saves component settings.

Parameters:
component - component registered for settings auto-save

unregisterComponent

public static void unregisterComponent(javax.swing.JComponent component)
Unregisters component from settings auto-save.

Parameters:
component - component to unregister