From 7243188d3a44ab8c4329a8ebd19018e21c6bdb94 Mon Sep 17 00:00:00 2001 From: Brian Patino Date: Thu, 3 Mar 2016 22:59:25 -0500 Subject: [PATCH] Add Tag by Meta-data and Other Button Events * add view of current tags * add new simpler gui * add fxids to some fields --- src/main/java/directory/IronFile.java | 43 +++- src/main/java/launcher/Controller.java | 74 +++--- src/main/java/launcher/Main.java | 3 +- src/main/java/utils/CmdExecutor.java | 4 - src/main/resources/SimpleGUI.fxml | 320 +++++++++++++++++++++++++ 5 files changed, 397 insertions(+), 47 deletions(-) create mode 100644 src/main/resources/SimpleGUI.fxml diff --git a/src/main/java/directory/IronFile.java b/src/main/java/directory/IronFile.java index 6b33120..ab849c9 100644 --- a/src/main/java/directory/IronFile.java +++ b/src/main/java/directory/IronFile.java @@ -3,6 +3,14 @@ import utils.IronFileFilter; import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.UserDefinedFileAttributeView; import java.util.List; /** @@ -12,17 +20,27 @@ public class IronFile extends File { private boolean isRoot = true; public IronFileFilter filter; private String tag; + final private String ATTR_TYPE = "tags"; + private UserDefinedFileAttributeView fileAttributeView; + /** + * Construct an IronFile that extends File + * @param pathname the path where the file is located + * */ public IronFile(String pathname) { super(pathname); isRoot = (getParent() == null); - filter = new IronFileFilter(); +// filter = new IronFileFilter(); } + /** + * Construct an IronFile that extends File. This is an overloaded method + * @param file file that can be passed instead of path (string) + * */ public IronFile(File file) { super(file.getPath()); isRoot = (getParent() == null); - filter = new IronFileFilter(); - +// filter = new IronFileFilter(); + fileAttributeView = Files.getFileAttributeView(this.toPath(), UserDefinedFileAttributeView.class); } @Override @@ -63,17 +81,26 @@ public void setRoot(boolean root) { @Override public String toString() { - if (isRoot) { - return this.getAbsolutePath(); - } else { - return this.getName(); - } + return (isRoot) ? this.getAbsolutePath() : this.getName(); } public String getTag() { + try { + ByteBuffer buf = ByteBuffer.allocate(fileAttributeView.size(ATTR_TYPE)); + fileAttributeView.read(ATTR_TYPE, buf); + buf.flip(); + tag = Charset.defaultCharset().decode(buf).toString(); + } catch(IOException e) { + e.printStackTrace(); + } return tag; } public void setTag(String tag) { this.tag = tag; + try { + fileAttributeView.write(ATTR_TYPE, Charset.defaultCharset().encode(tag)); // Set file tag attributes + } catch (IOException e) { + e.printStackTrace(); + } } } \ No newline at end of file diff --git a/src/main/java/launcher/Controller.java b/src/main/java/launcher/Controller.java index 87e9e8f..13df311 100644 --- a/src/main/java/launcher/Controller.java +++ b/src/main/java/launcher/Controller.java @@ -35,51 +35,28 @@ public class Controller{ @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 MenuItem toolsTagFiles; @FXML private ResourceBundle resources; - @FXML private Button btnAddTag; + @FXML private TreeView dirTree; @FXML private TextField txtAddTag; @FXML private TextField txtSearchTag; - @FXML private Button btnSearchTag; - @FXML private ListView viewTags; private FolderViewManager manager; @FXML private MenuBar menubar; @FXML private Label dragHereLabel; + @FXML private ListView viewTags; + @FXML private ListView viewExistTags; + @FXML private void initialize() { manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best - IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives +// IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives menubar.setUseSystemMenuBar(true); //allows use of native menu bars, luckily an easy 1 liner // manager.setRootDirectory(hardDrives); //Ideally only show tree view of files the user drags in -// initializeSceneEvents(); // initialize Drag and Drop feature } /** - * 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(txtSearchTag.getText()); - viewTags.setItems(taggedItems); - } - /** - * Action on click event that will delete all tag information from selected files. + * Initialize the drag and Drop event and other scene events * */ - @FXML private void eventDeleteTags() { - ObservableList> selectedItems = dirTree.getSelectionModel().getSelectedItems(); // get list of selected files - manager.deleteAllTags(selectedItems); - } public void initializeSceneEvents() { Scene scene = dirTree.getScene(); scene.setOnDragOver(args -> { @@ -104,9 +81,40 @@ public void initializeSceneEvents() { args.setDropCompleted(success); }); } + /** + * 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()); + ObservableList tagsList = FXCollections.observableArrayList(txtAddTag.getText()); + tagsList.addAll(viewExistTags.getItems()); + viewExistTags.setItems(tagsList); + } + @FXML private void eventSearchRemoveTag() { -/* public void setScene(Scene scene) { - this.scene = scene; - }*/ + } + /** + * On Click event that will search and display files based on entered tag + * */ + @FXML private void eventSearchTag() { + ObservableList taggedItems = manager.getTaggedItems(txtSearchTag.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); + } + + @FXML private void eventRemoveTag() { +// ObservableList> treeIronFile + } } diff --git a/src/main/java/launcher/Main.java b/src/main/java/launcher/Main.java index 13256d5..1fa4d5e 100644 --- a/src/main/java/launcher/Main.java +++ b/src/main/java/launcher/Main.java @@ -19,7 +19,7 @@ public class Main extends Application { public void start(Stage primaryStage) throws Exception{ // setUserAgentStylesheet(STYLESHEET_CASPIAN); FXMLLoader loader = new FXMLLoader(); - Parent root = loader.load(getClass().getResource("/StartPage.fxml").openStream()); + Parent root = loader.load(getClass().getResource("/SimpleGUI.fxml").openStream()); Controller controller = loader.getController(); primaryStage.setTitle("Iron-gate!"); Scene scene = new Scene(root, 990, 700); @@ -28,7 +28,6 @@ public void start(Stage primaryStage) throws Exception{ scene.getStylesheets().clear(); // clear any styles // scene.getStylesheets().add("/main/resources/mainStyle.css"); // absolute path primaryStage.show(); // show the initialized stage - } public static void main(String[] args) { launch(args); diff --git a/src/main/java/utils/CmdExecutor.java b/src/main/java/utils/CmdExecutor.java index f9e93f2..fe9be4d 100644 --- a/src/main/java/utils/CmdExecutor.java +++ b/src/main/java/utils/CmdExecutor.java @@ -8,9 +8,6 @@ * 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}; @@ -30,7 +27,6 @@ public String run(String cmd) throws IOException { while(error != null) { System.out.println("error output: " + error); error = errorReader.readLine(); - } outputReader.close(); errorReader.close(); diff --git a/src/main/resources/SimpleGUI.fxml b/src/main/resources/SimpleGUI.fxml new file mode 100644 index 0000000..d5cbaa4 --- /dev/null +++ b/src/main/resources/SimpleGUI.fxml @@ -0,0 +1,320 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+
+ + +
+ + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+
+ + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + +
+
+
+ + + + + + +
+ + + + + + + + + + + + + + +
+ + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+
+
+
+ + + + + +
+
+
+ + + +
+
+ + + + + +
+ +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+