This commit is contained in:
Oystein 2021-02-22 10:11:56 +01:00
parent 8d00a00804
commit d0bddf7d46
6 changed files with 102 additions and 5 deletions

View File

@ -1,8 +1,14 @@
package app.controllers;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBoxTreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.CheckBoxTreeCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import jdk.jshell.execution.Util;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
@ -12,13 +18,51 @@ import app.model.Model;
import javafx.fxml.Initializable;
public class FiletreeController implements Initializable, Controller {
private EventBus eventBus;
private Model model;
@FXML
private TreeView filetree;
Image folder = new Image(getClass().getResourceAsStream("/graphics/folder.png"));
Image md = new Image(getClass().getResourceAsStream("/graphics/md.png"));
Image java = new Image(getClass().getResourceAsStream("/graphics/java.png"));
public void generateTree(File file, CheckBoxTreeItem<String> parent) {
if (file.isDirectory()) {
CheckBoxTreeItem<String> element = new CheckBoxTreeItem<String>(file.getName(), new ImageView(folder));
parent.getChildren().add(element);
for (File f : file.listFiles()) {
generateTree(f, element);
}
} else if ("java".equals(file.getName().substring(file.getName().lastIndexOf(".") + 1, file.getName().length()))) {
parent.getChildren().add(new CheckBoxTreeItem<>(file.getName(), new ImageView(java)));
} else if ("md".equals(file.getName().substring(file.getName().lastIndexOf(".") + 1, file.getName().length()))) {
parent.getChildren().add(new CheckBoxTreeItem<>(file.getName(), new ImageView(md)));
}
}
public void showTree(String inputChosen) {
CheckBoxTreeItem<String> root = new CheckBoxTreeItem<String>(inputChosen);
filetree.setShowRoot(false);
File fileInputChosen = new File(inputChosen);
File fileList[] = fileInputChosen.listFiles();
for (File f : fileList) {
generateTree(f, root);
}
filetree.setRoot(root);
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
// TODO: implement
showTree("C:\\Users\\Oyste\\OneDrive\\Skrivebord\\test");
}
@Override
@ -29,6 +73,7 @@ public class FiletreeController implements Initializable, Controller {
/**
* Links the controller to the global model
*
* @param model The model to be linked
*/
public void setModel(Model model) {

View File

@ -1,18 +1,69 @@
package app.controllers;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import com.google.common.eventbus.EventBus;
import app.model.Model;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuBar;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class MenubarController implements Initializable, Controller {
private EventBus eventBus;
private Model model;
@FXML
private MenuBar menubar;
@FXML
public String handleOpenFile() {
FileChooser fc = new FileChooser();
fc.setTitle("Open File");
Stage stage = (Stage) menubar.getScene().getWindow();
File chosenFile = fc.showOpenDialog(stage);
String corFormat = chosenFile.getAbsolutePath().replace("\\", "\\\\");
System.out.println(chosenFile.getAbsolutePath());
System.out.println(corFormat);
return corFormat;
}
@FXML
public String handleOpenProject() {
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("Open Project");
Stage stage = (Stage) menubar.getScene().getWindow();
File chosenDir = dc.showDialog(stage);
String corFormat = chosenDir.getAbsolutePath().replace("\\", "\\\\");
System.out.println(chosenDir.getAbsolutePath());
System.out.println(corFormat);
return corFormat;
}
// @FXML
// public void handleSaveFile() {
// FileChooser fc = new FileChooser();
// fc.setTitle("Save File");
// Stage stage = (Stage) menubar.getScene().getWindow();
// FileChooser.ExtensionFilter extentionjava = new
// FileChooser.ExtensionFilter(".java");
// FileChooser.ExtensionFilter extentionmd = new
// FileChooser.ExtensionFilter(".md");
// fc.getExtensionFilters().addAll(extentionjava, extentionmd);
// fc.showOpenDialog(stage);
// }
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
// TODO: implement
@ -26,11 +77,11 @@ public class MenubarController implements Initializable, Controller {
/**
* Links the controller to the global model
*
* @param model The model to be linked
*/
public void setModel(Model model) {
this.model = model;
}
}

View File

@ -7,6 +7,7 @@
<?import javafx.scene.control.SeparatorMenuItem?>
<MenuBar
fx:id="menubar"
prefHeight="25.0"
xmlns="http://javafx.com/javafx/8.0.65"
xmlns:fx="http://javafx.com/fxml/1"
@ -17,8 +18,8 @@
<MenuItem mnemonicParsing="false" text="New File" accelerator="Shortcut+n"/>
<MenuItem mnemonicParsing="false" text="New Folder" accelerator="Shortcut+N"/>
<SeparatorMenuItem/>
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o"/>
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+O"/>
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o" onAction="#handleOpenFile"/>
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+O" onAction="#handleOpenProject"/>
<SeparatorMenuItem/>
<MenuItem mnemonicParsing="false" text="Save" accelerator="Shortcut+s"/>
<MenuItem mnemonicParsing="false" text="Save as" accelerator="Shortcut+S"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B