public static void registerDirectory(File directory) {
        // ensures that the specified File is a directory and that it isn't
        // currently registered
        if (directory.isDirectory() && !registeredDirectories.contains(directory)) {
            if (!running)
                start();
            
            try {
                Path directoryPath = directory.toPath();    // the Path to the directory
                
                // the WatchKey that monitors this directory
                WatchKey watchKey = directoryPath.register(
                        watchService, 
                        StandardWatchEventKinds.ENTRY_CREATE,
                        StandardWatchEventKinds.ENTRY_MODIFY,
                        StandardWatchEventKinds.ENTRY_DELETE);

                // put the Path and WatchKey into a two-way mapping
                pathToWatchKey.put(directoryPath, watchKey);
                watchKeyToPath.put(watchKey, directoryPath);
                
                // add the directory to the list of registered directories, update
                // the user interface, and store the directory in the user's settings
                // so that the directory will automatically be registered the next
                // time the user starts the program
                registeredDirectories.add(directory);
                UserInterfaceManager.getSmartFolderFrame().getSmartFolderPanel().updateMonitoredDirectoriesTree(registeredDirectories);
                SettingsManager.updateSmartFolders();

                // recursive step
                for (File child : directory.listFiles())
                    if (child.isFile())
                        ScanManager.pushFileForUpload(child, false);
                    else if (child.isDirectory())
                        registerDirectory(child);
            } catch (IOException e) {}
        }
    }