Package be.gaudry.model.file
Class AbstractFileParser<T>
java.lang.Object
be.gaudry.model.file.AbstractFileParser<T>
- Type Parameters:
T-
- All Implemented Interfaces:
PropertyChangeListener,EventListener
- Direct Known Subclasses:
FileChartCountParser,FileChartExtensionParser,FileChartModDateParser,FileChartSizeParser,ImagesDirectoryHighMemoryParser,ImagesDirectoryParser,MReportParser,RefreshSynchroParser,Runtastic2GpxParser,SearchFilesParser,SearchMediaParser,SimpleRenameParser,TransfertPhotosParser
An abstract class to parse files, forces to implement something to do on
files (lengthy GUI-interacting tasks) in a dedicated thread threw an
AbstractBrolWorker. \n
As a new instance of AbstractBrolWorker must be created each time we want to
perform a task, the new instance will be given to the
parse(AbstractBrolWorker) method.
\n
Provided by the broldev.core.model project.- Since:
- 1.0 Jun 10, 2008, broldev.core.model 0.0.1-SNAPSHOT dependency
- Version:
- 1.1 Feb 18, 2009
- Author:
- Steph GAUDRY
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleantrue if the maximum value has been calculated for the same kind of parsing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks equality on following points : parameter not null and parameter class equals real implementation of this classincludeHiddenincludeSubFolderspreCalcProgressstartPathSome points are not checked : The generic type (T)progressMaxprogressToDovalidPreviousProgressreadDirSizeStrprotected voidfinalize()longThe returned value is not the size of the parsed directory, but only the total size of the matched files.inthashCode()protected voidinit()Override this to do some initializations before starting the parsing, like reset errors, etc.booleanbooleanbooleanbooleanbooleanAny modification on the parsing configuration wich affects the progress percentage will set this to falselongparse(AbstractBrolWorker<T> bgw)Parses files from the definedstart path, and call theperformOnFile(AbstractBrolWorker, File, int, int)on each file.protected voidparseFiles(AbstractBrolWorker<T> bgw, File file, int subDirDeep)Does the real parsing job.protected voidperformOnDirectory(AbstractBrolWorker<T> bgw, File directory, int subDirDeep)Do something on each directory.protected abstract booleanperformOnFile(AbstractBrolWorker<T> bgw, File file, int percent, int subDirDeep)Do something on each filevoidvoidsetIncludeHiddenFiles(boolean includeHidden)True to search on the hidden files.voidsetIncludeSubFolders(boolean includeSubFolders)True to search on the sub folders.voidLocalize some strings using theLanguageHelperfeatures.voidsetPreCalcProgress(boolean preCalcProgress)voidsetStartPath(String startPath)Path of the root directory where to search Modifying this forces total size calculation if progress neededvoidEnable pause if not enabled; disable it if enabled
-
Field Details
-
validPreviousProgress
protected boolean validPreviousProgresstrue if the maximum value has been calculated for the same kind of parsing. If a parse modification is done in the child class, we need setting this to false re-calculation of maximum value.
-
-
Constructor Details
-
AbstractFileParser
public AbstractFileParser()
-
-
Method Details
-
finalize
-
init
protected void init()Override this to do some initializations before starting the parsing, like reset errors, etc. -
togglePause
public void togglePause()Enable pause if not enabled; disable it if enabled -
isPauseProcessing
public boolean isPauseProcessing()- Returns:
- true if the process is in pause mode
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
hashCode
public int hashCode()- Overrides:
hashCodein classObject- See Also:
equals(Object)
-
equals
Checks equality on following points :- parameter not null and parameter class equals real implementation of this class
includeHiddenincludeSubFolderspreCalcProgressstartPath
- The generic type (T)
progressMaxprogressToDovalidPreviousProgressreadDirSizeStr
- Overrides:
equalsin classObject- See Also:
Object.equals(java.lang.Object),hashCode()
-
parse
Parses files from the definedstart path, and call theperformOnFile(AbstractBrolWorker, File, int, int)on each file.- Parameters:
bgw-- Returns:
- the size of the matching files, not the size of the parsed directory
-
performOnFile
protected abstract boolean performOnFile(AbstractBrolWorker<T> bgw, File file, int percent, int subDirDeep)Do something on each file- Parameters:
bgw-AbstractBrolWorkerto perform cancel if needed, and report progressfile- file to checkpercent- Progress percentagesubDirDeep- Deep of the directory in comparison with start directory- Returns:
- true if we must stop the parsing of current directory (ie. if we have a vob file, we don't check the other files in this directory) false otherwise
-
performOnDirectory
Do something on each directory. Does nothing in this default implementation, but may be overrided.- Parameters:
bgw-AbstractBrolWorkerto notify progress.directory-Fileobject. No need to check if is directory (already done in the parser)subDirDeep- Deep of the directory in comparison with start directory- Since:
- 0.1.12-SNAPSHOT (Feb 8 2009)
-
setLanguage
public void setLanguage()Localize some strings using theLanguageHelperfeatures. See thelogging informationto know how the logging is implemented.- Since:
- 1.1 (Feb 18, 2009)
-
parseFiles
Does the real parsing job. Recursive method if theisIncludeSubFolders()is true. See thelogging informationto know how the logging is implemented.- Parameters:
bgw- SearchFilesWorker to perform cancel if needed, and report progressfile- to get sizesubDirDeep- Deep of the directory in comparison with start directory
-
isIncludeSubFolders
public boolean isIncludeSubFolders()- Returns:
- true if sub-folders must be parsed
-
setIncludeSubFolders
public void setIncludeSubFolders(boolean includeSubFolders)True to search on the sub folders. Modifying this value forces total size calculation if progress needed- Parameters:
includeSubFolders- the includeSubFolders to set
-
isIncludeHiddenFiles
public boolean isIncludeHiddenFiles()- Returns:
- true if the hidden files must be parsed
-
setIncludeHiddenFiles
public void setIncludeHiddenFiles(boolean includeHidden)True to search on the hidden files. Modifying this forces total size calculation if progress needed- Parameters:
includeHidden- the includeHidden to set
-
isPreCalcProgress
public boolean isPreCalcProgress()- Returns:
- true if the maximum value must be calculated before parsing files
-
setPreCalcProgress
public void setPreCalcProgress(boolean preCalcProgress)- Parameters:
preCalcProgress- true if the maximum value must be calculated before parsing files
-
getStartPath
- Returns:
- the startPath
-
setStartPath
Path of the root directory where to search Modifying this forces total size calculation if progress needed- Parameters:
startPath- the startPath to set
-
getProgressMax
public long getProgressMax()The returned value is not the size of the parsed directory, but only the total size of the matched files. \n To get the total size of a directory, call theFileUtils.getFileSizeString(File)method.- Returns:
- total length of matching files
-
isPreCalculated
public boolean isPreCalculated()Any modification on the parsing configuration wich affects the progress percentage will set this to false- Returns:
- true if the maximum value has been calculated for the same kind of parsing
-