SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.ui.FileChooserService Class Reference

A Spring service that provides a reusable and type-safe file chooser utility for selecting different kinds of files (e.g., images, audio). More...

+ Collaboration diagram for fr.softsf.sudokufx.service.ui.FileChooserService:

Classes

enum  FileType
 Supported file types for the file chooser. More...
 

Public Member Functions

Optional< File > chooseFile (@Nullable Stage ownerStage, FileType type)
 Opens a FileChooser dialog for the specified file type.
 

Private Member Functions

FileChooser.ExtensionFilter getFilter (FileType type)
 Returns the appropriate FileChooser.ExtensionFilter for the given file type.
 

Static Private Attributes

static final Logger LOG = LoggerFactory.getLogger(FileChooserService.class)
 

Detailed Description

A Spring service that provides a reusable and type-safe file chooser utility for selecting different kinds of files (e.g., images, audio).

The service handles:

  • Configuring extension filters based on file type
  • Setting an initial directory (user home by default)
  • Gracefully handling errors and returning Optional.empty() if cancelled or failed

Member Function Documentation

◆ chooseFile()

Optional< File > fr.softsf.sudokufx.service.ui.FileChooserService.chooseFile ( @Nullable Stage ownerStage,
FileType type )

Opens a FileChooser dialog for the specified file type.

If the user selects a valid file, it is returned wrapped in an Optional. If the user cancels or an error occurs, Optional#empty() is returned.

Parameters
ownerStagethe parent Stage for the dialog; can be null, in which case the method returns Optional.empty()
typethe type of file to choose (IMAGE or AUDIO); must not be null
Returns
an Optional containing the selected file, or empty if cancelled or failed
Exceptions
NullPointerExceptionif type is null
+ Here is the call graph for this function:

◆ getFilter()

FileChooser.ExtensionFilter fr.softsf.sudokufx.service.ui.FileChooserService.getFilter ( FileType type)
private

Returns the appropriate FileChooser.ExtensionFilter for the given file type.

Parameters
typethe file type (IMAGE or AUDIO); must not be null
Returns
a FileChooser.ExtensionFilter restricting files to the allowed extensions
Exceptions
NullPointerExceptionif type is null

Member Data Documentation

◆ LOG

final Logger fr.softsf.sudokufx.service.ui.FileChooserService.LOG = LoggerFactory.getLogger(FileChooserService.class)
staticprivate

The documentation for this class was generated from the following file: