Move starting file scanner in background to file scanner class
[jSite.git] / src / main / java / de / todesbaum / jsite / gui / FileScanner.java
index cfb0c23..9135073 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - FileScanner.java - Copyright © 2006–2012 David Roden
+ * jSite - FileScanner.java - Copyright © 2006–2014 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -63,6 +63,9 @@ public class FileScanner implements Runnable {
        /** Wether there was an error. */
        private boolean error = false;
 
+       /** The name of the last file scanned. */
+       private String lastFilename;
+
        /**
         * Creates a new file scanner for the given project.
         *
@@ -103,6 +106,20 @@ public class FileScanner implements Runnable {
        }
 
        /**
+        * Returns the name of the last file scanned.
+        *
+        * @return The name of the last file scanned, or {@code null} if there was
+        *         no file scanned yet
+        */
+       public String getLastFilename() {
+               return lastFilename;
+       }
+
+       public void startInBackground() {
+               new Thread(this).start();
+       }
+
+       /**
         * {@inheritDoc}
         * <p>
         * Scans all available files in the project’s local path and emits an event
@@ -114,6 +131,7 @@ public class FileScanner implements Runnable {
        public void run() {
                files = new ArrayList<ScannedFile>();
                error = false;
+               lastFilename = null;
                try {
                        scanFiles(new File(project.getLocalPath()), files);
                        Collections.sort(files);
@@ -172,6 +190,7 @@ public class FileScanner implements Runnable {
                        String filename = project.shortenFilename(file).replace('\\', '/');
                        String hash = hashFile(project.getLocalPath(), filename);
                        fileList.add(new ScannedFile(filename, hash));
+                       lastFilename = filename;
                }
        }