Skip to content

Commit

Permalink
Beginning of redesign. More user friendly, files and folders can now …
Browse files Browse the repository at this point in the history
…be drag and dropped into program.
  • Loading branch information
kag12017 committed Mar 1, 2016
1 parent 063fc09 commit f4f2f94
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 135 deletions.
75 changes: 69 additions & 6 deletions src/main/java/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import javafx.event.EventHandler;
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.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;

Expand All @@ -32,16 +33,27 @@ public class Controller{
@FXML private MenuItem fileTag;
@FXML private MenuItem fileExit;
@FXML private MenuItem editPreferences;
@FXML private MenuBar menubar;
@FXML private TreeView<IronFile> dirTree;
@FXML private MenuItem toolsTagFiles;
@FXML private MenuItem toolsDeleteTags;
@FXML private ResourceBundle resources;
@FXML private Label dragHereLabel;

FolderViewManager manager;

@FXML private void initialize() {
final FolderViewManager manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best

manager = new FolderViewManager(dirTree);

IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives
manager.setRootDirectory(hardDrives);
// 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<MouseEvent>() {

@Override
Expand Down Expand Up @@ -78,6 +90,57 @@ public void handle(ActionEvent event) {

});

}

public void initializeSceneEvents() {

Scene scene = dirTree.getScene();

scene.setOnDragOver(new EventHandler<DragEvent>() {

@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<DragEvent>() {

@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);

}

});

}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/IronFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package main.java;

import java.io.File;
import java.util.List;

/**
* This class extends the java File class and returns the filename for toString()
Expand Down Expand Up @@ -43,6 +44,14 @@ public static IronFile[] convertFiles(File[] files) {
return ironFiles;
}

public static IronFile[] convertFiles(List<File> files) {
IronFile[] ironFiles = new IronFile[files.size()];
for (int i = 0; i < files.size(); i++) {
ironFiles[i] = new IronFile(files.get(i));
}
return ironFiles;
}

public boolean isRoot() {
return isRoot;
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ 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"));

FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(getClass().getResource("/main/resources/StartPage.fxml").openStream());
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

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);
Expand Down
Loading

0 comments on commit f4f2f94

Please sign in to comment.