import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import net.pterodactylus.util.io.StreamCopier.ProgressListener;
import de.todesbaum.jsite.gui.FileScanner;
-import de.todesbaum.jsite.gui.FileScanner.ScannedFile;
+import de.todesbaum.jsite.gui.ScannedFile;
import de.todesbaum.jsite.gui.FileScannerListener;
import de.todesbaum.util.freenet.fcp2.Client;
import de.todesbaum.util.freenet.fcp2.ClientPutComplexDir;
}
long totalSize = 0;
final CountDownLatch completionLatch = new CountDownLatch(1);
- FileScanner fileScanner = new FileScanner(project, new FileScannerListener() {
-
- @Override
- public void fileScannerFinished(FileScanner fileScanner) {
- completionLatch.countDown();
- }
- });
+ FileScanner fileScanner = new FileScanner(project, (error, files) -> completionLatch.countDown());
fileScanner.startInBackground();
while (completionLatch.getCount() > 0) {
try {
* {@inheritDoc}
*/
@Override
- public void fileScannerFinished(FileScanner fileScanner) {
- if (!fileScanner.isError()) {
+ public void fileScannerFinished(boolean error, Collection<ScannedFile> files) {
+ if (!error) {
new Thread(this).start();
} else {
projectInsertListeners.fireProjectInsertFinished(project, false, null);
* files as an event.
*
* @see Project#getLocalPath()
- * @see FileScannerListener#fileScannerFinished(FileScanner)
+ * @see FileScannerListener#fileScannerFinished(boolean, java.util.Collection)
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class FileScanner implements Runnable {
* Scans all available files in the project’s local path and emits an event
* when finished.
*
- * @see FileScannerListener#fileScannerFinished(FileScanner)
+ * @see FileScannerListener#fileScannerFinished(boolean, java.util.Collection)
*/
@Override
public void run() {
} catch (IOException ioe1) {
error = true;
}
- fileScannerListener.fileScannerFinished(this);
+ fileScannerListener.fileScannerFinished(error, files);
}
/**
return hexString.toString();
}
- /**
- * Container for a scanned file, consisting of the name of the file and its
- * hash.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public static class ScannedFile implements Comparable<ScannedFile> {
-
- /** The name of the file. */
- private final String filename;
-
- /** The hash of the file. */
- private final String hash;
-
- /**
- * Creates a new scanned file.
- *
- * @param filename
- * The name of the file
- * @param hash
- * The hash of the file
- */
- public ScannedFile(String filename, String hash) {
- this.filename = filename;
- this.hash = hash;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the name of the file.
- *
- * @return The name of the file
- */
- public String getFilename() {
- return filename;
- }
-
- /**
- * Returns the hash of the file.
- *
- * @return The hash of the file
- */
- public String getHash() {
- return hash;
- }
-
- //
- // OBJECT METHODS
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return filename.hashCode();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- return filename.equals(obj);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return filename;
- }
-
- //
- // COMPARABLE METHODS
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int compareTo(ScannedFile scannedFile) {
- return filename.compareTo(scannedFile.filename);
- }
-
- }
-
}
package de.todesbaum.jsite.gui;
+import java.util.Collection;
import java.util.EventListener;
/**
*/
public interface FileScannerListener extends EventListener {
- /**
- * Notifies a listener that scanning a project’s local path has finished.
- *
- * @param fileScanner
- * The file scanner that finished
- */
- public void fileScannerFinished(FileScanner fileScanner);
+ void fileScannerFinished(boolean error, Collection<ScannedFile> files);
-}
\ No newline at end of file
+}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.MessageFormat;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import javax.swing.AbstractAction;
import net.pterodactylus.util.thread.StoppableDelay;
import de.todesbaum.jsite.application.FileOption;
import de.todesbaum.jsite.application.Project;
-import de.todesbaum.jsite.gui.FileScanner.ScannedFile;
import de.todesbaum.jsite.i18n.I18n;
import de.todesbaum.jsite.i18n.I18nContainer;
import de.todesbaum.util.swing.TLabel;
* Updates the file list.
*/
@Override
- public void fileScannerFinished(FileScanner fileScanner) {
+ public void fileScannerFinished(boolean error, Collection<ScannedFile> files) {
delayedNotification.finish();
- final boolean error = fileScanner.isError();
if (!error) {
- final List<ScannedFile> files = fileScanner.getFiles();
SwingUtilities.invokeLater(new Runnable() {
@Override
--- /dev/null
+package de.todesbaum.jsite.gui;
+
+/**
+ * Container for a scanned file, consisting of the name of the file and its
+ * hash.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public class ScannedFile implements Comparable<ScannedFile> {
+
+ /** The name of the file. */
+ private final String filename;
+
+ /** The hash of the file. */
+ private final String hash;
+
+ /**
+ * Creates a new scanned file.
+ *
+ * @param filename
+ * The name of the file
+ * @param hash
+ * The hash of the file
+ */
+ public ScannedFile(String filename, String hash) {
+ this.filename = filename;
+ this.hash = hash;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the name of the file.
+ *
+ * @return The name of the file
+ */
+ public String getFilename() {
+ return filename;
+ }
+
+ /**
+ * Returns the hash of the file.
+ *
+ * @return The hash of the file
+ */
+ public String getHash() {
+ return hash;
+ }
+
+ //
+ // OBJECT METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return filename.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return filename.equals(obj);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return filename;
+ }
+
+ //
+ // COMPARABLE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compareTo(ScannedFile scannedFile) {
+ return filename.compareTo(scannedFile.filename);
+ }
+
+}