public class InfoController
extends java.lang.Object
implements java.awt.event.WindowListener, java.awt.event.ActionListener, javax.swing.event.TreeSelectionListener, javax.swing.event.ListSelectionListener, java.awt.event.ItemListener, javax.swing.event.DocumentListener, java.awt.event.FocusListener, javax.swing.event.RowSorterListener
Controller for the info window. Acts as a listener to events that occur in the info window.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CMD_ADD_KEY_BINDING |
static java.lang.String |
CMD_COLLAPSE |
static java.lang.String |
CMD_EXPAND |
static java.lang.String |
CMD_REMOVE_KEY_BINDING |
static java.lang.String |
CMD_RESET_KEY_BINDING_GLOB |
static java.lang.String |
CMD_RESET_KEY_BINDING_ID |
static java.lang.String |
NAME_KB_FILTER |
static java.lang.String |
NAME_TREE_BANKS_PER_CHANNEL |
static java.lang.String |
NAME_TREE_BANKS_TOTAL |
static java.lang.String |
NAME_TREE_KEYBINDINGS |
static java.lang.String |
NAME_TREE_MESSAGES |
private KeyBinding |
pressedKeyBinding |
private java.lang.String |
selectedKeyBindingId |
private MidicaTreeModel |
tmBanksPerChannel |
private MidicaTreeModel |
tmBanksTotal |
private MidicaTreeModel |
tmKeyBindings |
private MidicaTreeModel |
tmMessages |
private InfoView |
view |
Constructor and Description |
---|
InfoController(InfoView view)
Creates a new instance of the controller for the given info view.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Handles all button clicks from the info view window.
|
void |
changedUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
|
private boolean |
checkTextFields(javax.swing.event.DocumentEvent e)
Checks if the content of the text fields (from-ticks, to/ticks, tracks) is ok.
|
private long |
checkTickTextField(javax.swing.text.Document doc,
long maxTicks)
Checks one of the tick text fields (to or from).
|
private javax.swing.event.DocumentEvent |
createFakeTxtFieldChange()
Creates a faked document change event in order to simulate a text field change.
|
java.awt.event.KeyAdapter |
createKeyListener(javax.swing.JTextField field)
Creates and returns a key listener to handle the detection of a new key binding that’s pressed while the key binding form text field is focused.
|
private void |
displayDetailsIfPossible(boolean fromTree)
Shows the message details from the selected tree node or table row in the details area.
|
private void |
displayKeyBindingDetailsIfPossible(MidicaTree tree)
Shows the key bindings, configured for the currently selected ID in the tree.
|
private void |
filterKeyBindingTree()
Filters the tree according to the text from the tree filter field.
|
private void |
filterMessages()
Applies the message filter.
|
void |
focusGained(java.awt.event.FocusEvent e)
Handles focus events of the message table and the message tree.
|
void |
focusLost(java.awt.event.FocusEvent e) |
MidicaTreeModel |
getKeyBindingTreeModel()
Creates the key binding tree model, if not yet done, and returns it.
|
private java.util.HashMap<java.lang.String,javax.swing.JComponent> |
getMsgFilterWidgetsIfReady()
Checks and returns the message filter widgets.
|
private SingleMessage |
getSelectedMessage()
Returns the currently selected message from the message table or null, if no message is selected.
|
private int |
getTrackNum(java.lang.String str,
int maxTrack)
Converts the given string into a number and checks if it’s a valid track number.
|
private java.util.HashSet<java.lang.Integer> |
getTracksFromTextField(javax.swing.text.Document doc)
Gets, checks and returns the tracks from the text field.
|
private void |
handleTextFieldChange(javax.swing.event.DocumentEvent e)
Handles text field change events.
|
void |
insertUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
|
void |
itemStateChanged(java.awt.event.ItemEvent e)
Handles checkbox events from message filter checkboxes.
|
void |
removeUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
|
void |
setTreeModel(MidicaTreeModel treeModel,
java.lang.String name)
Receives the specified tree model so that it’s tree can be collapsed/expanded later.
|
private void |
showInTree()
Shows the selected message from the table in the tree.
|
void |
sorterChanged(javax.swing.event.RowSorterEvent e) |
private void |
updateKeyBindingTree()
Recreates the key binding tree model, reconnects it with the tree and selects the previously selected nodes.
|
private void |
updateShowInTreeButtonActivity()
Activates or deactivates the show-in-tree button in the message filter.
|
private void |
updateVisibleTotalLabels()
Updates the labels for visible and total messages.
|
void |
valueChanged(javax.swing.event.ListSelectionEvent event)
Handles selection changes in the message table.
|
void |
valueChanged(javax.swing.event.TreeSelectionEvent e)
Handles selection changes in the message or key binding tree.
|
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)
Fills the labels for visible and total messages.
|
public static final java.lang.String CMD_COLLAPSE
public static final java.lang.String CMD_EXPAND
public static final java.lang.String CMD_ADD_KEY_BINDING
public static final java.lang.String CMD_REMOVE_KEY_BINDING
public static final java.lang.String CMD_RESET_KEY_BINDING_ID
public static final java.lang.String CMD_RESET_KEY_BINDING_GLOB
public static final java.lang.String NAME_TREE_BANKS_TOTAL
public static final java.lang.String NAME_TREE_BANKS_PER_CHANNEL
public static final java.lang.String NAME_TREE_MESSAGES
public static final java.lang.String NAME_TREE_KEYBINDINGS
public static final java.lang.String NAME_KB_FILTER
private InfoView view
private MidicaTreeModel tmBanksTotal
private MidicaTreeModel tmBanksPerChannel
private MidicaTreeModel tmMessages
private MidicaTreeModel tmKeyBindings
private java.lang.String selectedKeyBindingId
private KeyBinding pressedKeyBinding
public InfoController(InfoView view)
Creates a new instance of the controller for the given info view. This is called during the initialization of the info view.
view
- info view to which the controller is connected.public void setTreeModel(MidicaTreeModel treeModel, java.lang.String name)
Receives the specified tree model so that it’s tree can be collapsed/expanded later.
treeModel
- The tree model to be set.name
- The name associated with this tree.public MidicaTreeModel getKeyBindingTreeModel()
Creates the key binding tree model, if not yet done, and returns it.
public void actionPerformed(java.awt.event.ActionEvent e)
Handles all button clicks from the info view window.
Those are:
actionPerformed
in interface java.awt.event.ActionListener
e
- The invoked action event.public void valueChanged(javax.swing.event.TreeSelectionEvent e)
Handles selection changes in the message or key binding tree.
Message tree
The details area is only filled if exactly one node is selected and this is a leaf node. In all other cases it will just be emptied.
Key binding tree
valueChanged
in interface javax.swing.event.TreeSelectionListener
e
- The event to be handled.public void valueChanged(javax.swing.event.ListSelectionEvent event)
Handles selection changes in the message table.
If a row (message) is selected now:
Otherwise:
At the end: activates or deactivates the button to show the message type in the tree. This depends also on the auto-show checkbox.
valueChanged
in interface javax.swing.event.ListSelectionListener
event
- Table row selection event.public void itemStateChanged(java.awt.event.ItemEvent e)
Handles checkbox events from message filter checkboxes.
If the limit-ticks checkbox has been changed:
If the limit-tracks checkbox has been changed:
If the channel-dependent-messages checkbox has been changed:
If one of the channel checkboxes has been changed:
At the end: applies the filter according to the changes.
If the auto-show checkbox has been changed, no special action is necessary. The filter will be re-applied, and filterMessages()
will re-select the previously selected message, if possible. That will fire a ListSelectionEvent
. This event is handled by valueChanged(ListSelectionEvent)
, where the button activity is updated and showInTree()
is called if needed. So we don’t need to do that here.
itemStateChanged
in interface java.awt.event.ItemListener
e
- Event object.public void changedUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
changedUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.public void insertUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
insertUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.public void removeUpdate(javax.swing.event.DocumentEvent e)
Handles text field changes.
removeUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.public void focusGained(java.awt.event.FocusEvent e)
Handles focus events of the message table and the message tree.
If one of these items gets the focus, this method tries to fill the details area with the selected content of that item.
focusGained
in interface java.awt.event.FocusListener
e
- Event object.public void focusLost(java.awt.event.FocusEvent e)
focusLost
in interface java.awt.event.FocusListener
public void sorterChanged(javax.swing.event.RowSorterEvent e)
sorterChanged
in interface javax.swing.event.RowSorterListener
public java.awt.event.KeyAdapter createKeyListener(javax.swing.JTextField field)
Creates and returns a key listener to handle the detection of a new key binding that’s pressed while the key binding form text field is focused.
field
- the text field that must be focused to receive a new key bindingprivate void displayDetailsIfPossible(boolean fromTree)
Shows the message details from the selected tree node or table row in the details area.
In the following cases this method has no effect:
fromTree
- true to display the details from a tree node; false to display the details from a table rowprivate void displayKeyBindingDetailsIfPossible(MidicaTree tree)
Shows the key bindings, configured for the currently selected ID in the tree. This is done only if exactly one leaf node is currently selected.
tree
- the key binding treeprivate void handleTextFieldChange(javax.swing.event.DocumentEvent e)
Handles text field change events.
The text field causing the event can be one of the following:
In the first case the tree is filtered. In the second case, the text field contents are checked (by calling checkTextFields(DocumentEvent)
).
e
- Event object.private void filterKeyBindingTree()
Filters the tree according to the text from the tree filter field. Only filters leaf nodes but no categories. Categories or the root node are colored in gray, if they don’t contain any matching leaf nodes.
The filter is checked against the action description and all associated key binding descriptions.
Example: To look for the action to close error message windows, you can filter for one of the following strings:
private void updateKeyBindingTree()
Recreates the key binding tree model, reconnects it with the tree and selects the previously selected nodes.
This is called when the key bindings have been changed.
private boolean checkTextFields(javax.swing.event.DocumentEvent e)
Checks if the content of the text fields (from-ticks, to/ticks, tracks) is ok. Checks the tick fields only if the limit-ticks checkbox is checked. Checks the tracks text field only if the limit-tracks checkbox is checked.
The text of the from/to tick fields is checked against the expected number format and range.
The track text field is checked against the expected comma- and/or minus separated track number format and the ranges of all contained edge values.
If the check fails for a text field, the background of that field is colored in red, otherwise in white.
If the from-ticks and to-ticks numbers are both ok, but the “from” number is higher than the “to” number, both fields are colored in red.
If the event comes from one of the text fields and it’s content is ok, the according field is colored in green.
e
- Event object.private long checkTickTextField(javax.swing.text.Document doc, long maxTicks)
Checks one of the tick text fields (to or from).
doc
- Document of the text field to check.maxTicks
- Number of ticks in the currently loaded MIDI sequence.private java.util.HashSet<java.lang.Integer> getTracksFromTextField(javax.swing.text.Document doc)
Gets, checks and returns the tracks from the text field.
doc
- Document of the text field to check.private int getTrackNum(java.lang.String str, int maxTrack) throws java.lang.NumberFormatException
Converts the given string into a number and checks if it’s a valid track number.
str
- String to convert.maxTrack
- Maximum track number.java.lang.NumberFormatException
- if the string cannot be converted into an integer or the check fails.private SingleMessage getSelectedMessage()
Returns the currently selected message from the message table or null, if no message is selected.
private void updateShowInTreeButtonActivity()
Activates or deactivates the show-in-tree button in the message filter.
The button is activated if:
Otherwise the button is deactivated
private void updateVisibleTotalLabels()
Updates the labels for visible and total messages.
private void filterMessages()
Applies the message filter.
Creates data structures from the filter widgets. Uses these structures as parameters for the filter function of the table model.
If a message is currently selected and still visible after the selection: - re-selects that message - scrolls to that message
private void showInTree()
Shows the selected message from the table in the tree. If no message is selected, this method has no effect.
private java.util.HashMap<java.lang.String,javax.swing.JComponent> getMsgFilterWidgetsIfReady()
Checks and returns the message filter widgets.
Returns the filter widgets only if all widgets in the view are ready. Otherwise, null is returned.
This is useful for listeners in order to avoid null pointer exceptions.
The widgets are made ready in the same order they are added to the view. Therefore it’s sufficient to check against the last widget. In the moment that’s the message table, but that may change in the future.
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)
Fills the labels for visible and total messages.
windowOpened
in interface java.awt.event.WindowListener
private javax.swing.event.DocumentEvent createFakeTxtFieldChange()
Creates a faked document change event in order to simulate a text field change. That’s necessary in order to call the check method so that the fields can be colored in red if their content is invalid.