From: David ‘Bombe’ Roden Date: Sun, 22 Jun 2008 14:02:24 +0000 (+0200) Subject: add javadoc X-Git-Tag: 0.4.12.2~12 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5c29aa2ec7fb5d4e362636d0e25c422668702f26;p=jSite.git add javadoc --- diff --git a/src/de/todesbaum/jsite/gui/FileScanner.java b/src/de/todesbaum/jsite/gui/FileScanner.java index d134e7c..b699ebb 100644 --- a/src/de/todesbaum/jsite/gui/FileScanner.java +++ b/src/de/todesbaum/jsite/gui/FileScanner.java @@ -29,31 +29,75 @@ import java.util.List; import de.todesbaum.jsite.application.Project; import de.todesbaum.jsite.i18n.I18n; +/** + * Scans the local path of a project anychronously and returns the list of found + * files as an event. + * + * @see Project#getLocalPath() + * @see FileScannerListener#fileScannerFinished(FileScanner) + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + */ public class FileScanner implements Runnable { + /** The list of listeners. */ private final List fileScannerListeners = new ArrayList(); + + /** The project to scan. */ private final Project project; + + /** The list of found files. */ private List files; + + /** Wether there was an error. */ private boolean error = false; + /** + * Creates a new file scanner for the given project. + * + * @param project + * The project whose files to scan + */ public FileScanner(Project project) { this.project = project; } + /** + * Adds the given listener to the list of listeners. + * + * @param fileScannerListener + * The listener to add + */ public void addFileScannerListener(FileScannerListener fileScannerListener) { fileScannerListeners.add(fileScannerListener); } + /** + * Removes the given listener from the list of listeners. + * + * @param fileScannerListener + * The listener to remove + */ public void removeFileScannerListener(FileScannerListener fileScannerListener) { fileScannerListeners.remove(fileScannerListener); } + /** + * Notifies all listeners that the file scan finished. + */ protected void fireFileScannerFinished() { - for (FileScannerListener fileScannerListener: new ArrayList(fileScannerListeners)) { + for (FileScannerListener fileScannerListener : new ArrayList(fileScannerListeners)) { fileScannerListener.fileScannerFinished(this); } } + /** + * {@inheritDoc} + *

+ * Scans all available files in the project’s local path and emits an event + * when finished. + * + * @see FileScannerListener#fileScannerFinished(FileScanner) + */ public void run() { files = new ArrayList(); error = false; @@ -66,14 +110,35 @@ public class FileScanner implements Runnable { fireFileScannerFinished(); } + /** + * Returns whether there was an error scanning for files. + * + * @return true if there was an error, false + * otherwise + */ public boolean isError() { return error; } + /** + * Returns the list of found files. + * + * @return The list of found files + */ public List getFiles() { return files; } + /** + * Recursively scans a directory and adds all found files to the given list. + * + * @param rootDir + * The directory to scan + * @param fileList + * The list to which to add the found files + * @throws IOException + * if an I/O error occurs + */ private void scanFiles(File rootDir, List fileList) throws IOException { File[] files = rootDir.listFiles(new FileFilter() { @@ -84,7 +149,7 @@ public class FileScanner implements Runnable { if (files == null) { throw new IOException(I18n.getMessage("jsite.file-scanner.can-not-read-directory")); } - for (File file: files) { + for (File file : files) { if (file.isDirectory()) { scanFiles(file, fileList); continue;