summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java2/aufgabe05/view
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-04 22:11:28 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-04 22:11:28 +0200
commit3b5728de6f2d8d2852fbb86fa8cac21e6dccc19b (patch)
tree54965319a9aafeb294dac8e36e4ce1371ec76ef3 /src/de/fhswf/in/inf/java2/aufgabe05/view
parentaf7b9bd6a962b9a290fc5d78c08c83653961811f (diff)
downloadJava2-3b5728de6f2d8d2852fbb86fa8cac21e6dccc19b.tar.gz
Java2-3b5728de6f2d8d2852fbb86fa8cac21e6dccc19b.zip
Build a file browser looking like Finder
Diffstat (limited to 'src/de/fhswf/in/inf/java2/aufgabe05/view')
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverview.fxml17
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverviewController.java55
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryTableView.java88
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayout.fxml31
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayoutController.java48
5 files changed, 239 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverview.fxml b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverview.fxml
new file mode 100644
index 0000000..5c1c3ed
--- /dev/null
+++ b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverview.fxml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import java.lang.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+<?import javafx.scene.layout.AnchorPane?>
+
+<AnchorPane xmlns="http://javafx.com/javafx/8.0.45" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.fhswf.in.inf.java2.aufgabe05.view.DirectoryOverviewController">
+ <children>
+ <SplitPane dividerPositions="0.25" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
+ <items>
+ <AnchorPane fx:id="leftPane" prefHeight="200.0" prefWidth="200.0" />
+ <AnchorPane fx:id="rightPane" prefHeight="200.0" prefWidth="200.0" />
+ </items>
+ </SplitPane>
+ </children>
+</AnchorPane>
diff --git a/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverviewController.java b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverviewController.java
new file mode 100644
index 0000000..d12efee
--- /dev/null
+++ b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryOverviewController.java
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.java2.aufgabe05.view;
+
+import java.io.File;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.TableView;
+import javafx.scene.layout.AnchorPane;
+import de.fhswf.fbin.java2fx.trees.DirectoryTreeView;
+
+/**
+ * TODO Add comment here
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public class DirectoryOverviewController
+{
+ @FXML
+ private AnchorPane leftPane;
+
+ @FXML
+ private AnchorPane rightPane;
+
+ private DirectoryTreeView dirTree;
+
+ private DirectoryTableView dirTab;
+
+ @FXML
+ private void initialize()
+ {
+ dirTree = new DirectoryTreeView();
+ leftPane.getChildren().add(dirTree);
+ AnchorPane.setTopAnchor(dirTree, 0.0);
+ AnchorPane.setBottomAnchor(dirTree, 0.0);
+ AnchorPane.setLeftAnchor(dirTree, 0.0);
+ AnchorPane.setRightAnchor(dirTree, 0.0);
+
+ dirTab = new DirectoryTableView(dirTree.getRoot().getValue());
+ rightPane.getChildren().add(dirTab);
+ AnchorPane.setTopAnchor(dirTab, 0.0);
+ AnchorPane.setBottomAnchor(dirTab, 0.0);
+ AnchorPane.setLeftAnchor(dirTab, 0.0);
+ AnchorPane.setRightAnchor(dirTab, 0.0);
+
+ dirTab.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
+
+ dirTree.getSelectionModel().selectedItemProperty()
+ .addListener((ov, oldParent, newParent) -> {
+ dirTab.getParentDirectoryProperty().set(newParent.getValue());
+ });
+ }
+}
diff --git a/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryTableView.java b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryTableView.java
new file mode 100644
index 0000000..0b76632
--- /dev/null
+++ b/src/de/fhswf/in/inf/java2/aufgabe05/view/DirectoryTableView.java
@@ -0,0 +1,88 @@
+/**
+ *
+ */
+
+package de.fhswf.in.inf.java2.aufgabe05.view;
+
+import java.io.File;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.collections.FXCollections;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.cell.PropertyValueFactory;
+import de.fhswf.fbin.java2fx.entities.FXFile;
+import de.fhswf.fbin.java2fx.tables.CheckBoxTableCellFactory;
+import de.fhswf.fbin.java2fx.tables.LocalDateTimeTableCellFactory;
+import de.fhswf.fbin.java2fx.tables.NumberTableCellFactory;
+
+/**
+ * TODO Add comment here
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public class DirectoryTableView extends TableView<FXFile>
+{
+ private SimpleObjectProperty<FXFile> parentDirectoryProperty;
+
+ public SimpleObjectProperty<FXFile> getParentDirectoryProperty()
+ {
+ return parentDirectoryProperty;
+ }
+
+ public DirectoryTableView(FXFile parentDirectory)
+ {
+ this.parentDirectoryProperty = new SimpleObjectProperty<FXFile>(parentDirectory);
+
+ // name column with default cell factory
+ TableColumn<FXFile, String> nameCol = new TableColumn<>("Name");
+ nameCol.setCellValueFactory(new PropertyValueFactory<FXFile, String>(
+ "name"));
+
+ // length column with custom number cell factory
+ TableColumn<FXFile, Number> lengthCol = new TableColumn<>("Length");
+ lengthCol.setCellValueFactory(new PropertyValueFactory<FXFile, Number>(
+ "length"));
+ lengthCol.setCellFactory(new NumberTableCellFactory<FXFile>());
+
+ // last modified column with custom date cell factory
+ TableColumn<FXFile, LocalDateTime> lastModifiedCol = new TableColumn<>(
+ "Last Modified");
+ lastModifiedCol
+ .setCellValueFactory(new PropertyValueFactory<FXFile, LocalDateTime>(
+ "lastModified"));
+ lastModifiedCol
+ .setCellFactory(new LocalDateTimeTableCellFactory<FXFile>());
+
+ // hidden attribute column with custom checkbox cell factory
+ TableColumn<FXFile, Boolean> hiddenCol = new TableColumn<>("Hidden");
+ hiddenCol
+ .setCellValueFactory(new PropertyValueFactory<FXFile, Boolean>(
+ "hidden"));
+ hiddenCol.setCellFactory(new CheckBoxTableCellFactory<FXFile>());
+
+ this.getColumns()
+ .addAll(nameCol, lengthCol, lastModifiedCol, hiddenCol);
+
+ this.parentDirectoryProperty
+ .addListener((ov, oldParent, newParent) -> {
+ updateContent(newParent);
+ });
+ }
+
+ private void updateContent(FXFile newParent)
+ {
+ File[] files = newParent.getFile().listFiles(f -> (f.isFile()));
+ List<FXFile> fxFiles = new ArrayList<>();
+ for (File file : files)
+ {
+ fxFiles.add(new FXFile(file));
+ }
+ this.getItems().setAll(FXCollections.observableArrayList(fxFiles));
+
+ }
+}
diff --git a/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayout.fxml b/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayout.fxml
new file mode 100644
index 0000000..c060ace
--- /dev/null
+++ b/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayout.fxml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import java.lang.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+<?import javafx.scene.layout.BorderPane?>
+
+<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.45" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.fhswf.in.inf.java2.aufgabe05.view.RootLayoutController">
+ <top>
+ <MenuBar BorderPane.alignment="CENTER">
+ <menus>
+ <Menu mnemonicParsing="false" text="Datei">
+ <items>
+ <MenuItem mnemonicParsing="false" onAction="#handelBeenden" text="Beenden" />
+ </items>
+ </Menu>
+ <Menu mnemonicParsing="false" text="Themes">
+ <items>
+ <MenuItem mnemonicParsing="false" onAction="#handelModena" text="MODENA" />
+ <MenuItem mnemonicParsing="false" onAction="#handelCaspian" text="CASPIAN" />
+ </items>
+ </Menu>
+ <Menu mnemonicParsing="false" text="Hilfe">
+ <items>
+ <MenuItem mnemonicParsing="false" onAction="#handelInfo" text="Info" />
+ </items>
+ </Menu>
+ </menus>
+ </MenuBar>
+ </top>
+</BorderPane>
diff --git a/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayoutController.java b/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayoutController.java
new file mode 100644
index 0000000..efc1a10
--- /dev/null
+++ b/src/de/fhswf/in/inf/java2/aufgabe05/view/RootLayoutController.java
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.java2.aufgabe05.view;
+
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
+
+
+/**
+ * TODO Add comment here
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public class RootLayoutController
+{
+ @FXML
+ private void handelBeenden()
+ {
+ Platform.exit();
+ }
+
+ @FXML
+ private void handelModena()
+ {
+ Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA);
+ }
+
+ @FXML
+ private void handelCaspian()
+ {
+ Application.setUserAgentStylesheet(Application.STYLESHEET_CASPIAN);
+ }
+
+ @FXML
+ private void handelInfo()
+ {
+ Alert info = new Alert(AlertType.INFORMATION);
+ info.setTitle("Info über das Programm");
+ info.setHeaderText("Programmierer: Stefan Suhren");
+ info.setContentText("Dieses Programm wurde programmiert.");
+ info.show();
+ }
+}