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 c0b610e..1e57750 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,57 @@ # 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 project that will provide convenient and simple tag based file and folder management. This is a cross-platform application for Windows, Mac OSX, and Linux. Some of the main features we are aiming for: +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: - - Inexact search using tags - - 1 click folder organizer - - 1 click file/folder tagging - - Save folder structures frequently used as templates + - Tag files and folders for quick search up + - Save folder structures frequently used + - Create predefined directories based on common usages - 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] - GUI library -* [JavaFX Scene Builder] - Quick GUI design +### 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 our personal preference. +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~~ - tag feature - design gui - - cloud service support + - cloud service suppoort - everything else [//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax) [JavaFx]: - [JavaFX Scene Builder]: + [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..08da353 --- /dev/null +++ b/build.gradle @@ -0,0 +1,16 @@ +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' + 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 f9da16a..0000000 --- a/src/main/java/Controller.java +++ /dev/null @@ -1,39 +0,0 @@ -package main.java; - -import javafx.fxml.FXML; -import javafx.scene.Node; -import javafx.scene.control.MenuItem; -import javafx.scene.control.TreeCell; -import javafx.scene.control.TreeItem; -import javafx.scene.control.TreeView; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -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 TreeView dirTree; - @FXML private ResourceBundle resources; - - @FXML private void initialize() { - FolderViewManager manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best - IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives - manager.setRootDirectory(hardDrives); -// IronFile homeDir = new IronFile(System.getProperty("user.home")); // use this for specific directory -// manager.setRootDirectory(homeDir); - } -} - diff --git a/src/main/java/FolderViewManager.java b/src/main/java/FolderViewManager.java deleted file mode 100644 index 962308c..0000000 --- a/src/main/java/FolderViewManager.java +++ /dev/null @@ -1,51 +0,0 @@ -package main.java; - -import javafx.scene.control.TreeView; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; - -/** - 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 kristopherguzman - @author Brian Patino patinobrian@gmail.com - */ -public class FolderViewManager { - private final Image hddIcon = new Image("/main/resources/icons/hdd.png"); -// private IronFileVisitor ironVisitor; // might be used later - private TreeView view; - - public FolderViewManager(TreeView dirTree) { - /*ironVisitor = new IronFileVisitor(); // save this for later - ironVisitor.setRoot(new TreeItem<>());*/ // save this for later - view = dirTree; - } - - /** - * 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 - } -} diff --git a/src/main/java/FileTreeItem.java b/src/main/java/directory/FileTreeItem.java similarity index 82% rename from src/main/java/FileTreeItem.java rename to src/main/java/directory/FileTreeItem.java index 4b9eaa5..bf8970f 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; @@ -21,7 +21,7 @@ public FileTreeItem(IronFile rootFile) { @Override public ObservableList> getChildren() { - if (isFirstTimeChildren) { + if (isFirstTimeChildren) { //if children of node have not been created, then do so isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } @@ -39,12 +39,18 @@ 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) { ObservableList children = FXCollections.observableArrayList(); + for (IronFile childFile : files) { - children.add(new FileTreeItem(childFile)); + if(childFile.filter.accept(childFile, childFile.getName())) { + children.add(new FileTreeItem(childFile)); + } } return children; } diff --git a/src/main/java/directory/FolderViewManager.java b/src/main/java/directory/FolderViewManager.java new file mode 100644 index 0000000..ed5396a --- /dev/null +++ b/src/main/java/directory/FolderViewManager.java @@ -0,0 +1,153 @@ +package directory; + +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 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 directory.IronFileVisitor ironVisitor; // might be used later + private TreeView view; + private CmdExecutor command; + private List> selectedFiles; + + public FolderViewManager(TreeView dirTree) { + /*ironVisitor = new directory.IronFileVisitor(); // save this for later + ironVisitor.setRoot(new TreeItem<>());*/ // save this for later + + OSDetection.getOS(); + view = dirTree; + command = new CmdExecutor(); + } + /** + * 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 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/IronFile.java b/src/main/java/directory/IronFile.java similarity index 88% rename from src/main/java/IronFile.java rename to src/main/java/directory/IronFile.java index 45c3037..011eb9c 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; @@ -7,15 +8,20 @@ * 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; public IronFile(String pathname) { super(pathname); isRoot = (getParent() == null); + filter = new IronFileFilter(); } public IronFile(File file) { super(file.getPath()); isRoot = (getParent() == null); + filter = new IronFileFilter(); + } @Override 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..461a438 --- /dev/null +++ b/src/main/java/launcher/Controller.java @@ -0,0 +1,75 @@ +package launcher; + +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 directory.FolderViewManager; +import directory.IronFile; +import javafx.fxml.FXML; +import javafx.scene.control.MenuItem; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeView; +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.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 MenuItem fileDropboxSignin; + @FXML private TreeView dirTree; + @FXML private MenuItem toolsTagFiles; + @FXML private MenuItem toolsDeleteTags; + @FXML private ResourceBundle resources; + + @FXML private void initialize() { + final FolderViewManager manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best + IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives + manager.setRootDirectory(hardDrives); + + 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(); + } + }); + + /* DropboxController dbManager = new DropboxController(); + try { + dbManager.test(); + } catch (DbxException e) { + e.printStackTrace(); + }*/ +// directory.IronFile homeDir = new directory.IronFile(System.getProperty("user.home")); // use this for specific directory +// manager.setRootDirectory(homeDir); + } +} + diff --git a/src/main/java/Main.java b/src/main/java/launcher/Main.java similarity index 84% rename from src/main/java/Main.java rename to src/main/java/launcher/Main.java index 151fb3b..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,8 +17,8 @@ public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ -// setUserAgentStylesheet(STYLESHEET_CASPIAN); - Parent root = FXMLLoader.load(getClass().getResource("/main/resources/StartPage.fxml")); + 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 diff --git a/src/main/java/utils/CmdExecutor.java b/src/main/java/utils/CmdExecutor.java new file mode 100644 index 0000000..f9e93f2 --- /dev/null +++ b/src/main/java/utils/CmdExecutor.java @@ -0,0 +1,39 @@ +package utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Created by kristopherguzman on 2/19/16. + */ +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 + BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); + + String line = outputReader.readLine(); + String error = errorReader.readLine(); + + 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/utils/IronFileFilter.java b/src/main/java/utils/IronFileFilter.java new file mode 100644 index 0000000..763d585 --- /dev/null +++ b/src/main/java/utils/IronFileFilter.java @@ -0,0 +1,31 @@ +package utils; + +import java.io.FilenameFilter; +import java.io.File; +import java.nio.file.Files; + +/** + * Created by kristopherguzman on 2/19/16. + */ +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) { + + } + + 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/utils/OSDetection.java b/src/main/java/utils/OSDetection.java new file mode 100644 index 0000000..ca37337 --- /dev/null +++ b/src/main/java/utils/OSDetection.java @@ -0,0 +1,31 @@ +package utils; + +/** + * Created by kristopherguzman on 2/19/16. + * + * This is a static utlity class to detect the OS. Program methods may have to adjust to the OS. + */ +public class OSDetection { + + private OSDetection() {} + + 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..623a458 --- /dev/null +++ b/src/main/java/webapp/DropboxController.java @@ -0,0 +1,29 @@ +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(); + } +} diff --git a/src/main/resources/StartPage.fxml b/src/main/resources/StartPage.fxml index 17cb614..6967c50 100644 --- a/src/main/resources/StartPage.fxml +++ b/src/main/resources/StartPage.fxml @@ -2,28 +2,39 @@ - - - - - - - + + + + + + + + + + + + + + + + + - + + - - + + 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