![]() |
SudokuFX
|
ViewModel managing menu options UI state and accessibility strings. More...
Collaboration diagram for fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel:Public Member Functions | |
| MenuOptionsViewModel (AudioService audioService, AsyncFileProcessorService asyncFileProcessorService, PlayerStateHolder playerStateHolder, OptionsService optionsService, ToasterService toasterService) | |
| void | applyAndPersistBackgroundImage (File selectedFile, SpinnerGridPane spinner, GridPane sudokuFX) |
Applies a background image to the specified GridPane and persists its path in the current player's options. | |
| void | applyAndPersistOptionsColor (GridPane sudokuFX, Color color) |
Applies the given color as the background of the specified GridPane and persists it in the current player's options if it has changed. | |
| BooleanProperty | gridOpacityProperty () |
| void | init (GridPane sudokuFX, ColorPicker menuOptionsButtonColor, SpinnerGridPane spinner) |
| Initializes the menu options UI state for the current player, including: | |
| StringBinding | optionsAccessibleTextProperty () |
| StringBinding | optionsClearSongAccessibleTextProperty () |
| StringBinding | optionsClearSongRoleDescriptionProperty () |
| StringBinding | optionsClearSongTooltipProperty () |
| StringBinding | optionsColorAccessibleTextProperty () |
| StringBinding | optionsColorRoleDescriptionProperty () |
| StringBinding | optionsColorTooltipProperty () |
| StringBinding | optionsImageAccessibleTextProperty () |
| StringBinding | optionsImageRoleDescriptionProperty () |
| StringBinding | optionsImageTextProperty () |
| StringBinding | optionsImageTooltipProperty () |
| StringBinding | optionsMenuMaxiAccessibleTextProperty () |
| StringBinding | optionsMenuMaxiRoleDescriptionProperty () |
| StringBinding | optionsMenuMaxiTextProperty () |
| StringBinding | optionsMenuMaxiTooltipProperty () |
| StringBinding | optionsMuteAccessibleTextProperty () |
| StringBinding | optionsMuteIconProperty () |
| StringBinding | optionsMuteRoleDescriptionProperty () |
| StringBinding | optionsMuteTextProperty () |
| StringBinding | optionsMuteTooltipProperty () |
| StringBinding | optionsOpacityAccessibleTextProperty () |
| StringBinding | optionsOpacityIconProperty () |
| StringBinding | optionsOpacityRoleDescriptionProperty () |
| StringBinding | optionsOpacityTextProperty () |
| StringBinding | optionsOpacityTooltipProperty () |
| StringBinding | optionsReduceAccessibleTextProperty () |
| StringBinding | optionsReduceTextProperty () |
| StringBinding | optionsReduceTooltipProperty () |
| StringBinding | optionsRoleDescriptionProperty () |
| StringBinding | optionsSongAccessibleTextProperty () |
| StringBinding | optionsSongRoleDescriptionProperty () |
| StringBinding | optionsSongTextProperty () |
| StringBinding | optionsSongTooltipProperty () |
| StringBinding | optionsTextProperty () |
| StringBinding | optionsTooltipProperty () |
| void | resetSongPath () |
| Resets the song path by clearing the current selection, persisting the change, and showing a toast notification. | |
| void | saveSong (File file) |
| Saves the provided song file path to the database and shows a confirmation toast. | |
| BooleanProperty | songIsBlankProperty () |
| boolean | toggleGridOpacityAndPersist () |
Toggles the grid opacity mode, persists the new state in the database, updates , and returns the actual updated value. | |
| void | toggleMuteAndPersist () |
Toggles the audio mute state, persists the new value in OptionsDto, updates the AudioService, and reflects the change in muteProperty. | |
Static Public Attributes | |
| static final int | HEXCOLOR_BEGIN_INDEX = 2 |
| static final int | HEXCOLOR_END_INDEX = 10 |
| static final String | SUDOKU_FX_MUST_NOT_BE_NULL = "sudokuFX must not be null" |
Private Member Functions | |
| void | checkInitialized () |
Checks whether the MenuOptionsViewModel has been initialized via init(GridPane, ColorPicker, SpinnerGridPane). | |
| Observable[] | concatDependencies (Observable... dependencies) |
| Utility: always observe the locale in addition to custom dependencies. | |
| StringBinding | createFormattedAndConcatenatedBinding (Supplier< String > keySupplier, Supplier< String > argSupplier, String suffixKey, Observable... dependencies) |
| Creates a localized binding combining a formatted message and a suffix. | |
| StringBinding | createFormattedBinding (String key, String suffixKey) |
| Creates a StringBinding that returns the concatenation of two localized strings (main key and suffix key), updating automatically when the locale changes. | |
| StringBinding | createFormattedBinding (Supplier< String > keySupplier, Supplier< String > argSupplier, Observable... dependencies) |
| Creates a formatted localized binding with one dynamic argument. | |
| StringBinding | createStringBinding (String key) |
| Creates a StringBinding that returns the localized string for the given key, updating automatically when the locale changes. | |
| String | gridOpacityText (boolean isOpaque) |
| Returns the localized text corresponding to the grid opacity state. | |
| StringBinding | initMuteAccessibleText () |
| Creates the accessibility label for the mute button, based on the current mute state. | |
| StringBinding | initMuteIcon () |
| Creates the icon name for the mute button, depending on whether mute is active or not. | |
| StringBinding | initMuteText () |
| Creates the visible label for the mute button, reflecting the current mute state. | |
| StringBinding | initMuteTooltip () |
| Creates the tooltip for the mute button, combining dynamic mute info and submenu role. | |
| StringBinding | initOpacityAccessibleText () |
| Creates the accessibility label for the opacity button, based on the inverse of the current grid opacity state. | |
| StringBinding | initOpacityIcon () |
| Creates the icon name for the opacity button, depending on whether opacity is enabled or not. | |
| StringBinding | initOpacityText () |
| Creates the visible label for the opacity button, reflecting the current grid opacity value. | |
| StringBinding | initOpacityTooltip () |
| Creates the tooltip for the opacity button, combining dynamic label and submenu role. | |
| StringBinding | initSongAccessibleText () |
| Creates the accessibility label for the song button, depending on whether the song field is empty. | |
| StringBinding | initSongText () |
| Creates the visible label for the song button, adapting to whether a song is present or not. | |
| StringBinding | initSongTooltip () |
| Creates the tooltip for the song button, combining dynamic song info and submenu role. | |
| String | muteInfo (boolean isMuted) |
| Returns the localized information about the current mute state. | |
| String | muteText (boolean isMuted) |
| Returns the localized text corresponding to the mute state. | |
| void | persistImagePath (String imagePath) |
Persists the given image path in the current player's OptionsDto if it differs from the existing path, then refreshes the player. | |
| void | persistSongPath (String absolutePath, String name) |
| Persists the audio file path (songPath) in the current player's options. | |
| void | setColorFromModel (GridPane sudokuFX, ColorPicker menuOptionsButtonColor, String colorValueFromModel) |
| Sets the background color of the GridPane and updates the ColorPicker based on the color value retrieved from the model. | |
Private Attributes | |
| final AsyncFileProcessorService | asyncFileProcessorService |
| final AudioService | audioService |
| final AudioUtils | audioUtils |
| final BooleanProperty | gridOpacityProperty = new SimpleBooleanProperty(false) |
| final ImageUtils | imageUtils |
| boolean | initialized = false |
| final BooleanProperty | muteProperty = new SimpleBooleanProperty(true) |
| final StringBinding | optionsAccessibleText |
| final StringBinding | optionsClearSongAccessibleText |
| final StringBinding | optionsClearSongRoleDescription |
| final StringBinding | optionsClearSongTooltip |
| final StringBinding | optionsColorAccessibleText |
| final StringBinding | optionsColorRoleDescription |
| final StringBinding | optionsColorTooltip |
| final StringBinding | optionsImageAccessibleText |
| final StringBinding | optionsImageRoleDescription |
| final StringBinding | optionsImageText |
| final StringBinding | optionsImageTooltip |
| final StringBinding | optionsMenuMaxiAccessibleText |
| final StringBinding | optionsMenuMaxiRoleDescription |
| final StringBinding | optionsMenuMaxiText |
| final StringBinding | optionsMenuMaxiTooltip |
| final StringBinding | optionsMuteAccessibleText |
| final StringBinding | optionsMuteIcon |
| final StringBinding | optionsMuteRoleDescription |
| final StringBinding | optionsMuteText |
| final StringBinding | optionsMuteTooltip |
| final StringBinding | optionsOpacityAccessibleText |
| final StringBinding | optionsOpacityIcon |
| final StringBinding | optionsOpacityRoleDescription |
| final StringBinding | optionsOpacityText |
| final StringBinding | optionsOpacityTooltip |
| final StringBinding | optionsReduceAccessibleText |
| final StringBinding | optionsReduceText |
| final StringBinding | optionsReduceTooltip |
| final StringBinding | optionsRoleDescription |
| final OptionsService | optionsService |
| final StringBinding | optionsSongAccessibleText |
| final StringBinding | optionsSongRoleDescription |
| final StringBinding | optionsSongText |
| final StringBinding | optionsSongTooltip |
| final StringBinding | optionsText |
| final StringBinding | optionsTooltip |
| final PlayerStateHolder | playerStateHolder |
| final BooleanProperty | songIsBlankProperty = new SimpleBooleanProperty(true) |
| final SimpleStringProperty | songProperty = new SimpleStringProperty("") |
| final ToasterService | toasterService |
Static Private Attributes | |
| static final int | HEX_RADIX = 16 |
| static final String | ICON_MUTE_OFF = "\ue04f" |
| static final String | ICON_MUTE_ON = "\ue050" |
| static final String | ICON_OPACITY_OFF = "\ue0c4" |
| static final String | ICON_OPACITY_ON = "\ue891" |
| static final Logger | LOG = LoggerFactory.getLogger(MenuOptionsViewModel.class) |
| static final String | ROLE_CLOSED = "menu.accessibility.role.description.closed" |
| static final String | ROLE_OPENED = "menu.accessibility.role.description.opened" |
| static final String | ROLE_SUBMENU_OPTION |
ViewModel managing menu options UI state and accessibility strings.
Provides localized StringBindings for button labels, tooltips, and roles, updating automatically on locale changes. Supports options color and image initialization and updates, including asynchronous image loading with user feedback.
| fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.MenuOptionsViewModel | ( | AudioService | audioService, |
| AsyncFileProcessorService | asyncFileProcessorService, | ||
| PlayerStateHolder | playerStateHolder, | ||
| OptionsService | optionsService, | ||
| ToasterService | toasterService ) |
Here is the call graph for this function:| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.applyAndPersistBackgroundImage | ( | File | selectedFile, |
| SpinnerGridPane | spinner, | ||
| GridPane | sudokuFX ) |
Applies a background image to the specified GridPane and persists its path in the current player's options.
If a valid image file is provided, it is loaded, resized, and converted asynchronously via AsyncFileProcessorService, applied to the GridPane, and persisted. An info toast is shown on success.
If the file is null, invalid, or missing, no background is applied, an empty path is persisted, and an error toast is displayed.
| selectedFile | the image file to load; may be null |
| spinner | the spinner to indicate loading; must not be null |
| sudokuFX | the GridPane to update; must not be null |
| NullPointerException | if spinner or sudokuFX is null |
Here is the call graph for this function:| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.applyAndPersistOptionsColor | ( | GridPane | sudokuFX, |
| Color | color ) |
Applies the given color as the background of the specified GridPane and persists it in the current player's options if it has changed.
The color is converted to a hex string including alpha (RRGGBBAA) and stored in a copy of the current OptionsDto with an empty image path. If the color is identical to the currently persisted value, no database update occurs.
On successful persistence, the GridPane background is updated. On failure, the exception is logged and an error toast is shown to the user.
| sudokuFX | the GridPane to update; must not be null |
| color | the color to apply and persist; must not be null |
| NullPointerException | if sudokuFX or color is null |
Here is the call graph for this function:
|
private |
Checks whether the MenuOptionsViewModel has been initialized via init(GridPane, ColorPicker, SpinnerGridPane).
If the menu options have not been initialized, this method throws an exception to prevent operations on an uninitialized state.
| IllegalStateException | if init(GridPane, ColorPicker, SpinnerGridPane) has not been called |
|
private |
Utility: always observe the locale in addition to custom dependencies.
|
private |
Creates a localized binding combining a formatted message and a suffix.
Updates when locale or any of the given dependencies change.
Here is the call graph for this function:
|
private |
Creates a StringBinding that returns the concatenation of two localized strings (main key and suffix key), updating automatically when the locale changes.
| key | the main i18n translation key |
| suffixKey | the suffix i18n translation key to append |
|
private |
Creates a formatted localized binding with one dynamic argument.
Updates when locale or any of the given dependencies change.
Here is the call graph for this function:
|
private |
Creates a StringBinding that returns the localized string for the given key, updating automatically when the locale changes.
| key | the i18n translation key |
| BooleanProperty fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.gridOpacityProperty | ( | ) |
|
private |
Returns the localized text corresponding to the grid opacity state.
| isOpaque | true for "opaque" text, false for "transparent" text |
| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.init | ( | GridPane | sudokuFX, |
| ColorPicker | menuOptionsButtonColor, | ||
| SpinnerGridPane | spinner ) |
Initializes the menu options UI state for the current player, including:
This method synchronizes the UI components with the current player's options and prepares the necessary properties for bindings. The ViewModel is marked as initialized at the start of this method to allow called methods (like applyAndPersistBackgroundImage) to safely check the initialization state.
| sudokuFX | the GridPane to apply background settings; must not be null |
| menuOptionsButtonColor | the ColorPicker to synchronize with the current color; must not be null |
| spinner | the spinner component to indicate loading state; must not be null |
| NullPointerException | if any of the parameters are null |
Here is the call graph for this function:
|
private |
Creates the accessibility label for the mute button, based on the current mute state.
Here is the call graph for this function:
|
private |
Creates the icon name for the mute button, depending on whether mute is active or not.
|
private |
Creates the visible label for the mute button, reflecting the current mute state.
Here is the call graph for this function:
|
private |
Creates the tooltip for the mute button, combining dynamic mute info and submenu role.
Here is the call graph for this function:
|
private |
Creates the accessibility label for the opacity button, based on the inverse of the current grid opacity state.
Here is the call graph for this function:
|
private |
Creates the icon name for the opacity button, depending on whether opacity is enabled or not.
|
private |
Creates the visible label for the opacity button, reflecting the current grid opacity value.
Here is the call graph for this function:
|
private |
Creates the tooltip for the opacity button, combining dynamic label and submenu role.
Here is the call graph for this function:
|
private |
Creates the accessibility label for the song button, depending on whether the song field is empty.
Here is the call graph for this function:
|
private |
Creates the visible label for the song button, adapting to whether a song is present or not.
Here is the call graph for this function:
|
private |
Creates the tooltip for the song button, combining dynamic song info and submenu role.
Here is the call graph for this function:
|
private |
Returns the localized information about the current mute state.
This text is intended for tooltips or accessibility purposes, indicating whether the audio is currently muted or unmuted.
| isMuted | true if audio is currently muted, false if unmuted |
|
private |
Returns the localized text corresponding to the mute state.
| isMuted | true for "muted" audio, false for "unmuted" audio |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsClearSongAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsClearSongRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsClearSongTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsColorAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsColorRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsColorTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsImageAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsImageRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsImageTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsImageTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMenuMaxiAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMenuMaxiRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMenuMaxiTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMenuMaxiTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMuteAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMuteIconProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMuteRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMuteTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsMuteTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsOpacityAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsOpacityIconProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsOpacityRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsOpacityTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsOpacityTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsReduceAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsReduceTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsReduceTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsSongAccessibleTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsSongRoleDescriptionProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsSongTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsSongTooltipProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsTextProperty | ( | ) |
| StringBinding fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.optionsTooltipProperty | ( | ) |
|
private |
Persists the given image path in the current player's OptionsDto if it differs from the existing path, then refreshes the player.
If persisting the path succeeds, the current player is refreshed. If an exception occurs, the error is logged and an error toast is displayed to the user.
| imagePath | the image path to persist; may be empty to indicate no background image |
|
private |
Persists the audio file path (songPath) in the current player's options.
A copy of the current OptionsDto is created with the new path and persisted via OptionsService#updateOptions(OptionsDto). On success, the current player is refreshed, songProperty is updated, and an info toast is shown. On failure, the exception is logged and an error toast with details is displayed.
| absolutePath | the new audio file absolute path |
| name | the file name, used in toast messages |
| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.resetSongPath | ( | ) |
Resets the song path by clearing the current selection, persisting the change, and showing a toast notification.
Here is the call graph for this function:| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.saveSong | ( | File | file | ) |
Saves the provided song file path to the database and shows a confirmation toast.
The method validates that the file is non-null, exists, and has a supported audio format (MP3, WAV, AAC, M4A, AIF, AIFF). If valid, it updates the database and songProperty; otherwise, it logs an error and shows an error toast via ToasterVBox.
| file | the audio file to save; must not be null, must exist, and be a valid audio file |
Here is the call graph for this function:
|
private |
Sets the background color of the GridPane and updates the ColorPicker based on the color value retrieved from the model.
| sudokuFX | the GridPane to update (must not be null) |
| menuOptionsButtonColor | the ColorPicker to update (must not be null) |
| colorValueFromModel | the hex color string from the model (must not be null or blank, e.g., "99b3ffcd") |
| NullPointerException | if any parameter is null |
| IllegalArgumentException | if colorValueFromModel is blank |
| NumberFormatException | if colorValueFromModel is not a valid hex number or too large for an int |
| BooleanProperty fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.songIsBlankProperty | ( | ) |
| boolean fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.toggleGridOpacityAndPersist | ( | ) |
Toggles the grid opacity mode, persists the new state in the database, updates , and returns the actual updated value.
gridOpacityProperty
On success, an info toast indicates the new state. On failure, the exception is logged, an error toast is shown, and the property is restored to its previous value.
true if opaque mode is now active, false if transparent
Here is the call graph for this function:| void fr.softsf.sudokufx.viewmodel.MenuOptionsViewModel.toggleMuteAndPersist | ( | ) |
Toggles the audio mute state, persists the new value in OptionsDto, updates the AudioService, and reflects the change in muteProperty.
On success, a user-friendly toast indicates the new mute state. On failure, the exception is logged and an error toast with details is displayed.
Here is the call graph for this function:
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
static |
|
static |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
static |
|
private |