public abstract class FileConfigController
extends java.lang.Object
implements java.awt.event.WindowListener, javax.swing.event.DocumentListener, java.awt.event.ActionListener, java.awt.event.FocusListener
This is the base class of controllers for file-based config windows.
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<java.lang.String,java.lang.Class<?>> |
configClasses |
protected java.util.HashSet<java.lang.String> |
configKeys |
protected java.util.HashMap<java.lang.String,javax.swing.JComponent> |
configWidgets |
protected ConfigIcon |
icon |
protected java.util.HashMap<java.lang.String,java.lang.String> |
sessionConfig |
protected FileConfigView |
view |
Modifier | Constructor and Description |
---|---|
protected |
FileConfigController(FileConfigView view,
ConfigIcon icon)
Creates a file config controller.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e) |
protected boolean |
applyConfig()
Copies each correct config value to the session config.
|
protected boolean |
applyConfigById(java.lang.String id)
Copies the given config key’s value to the session config, if the value is correct.
|
void |
changedUpdate(javax.swing.event.DocumentEvent e) |
protected abstract void |
createDefaultView()
Creates a default view that is not intended to be used as a real window.
|
void |
focusGained(java.awt.event.FocusEvent e) |
void |
focusLost(java.awt.event.FocusEvent e) |
protected abstract java.util.HashMap<java.lang.String,java.lang.String> |
getDefaultConfig()
Returns the hard-coded default config.
|
private java.lang.String |
getSavedConfigValue(java.lang.String id)
Returns the saved config value of the given config ID.
|
java.util.HashMap<java.lang.String,java.lang.String> |
getSessionConfig()
Returns the session config.
|
protected void |
handleDocumentChange(javax.swing.event.DocumentEvent e)
Adjusts the background color of fields that are not directly related to a config variable, if overridden accordingly.
|
protected void |
init(FileConfigView view,
ConfigIcon icon)
Initializes the controller.
|
protected void |
initSessionConfig(boolean fromConfig)
Initializes the session config and the state of the widgets.
|
protected abstract void |
initSessionConfigSpecific(boolean fromConfig)
Initializes the specific part of the session config.
|
protected void |
initWidgetConfig(java.lang.String id,
javax.swing.JComponent widget,
java.lang.Class<?> type,
boolean fromConfig)
Initializes data structures for one config element.
|
void |
insertUpdate(javax.swing.event.DocumentEvent e) |
void |
removeUpdate(javax.swing.event.DocumentEvent e) |
private void |
restoreDefaultConfig(java.lang.String id,
java.lang.String value,
javax.swing.JComponent widget)
Restores the session config with the according default value.
|
private void |
restoreDefaultSettings()
Applies the (hard-coded) default settings to the session config and the widgets.
|
private void |
saveSettings()
Saves the session config to the config file.
|
private void |
setWidget(javax.swing.JComponent widget,
java.lang.String valueStr)
Sets the given widget to the given value.
|
void |
windowActivated(java.awt.event.WindowEvent e) |
void |
windowClosed(java.awt.event.WindowEvent e) |
void |
windowClosing(java.awt.event.WindowEvent e) |
void |
windowDeactivated(java.awt.event.WindowEvent e) |
void |
windowDeiconified(java.awt.event.WindowEvent e) |
void |
windowIconified(java.awt.event.WindowEvent e) |
void |
windowOpened(java.awt.event.WindowEvent e) |
protected ConfigIcon icon
protected FileConfigView view
protected java.util.HashSet<java.lang.String> configKeys
protected java.util.HashMap<java.lang.String,java.lang.Class<?>> configClasses
protected java.util.HashMap<java.lang.String,java.lang.String> sessionConfig
protected java.util.HashMap<java.lang.String,javax.swing.JComponent> configWidgets
protected FileConfigController(FileConfigView view, ConfigIcon icon)
Creates a file config controller.
view
- the window to be controlledicon
- the icon that is used to open the config windowpublic java.util.HashMap<java.lang.String,java.lang.String> getSessionConfig()
Returns the session config.
protected abstract void createDefaultView()
Creates a default view that is not intended to be used as a real window. This is used to initialize data structures, if the user does not want to config window is.
protected void init(FileConfigView view, ConfigIcon icon)
Initializes the controller.
Connects view and icon with the controller, if not yet done. Initializes the session config, if not yet done. Connects the session config to the widgets.
view
- the window to be controlledicon
- the icon that is used to open the config windowpublic void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
public void focusGained(java.awt.event.FocusEvent e)
focusGained
in interface java.awt.event.FocusListener
public void focusLost(java.awt.event.FocusEvent e)
focusLost
in interface java.awt.event.FocusListener
public void changedUpdate(javax.swing.event.DocumentEvent e)
changedUpdate
in interface javax.swing.event.DocumentListener
public void insertUpdate(javax.swing.event.DocumentEvent e)
insertUpdate
in interface javax.swing.event.DocumentListener
public void removeUpdate(javax.swing.event.DocumentEvent e)
removeUpdate
in interface javax.swing.event.DocumentListener
public void windowActivated(java.awt.event.WindowEvent e)
windowActivated
in interface java.awt.event.WindowListener
public void windowClosed(java.awt.event.WindowEvent e)
windowClosed
in interface java.awt.event.WindowListener
public void windowClosing(java.awt.event.WindowEvent e)
windowClosing
in interface java.awt.event.WindowListener
public void windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated
in interface java.awt.event.WindowListener
public void windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified
in interface java.awt.event.WindowListener
public void windowIconified(java.awt.event.WindowEvent e)
windowIconified
in interface java.awt.event.WindowListener
public void windowOpened(java.awt.event.WindowEvent e)
windowOpened
in interface java.awt.event.WindowListener
protected void initSessionConfig(boolean fromConfig)
Initializes the session config and the state of the widgets.
If the parameter fromConfig is true, the config is copied from Config
to the session config. Otherwise the session config is left unchanged.
fromConfig
- true if the session config shall be copied from the Config
class.protected abstract void initSessionConfigSpecific(boolean fromConfig)
Initializes the specific part of the session config.
fromConfig
- true if the session config shall be copied from the Config
class.protected void initWidgetConfig(java.lang.String id, javax.swing.JComponent widget, java.lang.Class<?> type, boolean fromConfig)
Initializes data structures for one config element.
id
- the config IDwidget
- the according widgettype
- the class of the config variablefromConfig
- true, if the session config shall be overwritten with the saved config valueprotected abstract java.util.HashMap<java.lang.String,java.lang.String> getDefaultConfig()
Returns the hard-coded default config.
protected boolean applyConfig()
Copies each correct config value to the session config.
Checks each config value first. Depending on the check result: Adjusts each incorrect widget accordingly (background of text fields etc.).
Adjusts the icon to open the config window accordingly:
protected boolean applyConfigById(java.lang.String id)
Copies the given config key’s value to the session config, if the value is correct.
Adjusts the widget according to the correctness (background of text fields etc.).
id
- config IDprotected void handleDocumentChange(javax.swing.event.DocumentEvent e)
Adjusts the background color of fields that are not directly related to a config variable, if overridden accordingly.
Does nothing by default. Per default, this is called by all kinds of document change event.
e
- document eventprivate void saveSettings()
Saves the session config to the config file.
private void restoreDefaultSettings()
Applies the (hard-coded) default settings to the session config and the widgets.
private void restoreDefaultConfig(java.lang.String id, java.lang.String value, javax.swing.JComponent widget)
Restores the session config with the according default value.
id
- config IDvalue
- config valuewidget
- the according widgetprivate void setWidget(javax.swing.JComponent widget, java.lang.String valueStr)
Sets the given widget to the given value.
widget
- the widget to be adjustedvalueStr
- the valueprivate java.lang.String getSavedConfigValue(java.lang.String id)
Returns the saved config value of the given config ID. If the saved config value is not valid, the default config value is used instead.
id
- the config ID