filtre
This commit is contained in:
parent
8d00a00804
commit
d0bddf7d46
|
@ -1,8 +1,14 @@
|
||||||
package app.controllers;
|
package app.controllers;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.CheckBoxTreeItem;
|
||||||
import javafx.scene.control.TreeView;
|
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.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
@ -12,13 +18,51 @@ import app.model.Model;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
|
||||||
public class FiletreeController implements Initializable, Controller {
|
public class FiletreeController implements Initializable, Controller {
|
||||||
|
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private Model model;
|
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
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
showTree("C:\\Users\\Oyste\\OneDrive\\Skrivebord\\test");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +73,7 @@ public class FiletreeController implements Initializable, Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Links the controller to the global model
|
* Links the controller to the global model
|
||||||
|
*
|
||||||
* @param model The model to be linked
|
* @param model The model to be linked
|
||||||
*/
|
*/
|
||||||
public void setModel(Model model) {
|
public void setModel(Model model) {
|
||||||
|
|
|
@ -1,18 +1,69 @@
|
||||||
package app.controllers;
|
package app.controllers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
|
|
||||||
import app.model.Model;
|
import app.model.Model;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
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 {
|
public class MenubarController implements Initializable, Controller {
|
||||||
|
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private Model model;
|
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
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
@ -26,11 +77,11 @@ public class MenubarController implements Initializable, Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Links the controller to the global model
|
* Links the controller to the global model
|
||||||
|
*
|
||||||
* @param model The model to be linked
|
* @param model The model to be linked
|
||||||
*/
|
*/
|
||||||
public void setModel(Model model) {
|
public void setModel(Model model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<?import javafx.scene.control.SeparatorMenuItem?>
|
<?import javafx.scene.control.SeparatorMenuItem?>
|
||||||
|
|
||||||
<MenuBar
|
<MenuBar
|
||||||
|
fx:id="menubar"
|
||||||
prefHeight="25.0"
|
prefHeight="25.0"
|
||||||
xmlns="http://javafx.com/javafx/8.0.65"
|
xmlns="http://javafx.com/javafx/8.0.65"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
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 File" accelerator="Shortcut+n"/>
|
||||||
<MenuItem mnemonicParsing="false" text="New Folder" accelerator="Shortcut+N"/>
|
<MenuItem mnemonicParsing="false" text="New Folder" accelerator="Shortcut+N"/>
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o"/>
|
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o" onAction="#handleOpenFile"/>
|
||||||
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+O"/>
|
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+O" onAction="#handleOpenProject"/>
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
<MenuItem mnemonicParsing="false" text="Save" accelerator="Shortcut+s"/>
|
<MenuItem mnemonicParsing="false" text="Save" accelerator="Shortcut+s"/>
|
||||||
<MenuItem mnemonicParsing="false" text="Save as" 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 |
Loading…
Reference in New Issue