diff --git a/.gitignore b/.gitignore index bd64445..5ffd15a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,34 @@ # IntelliJ .idea/ *.iml -out/ \ No newline at end of file +out/ +*.ipr +*.iws + +#Gradle +.gradletasknamecache +.gradle/ +build/ +# dropbox credentials +dropbox.json + + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse project files +.classpath +.project + +# Proguard folder generated by Eclipse +proguard/ \ No newline at end of file diff --git a/README.md b/README.md index 93c2e42..1e57750 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Iron Gate +[![build-passing](https://img.shields.io/badge/build-passing-brightgreen.svg)]() +[![version](https://img.shields.io/badge/version-0.2-red.svg)]() -Iron Gate is the code name given to a really convenient files and folders organization system. This is a cross-platform application built for Windows and Mac OSX. Some really great features: +Iron Gate is the code name given to a really convenient files and folders organization system. This is a cross-platform application built for Windows and Mac OSX. A few things Iron Gate can do: - Tag files and folders for quick search up - Save folder structures frequently used @@ -8,30 +10,32 @@ Iron Gate is the code name given to a really convenient files and folders organi - Search, upload, and download other user directory templates - Easily remove unused files and folders - ... more to come - - -### Version -0.2 -### Tech +### Cloud Support -The following is used to develop Iron Gate: +Iron Gate supports the following cloud services +- Dropbox +- Google Drive +- OneDrive -* [JavaFX] - great GUI library -* [JavaFX Scene Builder] - faster way to build! +### Installation -Iron Gate is open source, feel free to [contribute]! +Any java based IDE can build Iron Gate, although [IntelliJ] is highly recommended. This project uses +[gradle] as the build tool to gather all dependencies. If using IntelliJ, +please import the gradle module when asked. -### Installation +### Libraries and Other Technology -Any java based IDE can build Iron Gate, although [IntelliJ] is highly recommended. +The following is used to develop Iron Gate: -### Plugins +- [JavaFX] - great GUI library +- [JavaFX Scene Builder] - faster way to build! +- [JUnit] - a simple framework to write repeatable tests +- [Dropbox SDK] - a Java library to access Dropbox's HTTP-based Core API v2 +- [Google Drive API] - integration with google drive +- [OneDrive API] - integration with one drive -Iron Gate will eventually use the following plugins: -* Dropbox -* Google Drive -* OneDrive +Iron Gate is open source, feel free to [contribute]! ### Todos - ~~file browser controller~~ @@ -46,3 +50,8 @@ Iron Gate will eventually use the following plugins: [JavaFX Scene Builder]: [IntelliJ]: [contribute]: + [Dropbox SDK]: https://github.com/dropbox/dropbox-sdk-java + [JUnit]: http://junit.org/ + [Google Drive API]: https://developers.google.com/drive/v3/web/enable-sdk + [OneDrive API]: https://dev.onedrive.com/ + [gradle]: http://gradle.org/ \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e5454dc --- /dev/null +++ b/build.gradle @@ -0,0 +1,17 @@ +group 'xyz.venfo.desktop' +version '1.0-SNAPSHOT' + +apply plugin: 'java' + +sourceCompatibility = 1.5 + +repositories { + mavenCentral() +} + +dependencies { + compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '2.0-beta-7' + compile group: 'org.json', name: 'json', version: '20160212' + compile group: 'commons-io', name: 'commons-io', version: '1.3.2' + testCompile group: 'junit', name: 'junit', version: '4.11' +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..30d399d Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..b76e764 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Feb 25 00:26:14 EST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..bb7e57e --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'IronGate' + diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java deleted file mode 100644 index b5c8a6f..0000000 --- a/src/main/java/Controller.java +++ /dev/null @@ -1,147 +0,0 @@ -package main.java; - -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.event.Event; -import javafx.event.EventHandler; -import javafx.fxml.FXML; -import javafx.scene.Node; -import javafx.scene.Scene; -import javafx.scene.control.*; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.input.DragEvent; -import javafx.scene.input.Dragboard; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.TransferMode; -import sun.misc.Resource; -import sun.reflect.generics.tree.Tree; - -import java.io.File; -import java.io.IOException; -import java.nio.file.FileVisitOption; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.EnumSet; -import java.util.ResourceBundle; - -public class Controller{ - @FXML private MenuItem fileOpen; - @FXML private MenuItem fileNew; - @FXML private MenuItem fileTag; - @FXML private MenuItem fileExit; - @FXML private MenuItem editPreferences; - @FXML private MenuBar menubar; - @FXML private TreeView dirTree; - @FXML private MenuItem toolsTagFiles; - @FXML private MenuItem toolsDeleteTags; - @FXML private ResourceBundle resources; - @FXML private Label dragHereLabel; - - FolderViewManager manager; - - @FXML private void initialize() { - - manager = new FolderViewManager(dirTree); - - IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives - // manager.setRootDirectory(hardDrives); - - menubar.setUseSystemMenuBar(true); //allows use of native menu bars, luckily an easy 1 liner - - /** - * Tell the manager that new files have been selected - */ - dirTree.setOnMouseClicked(new EventHandler() { - - @Override - public void handle(MouseEvent args) { - - ObservableList> selectedItems = dirTree.getSelectionModel().getSelectedItems(); - - manager.setSelectedFiles(selectedItems); - - } - - }); - - - toolsTagFiles.setOnAction(new EventHandler() { - - @Override - public void handle(ActionEvent event) { - - manager.setFileAttrForSelected(); - - } - - }); - - toolsDeleteTags.setOnAction(new EventHandler() { - - @Override - public void handle(ActionEvent event) { - - manager.deleteFileAttrForSelected(); - - } - - }); - - } - - public void initializeSceneEvents() { - - Scene scene = dirTree.getScene(); - - scene.setOnDragOver(new EventHandler() { - - @Override - public void handle(DragEvent args) { - - Dragboard db = args.getDragboard(); - //System.out.println("dragging over"); - - if(db.hasFiles()) { - - args.acceptTransferModes(TransferMode.COPY); - - } else { args.consume(); } - } - - }); - - - scene.setOnDragDropped(new EventHandler() { - - @Override - public void handle(DragEvent args) { - - Dragboard db = args.getDragboard(); - args.acceptTransferModes(TransferMode.COPY); - - boolean success = false; - - if(db.hasFiles()) { - - System.out.println("dropped file(s)"); - - IronFile[] roots = IronFile.convertFiles(db.getFiles()); - manager.setRootDirectory(roots); - success = true; - dragHereLabel.setText(""); - dragHereLabel.setMaxWidth(0); - - } - - args.setDropCompleted(success); - - } - - }); - - } -} - diff --git a/src/main/java/FolderViewManager.java b/src/main/java/FolderViewManager.java deleted file mode 100644 index 17f6034..0000000 --- a/src/main/java/FolderViewManager.java +++ /dev/null @@ -1,197 +0,0 @@ -package main.java; - -import javafx.collections.ObservableList; -import javafx.scene.control.TreeItem; -import javafx.scene.control.TreeView; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.attribute.UserDefinedFileAttributeView; -import java.util.ArrayList; -import java.util.List; - -/** - This class handles manipulation of the Folder View. This includes - directory searches, displaying directories, and all things directly changing - the Folder View. - - @author Kristopher Guzman kristopherguz@gmail.com - @author Brian Patino patinobrian@gmail.com - */ -public class FolderViewManager { - - //private IronFileVisitor ironVisitor; // might be used later - private final Image hddIcon = new Image("/main/resources/icons/hdd.png"); - private TreeView view; - private CmdExecutor command; - private List> selectedFiles; - - public FolderViewManager(TreeView dirTree) { - /*ironVisitor = new IronFileVisitor(); // save this for later - ironVisitor.setRoot(new TreeItem<>());*/ // save this for later - - OSDetection.getOS(); - view = dirTree; - command = new CmdExecutor(); - - } - - - public void setRootDirectory(IronFile[] hardDrives) { - view.setRoot(new FileTreeItem(new IronFile(""))); // needs a blank file as root - for (IronFile hdd : hardDrives) { - System.out.println(hdd.getName()); - FileTreeItem diskTreeItem = new FileTreeItem(hdd); - diskTreeItem.setGraphic(new ImageView(hddIcon)); - view.getRoot().getChildren().add(diskTreeItem); - } - view.setShowRoot(false); // hide the blank file - } - - public void setSelectedFiles(List> files) { - - selectedFiles = files; - - } - - public void setFileAttrForSelected() { - - for(TreeItem item : selectedFiles) { - - setFileAttr(item.getValue(), "test_attr_key", "test_attr_value"); - - } - - } - - public void getFileAttrForSelected() { - - for(TreeItem item : selectedFiles) { - - getFileAttr(item.getValue(), "test_attr_key"); - - } - - } - - public void deleteFileAttrForSelected() { - - for(TreeItem item : selectedFiles) { - - deleteFileAttr(item.getValue(), "test_attr_key"); - - } - - } - - public void setFileAttr(IronFile file, String key, String value) { - - if(OSDetection.OSType == OSDetection.OS.WINDOWS) { - - try { - - UserDefinedFileAttributeView view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class); - - //might want to give unique prefix to tag keys to avoid collision with system metadata - view.write(key, Charset.defaultCharset().encode(value)); - - } catch(IOException e) { e.printStackTrace(); } - - } else if(OSDetection.OSType == OSDetection.OS.MAC) { - - String option = ""; - - if(file.isDirectory()) { - option = "-r"; - } - - - String cmd = "xattr -w " + option + " " + key + " " + value + " " + file.getAbsolutePath(); - - try { - - String output = command.run(cmd); - - } catch(IOException e) { e.printStackTrace(); } - - - } - - } - - public String getFileAttr(IronFile file, String key) { - - if(OSDetection.OSType == OSDetection.OS.WINDOWS) { - - try { - UserDefinedFileAttributeView view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class); - - ByteBuffer buf = ByteBuffer.allocate(view.size(key)); - view.read(key, buf); - buf.flip(); - - return Charset.defaultCharset().decode(buf).toString(); - - } catch(IOException e) { e.printStackTrace(); } - - } else if(OSDetection.OSType == OSDetection.OS.MAC) { - - System.out.println("file path: " + file.getAbsolutePath()); - - String option = ""; - - if(file.isDirectory()) { - //option = "-r"; - } - - - String cmd = "xattr -p " + option + " " + key + " " + file.getAbsolutePath(); //then append the attr command - - try { - - String output = command.run(cmd); - - } catch(IOException e) { e.printStackTrace(); } - - } - - return null; - - } - - public void deleteFileAttr(IronFile file, String key) { - - if(OSDetection.OSType == OSDetection.OS.WINDOWS) { - - try { - - UserDefinedFileAttributeView view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class); - view.delete(key); - - } catch(IOException e) { e.printStackTrace(); } - - } else if(OSDetection.OSType == OSDetection.OS.MAC) { - - System.out.println("file path: " + file.getAbsolutePath()); - - - String cmd = "xattr -d " + key + " " + file.getAbsolutePath(); //then append the attr command - - try { - - String output = command.run(cmd); - - - } catch(IOException e) { e.printStackTrace(); } - - } - - } - -} diff --git a/src/main/java/FileTreeItem.java b/src/main/java/directory/FileTreeItem.java similarity index 95% rename from src/main/java/FileTreeItem.java rename to src/main/java/directory/FileTreeItem.java index ef1aa5b..e3f5c9a 100644 --- a/src/main/java/FileTreeItem.java +++ b/src/main/java/directory/FileTreeItem.java @@ -1,4 +1,4 @@ -package main.java; +package directory; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -39,9 +39,6 @@ public boolean isLeaf() { } private ObservableList buildChildren(TreeItem ironTreeItem) { IronFile f = ironTreeItem.getValue(); - - System.out.println("file's parent: " + f.getParent()); - if (f != null && f.isDirectory()) { IronFile[] files = f.listFiles(); if (files != null) { diff --git a/src/main/java/directory/FolderViewManager.java b/src/main/java/directory/FolderViewManager.java new file mode 100644 index 0000000..ae6ddd5 --- /dev/null +++ b/src/main/java/directory/FolderViewManager.java @@ -0,0 +1,94 @@ +package directory; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.ListView; +import javafx.scene.control.SelectionMode; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeView; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import sun.reflect.generics.tree.Tree; +import utils.CmdExecutor; +import utils.OSDetection; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.attribute.UserDefinedFileAttributeView; +import java.util.ArrayList; +import java.util.List; + +/** + This class handles manipulation of the Folder View. This includes + directory searches, displaying directories, and all things directly changing + the Folder View. + + Additionally, this class extends SimpleFileVisitor which uses java 8. + + @author Kristopher Guzman kristopherguz@gmail.com + @author Brian Patino patinobrian@gmail.com + */ +public class FolderViewManager { + private final Image hddIcon = new Image("/icons/hdd.png"); + private TreeView view; + private ObservableList taggedItems = FXCollections.observableArrayList(); + + /** + * Folder View Manager constructor, initializes the view for the file browser + * */ + public FolderViewManager(TreeView dirTree) { + view = dirTree; + view.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); // enable multi-select + } + /** + * Sets the root directory of the file browser to the specified folder. + * @param file root folder/file to start browser view + **/ + public void setRootDirectory(IronFile file) { + FileTreeItem rootItem = new FileTreeItem(file); + view.setRoot(rootItem); + } + /** + * Overloaded method that sets a collection of folders/files as file browser view. + * @param hardDrives a collection of hard drives to being from root + * */ + public void setRootDirectory(IronFile[] hardDrives) { + view.setRoot(new FileTreeItem(new IronFile(""))); // needs a blank file as root + for (IronFile hdd : hardDrives) { + FileTreeItem diskTreeItem = new FileTreeItem(hdd); + diskTreeItem.setGraphic(new ImageView(hddIcon)); + view.getRoot().getChildren().add(diskTreeItem); + } + view.setShowRoot(false); // hide the blank file + } + + public void setTags(ObservableList selectedItems, String tag) { + for (IronFile selectedIronFile : selectedItems) { + selectedIronFile.setTag(tag); + taggedItems.add(selectedIronFile); // add tagged item to list + } + } + + public void deleteAllTags(ObservableList> selectedItems) { + for (TreeItem selectedItem : selectedItems) { + selectedItem.getValue().setTag(null); // removes all tags for all selected files + } + } + + /** + * Retrieves an Observable list of TreeItem of tagged items. + * */ + public ObservableList getTaggedItems(String searchTag) { + ObservableList listTagFiles = FXCollections.observableArrayList(); + for (IronFile taggedIronFile : taggedItems) { + if (taggedIronFile.getTag().equals(searchTag)) { + listTagFiles.add(taggedIronFile); + } + } + return listTagFiles; + } +} diff --git a/src/main/java/IronFile.java b/src/main/java/directory/IronFile.java similarity index 89% rename from src/main/java/IronFile.java rename to src/main/java/directory/IronFile.java index 5f64ed6..6b33120 100644 --- a/src/main/java/IronFile.java +++ b/src/main/java/directory/IronFile.java @@ -1,5 +1,6 @@ +package directory; -package main.java; +import utils.IronFileFilter; import java.io.File; import java.util.List; @@ -8,9 +9,9 @@ * This class extends the java File class and returns the filename for toString() */ public class IronFile extends File { - private boolean isRoot = true; public IronFileFilter filter; + private String tag; public IronFile(String pathname) { super(pathname); @@ -68,4 +69,11 @@ public String toString() { return this.getName(); } } + + public String getTag() { + return tag; + } + public void setTag(String tag) { + this.tag = tag; + } } \ No newline at end of file diff --git a/src/main/java/IronFileVisitor.java b/src/main/java/directory/IronFileVisitor.java similarity index 91% rename from src/main/java/IronFileVisitor.java rename to src/main/java/directory/IronFileVisitor.java index ddc9222..eb77a4c 100644 --- a/src/main/java/IronFileVisitor.java +++ b/src/main/java/directory/IronFileVisitor.java @@ -1,10 +1,7 @@ -package main.java; +package directory; -import javafx.scene.Scene; import javafx.scene.control.TreeItem; -import javafx.scene.control.TreeView; -import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Path; @@ -27,7 +24,7 @@ public class IronFileVisitor extends SimpleFileVisitor{ public FileVisitResult visitFile(Path pathFile, BasicFileAttributes attrs) throws IOException { IronFile current = new IronFile(pathFile.toFile()); // System.out.println(current.getAbsolutePath()); -// root.getChildren().add(new TreeItem<>(new IronFile(current.getAbsolutePath()))); +// root.getChildren().add(new TreeItem<>(new directory.IronFile(current.getAbsolutePath()))); System.out.printf("Visiting file %s\n", pathFile); return FileVisitResult.CONTINUE; } diff --git a/src/main/java/launcher/Controller.java b/src/main/java/launcher/Controller.java new file mode 100644 index 0000000..8153b32 --- /dev/null +++ b/src/main/java/launcher/Controller.java @@ -0,0 +1,76 @@ +package launcher; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventHandler; +import directory.FolderViewManager; +import directory.IronFile; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import sun.misc.Resource; +import sun.reflect.generics.tree.Tree; +import com.dropbox.core.*; +import com.dropbox.core.v2.*; +import webapp.DropboxController; + +import java.util.List; +import java.util.ResourceBundle; +import java.util.stream.Collectors; + +public class Controller{ + @FXML private MenuItem fileOpen; + @FXML private MenuItem fileNew; + @FXML private MenuItem fileTag; + @FXML private MenuItem fileExit; + @FXML private MenuItem editPreferences; + @FXML private MenuItem fileDropboxSignin; + @FXML private TreeView dirTree; + @FXML private MenuItem toolsTagFiles; + @FXML private MenuItem toolsDeleteTags; + @FXML private ResourceBundle resources; + @FXML private Button btnAddTag; + @FXML private TextField txtAddTag; + @FXML private TextField txtTagSearch; + @FXML private Button btnSearchTag; + @FXML private ListView viewTags; + private FolderViewManager manager; + + @FXML private void initialize() { + manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best + IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives + manager.setRootDirectory(hardDrives); + } + /** + * Action event triggered when user clicks. This method will add tag directly to IronFile + * Method name must match StartPage.fxml assigned `on Action` + * */ + @FXML private void eventAddTag() { + ObservableList> treeIronFileList = dirTree.getSelectionModel().getSelectedItems(); + ObservableList selectedIronFiles = FXCollections.observableArrayList(); + /** The following line converts ObservableList into ObservableList which is needed to display just the names.**/ + selectedIronFiles.addAll(treeIronFileList.stream().map(TreeItem::getValue).collect(Collectors.toList())); + manager.setTags(selectedIronFiles, txtAddTag.getText()); + } + /** + * On Click event that will search and display files based on entered tag + * */ + @FXML private void eventSearchTag() { + ObservableList taggedItems = manager.getTaggedItems(txtTagSearch.getText()); + viewTags.setItems(taggedItems); + } + /** + * Action on click event that will delete all tag information from selected files. + * */ + @FXML private void eventDeleteTags() { + ObservableList> selectedItems = dirTree.getSelectionModel().getSelectedItems(); // get list of selected files + manager.deleteAllTags(selectedItems); + } +} + diff --git a/src/main/java/Main.java b/src/main/java/launcher/Main.java similarity index 69% rename from src/main/java/Main.java rename to src/main/java/launcher/Main.java index a67fe94..d64ce98 100644 --- a/src/main/java/Main.java +++ b/src/main/java/launcher/Main.java @@ -1,4 +1,4 @@ -package main.java; +package launcher; import javafx.application.Application; import javafx.fxml.FXMLLoader; @@ -17,22 +17,14 @@ public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ -// setUserAgentStylesheet(STYLESHEET_CASPIAN); - - FXMLLoader loader = new FXMLLoader(); - Parent root = loader.load(getClass().getResource("/main/resources/StartPage.fxml").openStream()); + setUserAgentStylesheet(STYLESHEET_CASPIAN); + Parent root = FXMLLoader.load(getClass().getResource("/StartPage.fxml")); primaryStage.setTitle("Iron-gate!"); primaryStage.setScene(new Scene(root, 990, 700)); Scene scene = primaryStage.getScene(); // we get the scene from above scene.getStylesheets().clear(); // clear any styles - scene.getStylesheets().add("/main/resources/mainStyle.css"); - Controller controller = loader.getController(); - - controller.initializeSceneEvents(); - // scene.getStylesheets().add("/main/resources/mainStyle.css"); // absolute path primaryStage.show(); - } public static void main(String[] args) { launch(args); diff --git a/src/main/java/CmdExecutor.java b/src/main/java/utils/CmdExecutor.java similarity index 97% rename from src/main/java/CmdExecutor.java rename to src/main/java/utils/CmdExecutor.java index 1bcecf0..f9e93f2 100644 --- a/src/main/java/CmdExecutor.java +++ b/src/main/java/utils/CmdExecutor.java @@ -1,4 +1,4 @@ -package main.java; +package utils; import java.io.BufferedReader; import java.io.IOException; @@ -12,10 +12,7 @@ public class CmdExecutor { public CmdExecutor() { } public String run(String cmd) throws IOException { - System.out.println("executing command: " + cmd); - - String[] args = new String[] {"sh", "-c", "cd / && " + cmd}; Process process = Runtime.getRuntime().exec(args); BufferedReader outputReader = new BufferedReader(new InputStreamReader(process.getInputStream())); //efficiently reads chars @@ -26,23 +23,17 @@ public String run(String cmd) throws IOException { System.out.println("Below is command output: \n "); while(line != null) { - System.out.println("cmd output: " + line); line = outputReader.readLine(); - } while(error != null) { - System.out.println("error output: " + error); error = errorReader.readLine(); } - outputReader.close(); errorReader.close(); return null; - } - } diff --git a/src/main/java/IronFileFilter.java b/src/main/java/utils/IronFileFilter.java similarity index 93% rename from src/main/java/IronFileFilter.java rename to src/main/java/utils/IronFileFilter.java index 6488872..763d585 100644 --- a/src/main/java/IronFileFilter.java +++ b/src/main/java/utils/IronFileFilter.java @@ -1,4 +1,4 @@ -package main.java; +package utils; import java.io.FilenameFilter; import java.io.File; @@ -10,26 +10,22 @@ public class IronFileFilter implements FilenameFilter { public boolean accept(File file, String name) { - boolean hidden = false; boolean isSymbolic = false; boolean isRegularFile = false; try { - hidden = Files.isHidden(file.toPath()); isSymbolic = Files.isSymbolicLink(file.toPath()); isRegularFile = Files.isRegularFile(file.toPath()); + } catch(Exception e) { - } catch(Exception e) { } + } if(hidden || isSymbolic || (!isRegularFile && !file.isDirectory())) { //System.out.println(name + " is hidden or a symbolic link, or just not a regular file"); return false; } - return true; - } - } diff --git a/src/main/java/OSDetection.java b/src/main/java/utils/OSDetection.java similarity index 96% rename from src/main/java/OSDetection.java rename to src/main/java/utils/OSDetection.java index 7c7a006..ca37337 100644 --- a/src/main/java/OSDetection.java +++ b/src/main/java/utils/OSDetection.java @@ -1,4 +1,4 @@ -package main.java; +package utils; /** * Created by kristopherguzman on 2/19/16. @@ -13,30 +13,19 @@ public enum OS { WINDOWS, MAC, UNIX } public static OS OSType; public static void getOS() { //utility method to get OS - String os = System.getProperty("os.name").toLowerCase(); if(os.contains("win")) { - OSType = OS.WINDOWS; System.out.println("OS: Windows"); - } else if(os.contains("nix") || os.contains("ux") || os.contains("aix")) { - OSType = OS.UNIX; System.out.println("OS: Unix/Linux"); - } else if(os.contains("mac")) { - OSType = OS.MAC; System.out.println("OS: Mac"); - } else { - System.out.println("Could not detect OS"); - } - } - } diff --git a/src/main/java/webapp/Dropbox.java b/src/main/java/webapp/Dropbox.java new file mode 100644 index 0000000..64c8696 --- /dev/null +++ b/src/main/java/webapp/Dropbox.java @@ -0,0 +1,64 @@ +package webapp; + +import org.json.JSONObject; + +import java.io.File; +import java.io.FileReader; +import java.net.URL; + +/** + * Dropbox API specific + */ +public class Dropbox { + // retrieve private credentials from Dropbox Developers app + private String key; + private String secret; + private String token; + + public Dropbox() { + readSetCredentials(); + } + public Dropbox(String key, String secret) { + this.key = key; + this.secret = secret; + } + public Dropbox(String key, String secret, String token) { + this.key = key; + this.secret = secret; + this.token = token; + } + + private void readSetCredentials() { + try { + URL url = getClass().getResource("/services/dropbox.json"); + FileReader readCred = new FileReader(url.getPath()); + JSONObject dropCred = new JSONObject(url.getPath()); + key = dropCred.getString("key"); + secret = dropCred.getString("secret"); + token = dropCred.getString("token"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public String getKey() { + return key; + } + public String getSecret() { + return secret; + } + public String getToken() { + return token; + } + public void setKey(String key) { + this.key = key; + } + public void setSecret(String secret) { + this.secret = secret; + } + public void setToken(String token) { + this.token = token; + } + + +} diff --git a/src/main/java/webapp/DropboxController.java b/src/main/java/webapp/DropboxController.java new file mode 100644 index 0000000..5d48e97 --- /dev/null +++ b/src/main/java/webapp/DropboxController.java @@ -0,0 +1,30 @@ +package webapp; + +import com.dropbox.core.DbxException; +import com.dropbox.core.DbxRequestConfig; +import com.dropbox.core.v2.DbxClientV2; +import com.dropbox.core.v2.users.FullAccount; + +/** + * This class controls the Dropbox application logic. + */ +public class DropboxController { + private static Dropbox dropbox; + private DbxClientV2 client; + private DbxRequestConfig config; + + public DropboxController() { + initialize(); + } + + private void initialize() { + dropbox = new Dropbox(); // uses default json file credentials + config = new DbxRequestConfig("dropbox/IronGate", "en_US"); + client = new DbxClientV2(config, dropbox.getToken()); + } + + public void test() throws DbxException{ + FullAccount account = client.users.getCurrentAccount(); + System.out.println(account); + } +} diff --git a/src/test/java/Test.java b/src/test/java/Test.java new file mode 100644 index 0000000..f274cd4 --- /dev/null +++ b/src/test/java/Test.java @@ -0,0 +1,6 @@ +/** + * A test of test methods + */ +public class Test { + +} diff --git a/src/test/resources/blank.text b/src/test/resources/blank.text new file mode 100644 index 0000000..cb843b9 --- /dev/null +++ b/src/test/resources/blank.text @@ -0,0 +1 @@ +resources test goes here \ No newline at end of file