CanScan
Loading...
Searching...
No Matches
fr.softsf.canscan.service.GenerateAndSaveService Class Reference

Service dedicated to QR code generation and saving. More...

+ Collaboration diagram for fr.softsf.canscan.service.GenerateAndSaveService:

Public Member Functions

 GenerateAndSaveService (EncodedImage encodedImage)
 Constructs a GenerateAndSaveService with the given QR code image generator.
 
void generateAndSave (EncodedData qrData, CommonFields config, JProgressBar loader)
 Generates and saves a QR code as a PNG file using the provided data and configuration.
 

Package Functions

File getSelectedFileForTests (JFileChooser chooser)
 Returns the selected PNG file for testing.
 
File resolveFileNameConflictForTests (File file)
 Resolves file name conflicts for testing.
 

Private Member Functions

boolean checkNPEInputs (EncodedData qrData, CommonFields config, JProgressBar loader)
 Validates that all required inputs are non-null.
 
File chooseOutputFile (EncodedData qrData)
 Opens a JFileChooser to select the output PNG file and handles file name conflicts.
 
void executeQrGeneration (EncodedData qrData, CommonFields config, JProgressBar loader, File outputFile)
 Executes QR code generation asynchronously using a SwingWorker.
 
File getSelectedPngFile (JFileChooser chooser)
 Ensures the selected file has a ".png" extension.
 
File resolveFileNameConflict (File file)
 Resolves potential file name conflicts by checking if the specified file already exists.
 

Private Attributes

final EncodedImage encodedImage
 

Detailed Description

Service dedicated to QR code generation and saving.

Constructor & Destructor Documentation

◆ GenerateAndSaveService()

fr.softsf.canscan.service.GenerateAndSaveService.GenerateAndSaveService ( EncodedImage encodedImage)

Constructs a GenerateAndSaveService with the given QR code image generator.

Parameters
encodedImagethe QR code image generator; must not be null

Member Function Documentation

◆ checkNPEInputs()

boolean fr.softsf.canscan.service.GenerateAndSaveService.checkNPEInputs ( EncodedData qrData,
CommonFields config,
JProgressBar loader )
private

Validates that all required inputs are non-null.

Parameters
qrDatathe QR code data to validate
configthe configuration to validate
loaderthe progress bar to validate
Returns
true if all inputs are valid, false otherwise

◆ chooseOutputFile()

File fr.softsf.canscan.service.GenerateAndSaveService.chooseOutputFile ( EncodedData qrData)
private

Opens a JFileChooser to select the output PNG file and handles file name conflicts.

Parameters
qrDatathe QR code data used to generate the default file name
Returns
the selected file ready for writing, or null if the user cancels
+ Here is the call graph for this function:

◆ executeQrGeneration()

void fr.softsf.canscan.service.GenerateAndSaveService.executeQrGeneration ( EncodedData qrData,
CommonFields config,
JProgressBar loader,
File outputFile )
private

Executes QR code generation asynchronously using a SwingWorker.

Parameters
qrDatathe QR code data
configthe visual configuration
loaderthe progress bar to hide after completion
outputFilethe file where the QR code will be saved

◆ generateAndSave()

void fr.softsf.canscan.service.GenerateAndSaveService.generateAndSave ( EncodedData qrData,
CommonFields config,
JProgressBar loader )

Generates and saves a QR code as a PNG file using the provided data and configuration.

Validates input data, applies visual settings, generates the QR code image, and saves it to a user-selected file location. All operations are performed asynchronously to prevent UI blocking.

Parameters
qrDatathe QR code data; must not be null
configthe visual configuration; must not be null
loaderthe progress indicator to display during generation
+ Here is the call graph for this function:

◆ getSelectedFileForTests()

File fr.softsf.canscan.service.GenerateAndSaveService.getSelectedFileForTests ( JFileChooser chooser)
package

Returns the selected PNG file for testing.

+ Here is the call graph for this function:

◆ getSelectedPngFile()

File fr.softsf.canscan.service.GenerateAndSaveService.getSelectedPngFile ( JFileChooser chooser)
private

Ensures the selected file has a ".png" extension.

Parameters
chooserthe file chooser
Returns
a File guaranteed to have a ".png" extension

◆ resolveFileNameConflict()

File fr.softsf.canscan.service.GenerateAndSaveService.resolveFileNameConflict ( File file)
private

Resolves potential file name conflicts by checking if the specified file already exists.

If the file exists, the user is prompted to overwrite it. If the user declines, a new file name is generated by appending a numeric suffix to avoid overwriting existing files.

Parameters
filethe initial File to check for conflicts
Returns
a File ready for writing, either the original, user-approved, or auto-renamed, or null if input file is null

◆ resolveFileNameConflictForTests()

File fr.softsf.canscan.service.GenerateAndSaveService.resolveFileNameConflictForTests ( File file)
package

Resolves file name conflicts for testing.

+ Here is the call graph for this function:

Member Data Documentation

◆ encodedImage

final EncodedImage fr.softsf.canscan.service.GenerateAndSaveService.encodedImage
private

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