public class UiController
extends java.lang.Object
implements java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.event.ItemListener
This class provides the controller of the main window.
It listens and reacts to events in the UiView
.
Modifier and Type | Field and Description |
---|---|
private AbcImporter |
abcImporter |
private AldaImporter |
aldaImporter |
static java.lang.String |
CMD_CANCELED |
static java.lang.String |
CMD_COMBOBOX_CHANGED |
static java.lang.String |
CMD_FILE_CHOSEN |
private java.io.File |
currentFile |
private java.lang.String |
currentFilePurpose |
private java.lang.String |
currentFileType |
private FileSelector |
exportSelector |
static java.lang.String |
FILE_PURPOSE_EXPORT |
static java.lang.String |
FILE_PURPOSE_PARSE |
private FileSelector |
importSelector |
private LilypondImporter |
lyImporter |
private MidiParser |
midiParser |
private MidicaPLParser |
mplParser |
private MusescoreImporter |
mscoreImporter |
private PlayerView |
player |
private SoundbankParser |
soundbankParser |
private FileSelector |
soundbankSelector |
private UiView |
view |
Constructor and Description |
---|
UiController()
Sets up the UI of the main window by initializing the
UiView and the parser classes. |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
This method processes all action events in the
UiView . |
private void |
configurationChanged(java.lang.String name,
java.lang.String selectedId)
Applies configuration changes.
|
private void |
displayFilename(java.lang.String type,
java.lang.String filename)
Displays the parsed sequence or soundbank file name.
|
void |
exportChosenFile(java.lang.String type,
java.io.File file)
Exports to the chosen file using the right exporter for this file type.
|
UiView |
getView()
Returns the view of the main window.
|
private void |
initSelectorsIfNotYetDone()
Initializes all possible types of
FileSelector s. |
private void |
initView()
Initializes the main window by creating the
UiView object and all possible types of FileSelector s. |
void |
itemStateChanged(java.awt.event.ItemEvent e)
Handles selecting/deselecting of one of the remember checkboxes.
|
private void |
openExportFileSelector()
Checks if a MIDI sequence is set and opens the file selector to choose the file to be exported.
|
void |
parseChosenFile(java.lang.String type,
java.lang.Object fileOrUrl)
Parses the chosen file or URL using the right parser for the right file type.
|
private void |
showErrorMessage(java.lang.String message)
Opens an error message window showing the given message, if in GUI mode.
|
private void |
showExportResult(ExportResult result)
Opens an export result window showing the given export result.
|
void |
soundbankLoadedBySourceCode()
Sets the soundbank file name label after loading a soundbank by MidicaPL source code.
|
void |
updateAfterPlayerClosed()
Updates the parsed file label after the player has been closed.
|
void |
updateImportedFileTypeAndName()
Update the labels for the imported sequence file name and type, if any sequence is loaded.
|
void |
windowActivated(java.awt.event.WindowEvent e)
Initializes key bindings and refreshes the current transpose level that has been set in the player (or 0, if the transpose level has not yet been changed).
|
void |
windowClosed(java.awt.event.WindowEvent e)
Does nothing.
|
void |
windowClosing(java.awt.event.WindowEvent e)
Writes the current config to the config file, and exits.
|
void |
windowDeactivated(java.awt.event.WindowEvent e)
Does nothing.
|
void |
windowDeiconified(java.awt.event.WindowEvent e)
Does nothing.
|
void |
windowIconified(java.awt.event.WindowEvent e)
Does nothing.
|
void |
windowOpened(java.awt.event.WindowEvent e)
Checks if files must be loaded automatically, and loads them, if the check succeeds.
|
public static final java.lang.String CMD_COMBOBOX_CHANGED
public static final java.lang.String CMD_FILE_CHOSEN
public static final java.lang.String CMD_CANCELED
public static final java.lang.String FILE_PURPOSE_PARSE
public static final java.lang.String FILE_PURPOSE_EXPORT
private UiView view
private FileSelector importSelector
private FileSelector soundbankSelector
private FileSelector exportSelector
private MidicaPLParser mplParser
private MidiParser midiParser
private AldaImporter aldaImporter
private AbcImporter abcImporter
private LilypondImporter lyImporter
private MusescoreImporter mscoreImporter
private SoundbankParser soundbankParser
private PlayerView player
private java.io.File currentFile
private java.lang.String currentFileType
private java.lang.String currentFilePurpose
public UiController()
Sets up the UI of the main window by initializing the UiView
and the parser classes.
private void initView()
Initializes the main window by creating the UiView
object and all possible types of FileSelector
s.
This method is also called after changing the language in order to re-draw everything.
private void initSelectorsIfNotYetDone()
Initializes all possible types of FileSelector
s.
public UiView getView()
Returns the view of the main window.
public void soundbankLoadedBySourceCode()
Sets the soundbank file name label after loading a soundbank by MidicaPL source code.
public void actionPerformed(java.awt.event.ActionEvent e)
This method processes all action events in the UiView
.
actionPerformed
in interface java.awt.event.ActionListener
e
- The event to be handled.public void itemStateChanged(java.awt.event.ItemEvent e)
Handles selecting/deselecting of one of the remember checkboxes.
itemStateChanged
in interface java.awt.event.ItemListener
e
- The event to be handled.private void openExportFileSelector()
Checks if a MIDI sequence is set and opens the file selector to choose the file to be exported.
If no MIDI sequence is set, shows an error message instead of opening the file selector.
public void parseChosenFile(java.lang.String type, java.lang.Object fileOrUrl)
Parses the chosen file or URL using the right parser for the right file type. A wait dialog is shown during parsing. The parsing itself is executed by a SwingWorker
.
type
- Import type.fileOrUrl
- Selected file or URL (as string).public void updateAfterPlayerClosed()
Updates the parsed file label after the player has been closed. This is necessary because a reparse from the player could have failed. Then the label must not display the file name any more.
public void exportChosenFile(java.lang.String type, java.io.File file)
Exports to the chosen file using the right exporter for this file type.
type
- File type.file
- Selected file.private void showErrorMessage(java.lang.String message)
Opens an error message window showing the given message, if in GUI mode. In CLI mode, prints the message to STDERR.
message
- Error message.private void showExportResult(ExportResult result)
Opens an export result window showing the given export result.
result
- Export result containing warnings and errors of a file export.public void updateImportedFileTypeAndName()
Update the labels for the imported sequence file name and type, if any sequence is loaded.
This is needed only in case of language switches to make sure that the correct files are still displayed.
private void displayFilename(java.lang.String type, java.lang.String filename)
Displays the parsed sequence or soundbank file name. In case of a sequence, also displays the file type.
type
- File type.filename
- File name.public void windowActivated(java.awt.event.WindowEvent e)
Initializes key bindings and refreshes the current transpose level that has been set in the player (or 0, if the transpose level has not yet been changed).
windowActivated
in interface java.awt.event.WindowListener
e
- Window event.public void windowClosed(java.awt.event.WindowEvent e)
Does nothing.
windowClosed
in interface java.awt.event.WindowListener
e
- Window event.public void windowClosing(java.awt.event.WindowEvent e)
Writes the current config to the config file, and exits.
windowClosing
in interface java.awt.event.WindowListener
e
- Window event.public void windowDeactivated(java.awt.event.WindowEvent e)
Does nothing.
windowDeactivated
in interface java.awt.event.WindowListener
e
- Window event.public void windowDeiconified(java.awt.event.WindowEvent e)
Does nothing.
windowDeiconified
in interface java.awt.event.WindowListener
e
- Window closed event.public void windowIconified(java.awt.event.WindowEvent e)
Does nothing.
windowIconified
in interface java.awt.event.WindowListener
e
- Window event.public void windowOpened(java.awt.event.WindowEvent e)
Checks if files must be loaded automatically, and loads them, if the check succeeds.
windowOpened
in interface java.awt.event.WindowListener
e
- Window event.private void configurationChanged(java.lang.String name, java.lang.String selectedId)
Applies configuration changes.
This method is called whenever one of the configuration comboboxes is changed.
name
- Name of the combobox that has been changed.selectedId
- ID of the selected item in the combobox.