public class DecompileConfigController
extends java.lang.Object
implements java.awt.event.WindowListener, javax.swing.event.DocumentListener, java.awt.event.ActionListener, java.awt.event.FocusListener
Controller for the decompile config window.
Modifier and Type | Field and Description |
---|---|
private static java.util.HashMap<java.lang.String,java.lang.Class<?>> |
configClasses |
private static java.util.HashSet<java.lang.String> |
configKeys |
private static java.util.HashMap<java.lang.String,javax.swing.JComponent> |
configWidgets |
private static java.util.TreeSet<java.lang.Long> |
extraGlobalTicks |
(package private) DecompileConfigIcon |
icon |
private static java.util.HashMap<java.lang.String,java.lang.String> |
sessionConfig |
(package private) DecompileConfigView |
view |
Constructor and Description |
---|
DecompileConfigController(DecompileConfigView view,
DecompileConfigIcon icon)
Creates a controller for the decompile config window.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e) |
private boolean |
applyConfig()
Copies each correct config value to the session config.
|
private 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) |
void |
focusGained(java.awt.event.FocusEvent e) |
void |
focusLost(java.awt.event.FocusEvent e) |
static javax.swing.DefaultComboBoxModel<NamedInteger> |
getComboboxModel(java.lang.String id)
Returns the model for a combobox.
|
static java.util.TreeSet<java.lang.Long> |
getExtraGlobalTicks()
Returns the ticks for extra global commands.
|
private java.util.TreeSet<java.lang.Long> |
getExtraTicksFromTxtArea()
Converts the comma-separated extra ticks from the text area into a data structure.
|
private static NamedInteger |
getMaxNoteLengthCbxModelElement(int ticks,
java.lang.String lengthName)
Creates a numbered integer that can be put into the combobox model for the max note length combobox.
|
private static java.lang.String |
getSavedConfigValue(java.lang.String id)
Returns the saved config value of the given decompile config ID.
|
static java.util.HashMap<java.lang.String,java.lang.String> |
getSessionConfig()
Returns the session config.
|
private void |
handleDocumentChange(javax.swing.event.DocumentEvent e)
Adjusts the background color of fields that are not directly related to a config variable.
|
private void |
initSessionConfig(boolean fromConfig)
Initializes the session config and the state of the widgets.
|
private void |
initWidgetConfig(java.lang.String id,
javax.swing.JComponent widget,
java.lang.Class<?> type,
boolean fromConfig)
Initializes data structures for one decompile config element.
|
void |
insertUpdate(javax.swing.event.DocumentEvent e) |
private void |
refillExtraGlobalField()
(Re)fills the text area with ticks for extra global commands.
|
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 |
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) |
DecompileConfigView view
DecompileConfigIcon icon
private static java.util.HashSet<java.lang.String> configKeys
private static java.util.HashMap<java.lang.String,java.lang.Class<?>> configClasses
private static java.util.HashMap<java.lang.String,java.lang.String> sessionConfig
private static java.util.HashMap<java.lang.String,javax.swing.JComponent> configWidgets
private static java.util.TreeSet<java.lang.Long> extraGlobalTicks
public DecompileConfigController(DecompileConfigView view, DecompileConfigIcon icon)
Creates a controller for the decompile config window.
view
- the window to be controlledpublic static java.util.HashMap<java.lang.String,java.lang.String> getSessionConfig()
Returns the session config.
public static java.util.TreeSet<java.lang.Long> getExtraGlobalTicks()
Returns the ticks for extra global commands.
private 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.private void initWidgetConfig(java.lang.String id, javax.swing.JComponent widget, java.lang.Class<?> type, boolean fromConfig)
Initializes data structures for one decompile 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 valueprivate 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 valuepublic 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 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
private void refillExtraGlobalField()
(Re)fills the text area with ticks for extra global commands. Makes the according config variable ready to be saved.
private boolean applyConfig()
Copies each correct config value to the session config.
Checks each config value first. Depending on the check value: Adjusts each incorrect widget accordingly (background of text fields etc.).
Adjusts the icon to open the config window accordingly:
private 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 IDprivate java.util.TreeSet<java.lang.Long> getExtraTicksFromTxtArea() throws java.lang.NumberFormatException
Converts the comma-separated extra ticks from the text area into a data structure.
java.lang.NumberFormatException
- if there are errors in the text string.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
private void handleDocumentChange(javax.swing.event.DocumentEvent e)
Adjusts the background color of fields that are not directly related to a config variable.
e
- document eventpublic static javax.swing.DefaultComboBoxModel<NamedInteger> getComboboxModel(java.lang.String id)
Returns the model for a combobox.
id
- config ID, identifying the config variable that the combobox controlsprivate static NamedInteger getMaxNoteLengthCbxModelElement(int ticks, java.lang.String lengthName)
Creates a numbered integer that can be put into the combobox model for the max note length combobox.
ticks
- note length in ticks of the target resolution (480 PPQ)lengthName
- note length name or descriptionprivate static java.lang.String getSavedConfigValue(java.lang.String id)
Returns the saved config value of the given decompile config ID. If the saved config value is not valid, the default config value is used instead.
id
- the config ID