Fxml #8
|
@ -1,100 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.Separator?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.tournamentListController">
|
||||
<children>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
<Label fx:id="tournierListTitle" text="Bestehende Turniere">
|
||||
<font>
|
||||
<Font name="System Bold" size="21.0" />
|
||||
</font>
|
||||
<VBox.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</VBox.margin>
|
||||
</Label>
|
||||
<ListView fx:id="tournierListView" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets />
|
||||
</VBox.margin>
|
||||
</ListView>
|
||||
<Button fx:id="openBtn" mnemonicParsing="false" onAction="#openTournier" text="Öffnen">
|
||||
<VBox.margin>
|
||||
<Insets bottom="20.0" top="40.0" />
|
||||
</VBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
<HBox.margin>
|
||||
<Insets left="40.0" />
|
||||
</HBox.margin>
|
||||
</VBox>
|
||||
<Separator orientation="VERTICAL" prefHeight="200.0">
|
||||
<HBox.margin>
|
||||
<Insets left="10.0" right="10.0" />
|
||||
</HBox.margin>
|
||||
</Separator>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
<Label fx:id="newTournamentFormularTitle" text="Neues Turnier erstellen">
|
||||
<font>
|
||||
<Font name="System Bold" size="21.0" />
|
||||
</font>
|
||||
<VBox.margin>
|
||||
<Insets bottom="40.0" />
|
||||
</VBox.margin></Label>
|
||||
<Separator prefWidth="200.0" />
|
||||
<GridPane fx:id="grid" prefHeight="200.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label fx:id="turnierNameLabel" styleClass="lableGrid" text="Turnier Name:">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField styleClass="inputGrid" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Label fx:id="tournierModLabel" styleClass="lableGrid" text="Turnier Modus:" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<ChoiceBox fx:id="modusChoiceBox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<Button fx:id="createBtn" alignment="TOP_LEFT" mnemonicParsing="false" onAction="#createTournament" text="Erstellen" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets bottom="20.0" top="40.0" />
|
||||
</VBox.margin></Button>
|
||||
</children>
|
||||
<HBox.margin>
|
||||
<Insets right="40.0" />
|
||||
</HBox.margin>
|
||||
</VBox>
|
||||
</children>
|
||||
|
||||
|
||||
</HBox>
|
|
@ -3,16 +3,24 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
public abstract class FXController {
|
||||
Tournament tournament;
|
||||
Factory factory;
|
||||
FileIO fileIO;
|
||||
|
||||
public void setup(Tournament tournament, Factory factory){
|
||||
public void setup(Tournament tournament, FileIO fileIO, Factory factory){
|
||||
this.tournament = tournament;
|
||||
this.fileIO = fileIO;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public abstract void loadContent();
|
||||
|
||||
protected Tournament getTournament() {
|
||||
return tournament;
|
||||
}
|
||||
|
||||
protected FileIO getFileIO() {
|
||||
return fileIO;
|
||||
}
|
||||
|
||||
protected Factory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Border;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Factory {
|
||||
private Tournament tournament;
|
||||
private FileIO fileIO;
|
||||
|
||||
|
||||
public Factory(){
|
||||
|
||||
public Factory(FileIO fileIO){
|
||||
this.fileIO = fileIO;
|
||||
}
|
||||
|
||||
public Tournament getTournament() {
|
||||
|
@ -38,7 +35,7 @@ public class Factory {
|
|||
}
|
||||
|
||||
public void loadTournamentList(BorderPane pane){
|
||||
setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml"));
|
||||
TournamentListController controller = (TournamentListController) setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml"));
|
||||
}
|
||||
|
||||
//Can be used to Open new Scene in same Stage.
|
||||
|
@ -47,16 +44,19 @@ public class Factory {
|
|||
setCenterOfBorderPane(pane, getClass().getResource("participantAddFormular/participantFormular.fxml"));
|
||||
}
|
||||
|
||||
private void setCenterOfBorderPane(BorderPane pane, URL location) {
|
||||
private FXController setCenterOfBorderPane(BorderPane pane, URL location) {
|
||||
FXController controller = null;
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(location);
|
||||
pane.setCenter(loader.load());
|
||||
FXController controller = loader.getController();
|
||||
controller.setup(tournament, this);
|
||||
controller = loader.getController();
|
||||
controller.setup(tournament, fileIO, this);
|
||||
controller.loadContent();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//TODO handle and logging?
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -32,9 +34,13 @@ public class FileIO {
|
|||
}
|
||||
}
|
||||
|
||||
public List<File> getList() {
|
||||
public List<TournamentFile> getList() {
|
||||
logger.fine("Creating a List out of all Files in the save directory and returning it");
|
||||
return Arrays.asList(saves.listFiles());
|
||||
List<TournamentFile> tournaments = new ArrayList<>();
|
||||
for(File tournament : saves.listFiles()){
|
||||
tournaments.add(new TournamentFile(tournament.toURI()));
|
||||
}
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,4 +116,17 @@ public class FileIO {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public class TournamentFile extends File{
|
||||
|
||||
public TournamentFile(URI uri) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String name = getName();
|
||||
return name.split("\\.")[0];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung.main;
|
||||
|
||||
import ch.zhaw.projekt2.turnierverwaltung.Factory;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
|
@ -12,10 +13,12 @@ import java.awt.*;
|
|||
import java.io.IOException;
|
||||
|
||||
public class MainWindow extends Application {
|
||||
private Factory factory = new Factory(); //TODO make it private!
|
||||
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + "/tournierverwaltung_angrynerds");
|
||||
private Factory factory = new Factory(fileIO); //TODO make it private!
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
|
||||
BorderPane pane = factory.loadMainWindow();
|
||||
factory.loadTournamentList(pane);
|
||||
|
||||
|
|
|
@ -15,4 +15,9 @@ public class MainWindowController extends FXController {
|
|||
void closeApplication(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadContent() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList;
|
||||
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.main.MainWindow;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
|
@ -10,7 +14,9 @@ import javafx.scene.control.Label;
|
|||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.GridPane;
|
||||
|
||||
public class tournamentListController extends FXController {
|
||||
import java.io.File;
|
||||
|
||||
public class TournamentListController extends FXController {
|
||||
|
||||
@FXML
|
||||
private Button createBtn;
|
||||
|
@ -31,7 +37,7 @@ public class tournamentListController extends FXController {
|
|||
private Label tournierListTitle;
|
||||
|
||||
@FXML
|
||||
private ListView<?> tournierListView;
|
||||
private ListView<File> tournierListView;
|
||||
|
||||
@FXML
|
||||
private Label tournierModLabel;
|
||||
|
@ -49,5 +55,13 @@ public class tournamentListController extends FXController {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadContent() {
|
||||
ObservableList<File> tournamentFiles = FXCollections.observableArrayList();
|
||||
for(File tournament : getFileIO().getList()){
|
||||
tournamentFiles.add(tournament);
|
||||
}
|
||||
tournierListView.setItems(tournamentFiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular.participantFormularController">
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular.ParticipantFormularController">
|
||||
<children>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.tournamentListController">
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController">
|
||||
<children>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AppTest {
|
||||
@Test void appHasAGreeting() {
|
||||
App classUnderTest = new App();
|
||||
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ class FileIOTest {
|
|||
|
||||
@Test
|
||||
void getList() {
|
||||
List<File> tournaments = io.getList();
|
||||
List<FileIO.TournamentFile> tournaments = io.getList();
|
||||
assertEquals("empty.txt", tournaments.get(0).getName());
|
||||
assertEquals("test1.txt", tournaments.get(1).getName());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue