Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d13dbcb45 | ||
|
|
02456bc5bf | ||
|
|
f3495d28d6 |
@@ -6,18 +6,8 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.main.MainWindow;
|
||||
import javafx.application.Application;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new LogConfiguration(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds",
|
||||
"ch" + System.getProperty("file.separator") + "zhaw" + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") +
|
||||
"turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Application.launch(MainWindow.class,args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -15,7 +18,7 @@ public class FileIO {
|
||||
private File mainDir;
|
||||
private File saves;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName());
|
||||
private static final Logger logger = Logger.getLogger(FileIO.class.getName());
|
||||
|
||||
/**
|
||||
* Constructor initiates the Directory and creates a save folder if not already existing.
|
||||
@@ -40,7 +43,6 @@ public class FileIO {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list with all save Files that are located inside the save folder.
|
||||
*
|
||||
@@ -49,26 +51,18 @@ public class FileIO {
|
||||
public ObservableList<TournamentFile> getList() {
|
||||
logger.fine("Creating a List out of all Files in the save directory and returning it");
|
||||
ObservableList<TournamentFile> tournamentFiles = FXCollections.observableArrayList();
|
||||
for (File tournament : saves.listFiles()) {
|
||||
for(File tournament : saves.listFiles()){
|
||||
tournamentFiles.add(new TournamentFile(tournament.toURI()));
|
||||
}
|
||||
return tournamentFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if a tournament with the existing name already exists.
|
||||
* @param name that is being checked
|
||||
* @return true if the name exists already false if the name is unique
|
||||
*/
|
||||
public boolean tournamentExists(String name) {
|
||||
logger.finer("checking for duplicate name in tournament List");
|
||||
for (TournamentFile file : getList()) {
|
||||
if (file.toString().toLowerCase().equals(name.toLowerCase())) {
|
||||
logger.fine(name + " is an already existing name in the list");
|
||||
public boolean tournamentExists(String name){
|
||||
for(TournamentFile file : getList()) {
|
||||
if(file.toString().toLowerCase().equals(name.toLowerCase())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
logger.fine(name + " is an unique name in the list");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,13 +90,13 @@ public class FileIO {
|
||||
logger.finer("Starting to read tournament File");
|
||||
tournament = (Tournament) in.readObject();
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.severe("Could not find tournament File" + e);
|
||||
logger.severe("Could not find tournament File");
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to read File" + tournamentFile.getName());
|
||||
throw new IOException("Error while reading File", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.severe("No definition for the class with the specified name could be found" + e);
|
||||
logger.severe("No definition for the class with the specified name could be found");
|
||||
throw new ClassNotFoundException("No definition for the class with the specified name could be found", e);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
@@ -110,7 +104,7 @@ public class FileIO {
|
||||
logger.finer("Trying to close input stream");
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to close input stream" + e);
|
||||
logger.severe("Failed to close input stream");
|
||||
throw new IOException("Error while closing input stream", e);
|
||||
}
|
||||
}
|
||||
@@ -139,20 +133,20 @@ public class FileIO {
|
||||
newSave.createNewFile();
|
||||
out = new ObjectOutputStream(new FileOutputStream(newSave));
|
||||
out.writeObject(tournament);
|
||||
System.out.println("Save File " + tournament.getName() + ".txt being saved to " + saves.getAbsolutePath());
|
||||
System.out.println("Save File" + tournament.getName() + ".txt being saved to " + saves.getAbsolutePath());
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.severe("Could not find tournament File" + e);
|
||||
logger.severe("Could not find tournament File");
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to write File " + tournament.getName() + e);
|
||||
logger.severe("Failed to write File" + tournament.getName());
|
||||
throw new IOException("Error while writing File", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to close output stream" + e);
|
||||
logger.severe("Failed to close output stream");
|
||||
throw new IOException("Error while closing output stream", e);
|
||||
}
|
||||
}
|
||||
@@ -179,28 +173,14 @@ public class FileIO {
|
||||
throw new FileNotFoundException("File deletion unsuccessful");
|
||||
}
|
||||
}
|
||||
|
||||
public class TournamentFile extends File{
|
||||
|
||||
/**
|
||||
* TournamentFile Class is in use to add missing functionality that is
|
||||
*/
|
||||
public class TournamentFile extends File {
|
||||
|
||||
/**
|
||||
* Only job the constructor got is to initialize it via its superclass. See java.io.File Documentation for more info.
|
||||
*
|
||||
* @param uri abstract pathname needed for its superclass to intialize the file accordingly.
|
||||
*/
|
||||
public TournamentFile(URI uri) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method overrides toString to return the names of the tournaments without having .txt endings.
|
||||
*
|
||||
* @return String without a txt ending
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString(){
|
||||
return getName().split("\\.")[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.*;
|
||||
|
||||
|
||||
public class LogConfiguration {
|
||||
private static final Logger logger = Logger.getLogger(LogConfiguration.class.getCanonicalName());
|
||||
private final File mainDir;
|
||||
|
||||
public LogConfiguration(String saveLocation, String logFileLocation) throws IOException {
|
||||
logger.fine("Starts setting up a main directory in which a folder with the log files will be placed, if not already exists");
|
||||
this.mainDir = new File(saveLocation);
|
||||
if (!mainDir.exists()) {
|
||||
logger.fine("Creating main directory for log ordner in given path" + saveLocation);
|
||||
mainDir.mkdir();
|
||||
} else {
|
||||
logger.finer("main directory for log folder already exists");
|
||||
}
|
||||
|
||||
File saves = new File(mainDir, "log_files");
|
||||
if (!saves.exists()) {
|
||||
saves.mkdir();
|
||||
logger.fine("Creating log save directory");
|
||||
} else {
|
||||
logger.finer("log save directory already exists");
|
||||
}
|
||||
|
||||
String propertiesPath = "ch" + System.getProperty("file.separator") + "zhaw" + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") +
|
||||
"turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties";
|
||||
|
||||
logger.fine("Getting and reading logconfig file from " + propertiesPath);
|
||||
InputStream logConfig = this.getClass().getClassLoader().getResourceAsStream(propertiesPath);
|
||||
LogManager.getLogManager().readConfiguration(logConfig);
|
||||
|
||||
|
||||
Logger.getLogger(LogConfiguration.class.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ public interface Participant extends Serializable {
|
||||
String getName();
|
||||
void setName(String name);
|
||||
boolean equals(Participant participant);
|
||||
void change(Participant participant);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||
|
||||
public class Person implements Serializable {
|
||||
private final String NAME_MATCHING_REGEX = "[a-zA-Z]{1,20}";
|
||||
private final String PHONE_MATCHING_REGEX = "[\\+0-9]+";
|
||||
private final String PHONE_MATCHING_REGEX = "[\\+]?[0-9]*";
|
||||
|
||||
private String name;
|
||||
private String firstName;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
public class Place {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Place implements Serializable {
|
||||
private final String NAME_MATCHING_REGEX = "[a-zA-Z0-9]{1,20}";
|
||||
private String name;
|
||||
|
||||
@@ -18,4 +20,13 @@ public class Place {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean equals(Place place){
|
||||
return name.equals(place.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,27 @@ public class Player extends Person implements Participant{
|
||||
}
|
||||
|
||||
public void setDateOfBirth(String dateOfBirth) {
|
||||
String[] date = dateOfBirth.split("\\.");
|
||||
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
|
||||
if(dateOfBirth.length() > 0) {
|
||||
String[] date = dateOfBirth.split("\\.");
|
||||
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
|
||||
} else {
|
||||
dateOfBirth = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDateOfBirth(LocalDate dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Participant participant) {
|
||||
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Participant participant) {
|
||||
Player player = (Player) participant;
|
||||
setDateOfBirth(player.getDateOfBirth());
|
||||
setPhoneNumber(player.getPhoneNumber());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,24 @@ public class Team implements Participant {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setPlayers(List<Player> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Participant participant) {
|
||||
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Participant participant) {
|
||||
return;
|
||||
}
|
||||
|
||||
public Person getContactPerson() {
|
||||
return contactPerson;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class Tournament implements Serializable {
|
||||
@@ -27,12 +28,14 @@ public class Tournament implements Serializable {
|
||||
setName(name);
|
||||
setType(type);
|
||||
participants = new ArrayList<>();
|
||||
places = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||
for(Participant participant : participants){
|
||||
public void saveParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||
for(Participant participant: participants){
|
||||
if(participant.equals(newParticipant)){
|
||||
participants.remove(participant);
|
||||
participant.change(newParticipant);
|
||||
return;
|
||||
}
|
||||
}
|
||||
participants.add(newParticipant);
|
||||
@@ -52,11 +55,7 @@ public class Tournament implements Serializable {
|
||||
}
|
||||
|
||||
public void addPlace(Place newPlace) throws PlaceExistsException {
|
||||
for(Place place : places){
|
||||
if(place.equals(newPlace)){
|
||||
places.remove(place);
|
||||
}
|
||||
}
|
||||
places.removeIf(place -> place.equals(newPlace));
|
||||
places.add(newPlace);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class TournamentDecorator implements IsObservable{
|
||||
@@ -81,7 +80,7 @@ public class TournamentDecorator implements IsObservable{
|
||||
|
||||
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
|
||||
try {
|
||||
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||
tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||
informListener();
|
||||
} catch (Tournament.ParticipantExistsException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainWindow extends Application {
|
||||
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds");
|
||||
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + "/tournierverwaltung_angrynerds");
|
||||
private TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO);
|
||||
private Factory factory = new Factory(fileIO, tournamentDecorator); //TODO make it private!
|
||||
private FactoryDecorator factoryDecorator;
|
||||
|
||||
+8
@@ -79,6 +79,14 @@ public class ParticipantFormularController extends FXController {
|
||||
@FXML
|
||||
void saveParticipant(ActionEvent event) {
|
||||
getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
|
||||
clearFormular();
|
||||
}
|
||||
|
||||
private void clearFormular() {
|
||||
firstNameTextField.clear();
|
||||
participantNameTextField.clear();
|
||||
phoneNumberTextField.clear();
|
||||
birthDateTextField.clear();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
||||
+5
-18
@@ -18,21 +18,9 @@ public class PlacesFormularController extends FXController {
|
||||
@FXML
|
||||
private Button addBtn;
|
||||
|
||||
@FXML
|
||||
private Label birthDateLabel;
|
||||
|
||||
@FXML
|
||||
private TextField birthDateTextField;
|
||||
|
||||
@FXML
|
||||
private VBox changeBtn;
|
||||
|
||||
@FXML
|
||||
private Label firstNameLabel;
|
||||
|
||||
@FXML
|
||||
private TextField firstNameTextField;
|
||||
|
||||
@FXML
|
||||
private GridPane grid;
|
||||
|
||||
@@ -58,12 +46,6 @@ public class PlacesFormularController extends FXController {
|
||||
@FXML
|
||||
private TextField placeNameTextField;
|
||||
|
||||
@FXML
|
||||
private Label phoneNumberLabel;
|
||||
|
||||
@FXML
|
||||
private TextField phoneNumberTextField;
|
||||
|
||||
@FXML
|
||||
private Button saveBtn;
|
||||
|
||||
@@ -76,6 +58,11 @@ public class PlacesFormularController extends FXController {
|
||||
@FXML
|
||||
void savePlace(ActionEvent event) {
|
||||
getTournamentDecorator().savePlace(placeNameTextField.getText());
|
||||
clearFormular();
|
||||
}
|
||||
|
||||
private void clearFormular() {
|
||||
placeNameTextField.clear();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
## configures handlers
|
||||
java.util.logging.ConsoleHandler.level = ALL
|
||||
|
||||
## File handler configuration
|
||||
## see https://docs.oracle.com/en/java/javase/11/docs/api/java.logging/java/util/logging/FileHandler.html
|
||||
java.util.logging.FileHandler.level = ALL
|
||||
# %g = generation number, %u = unique number to resolve conflicts
|
||||
java.util.logging.FileHandler.pattern = tournierverwaltung_angrynerds/log_files/log-%g-%u.log
|
||||
# use SimpleFormatter instead of default XMLFormatter
|
||||
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
|
||||
java.util.logging.FileHandler.encoding = UTF-8
|
||||
# max log file size in byte before switching to next generation (=1kB); 0=unlimited
|
||||
java.util.logging.FileHandler.limit = 2048
|
||||
# max number of generations (%g) before overwriting (5 -> 0..4)
|
||||
java.util.logging.FileHandler.count=10
|
||||
java.util.logging.FileHandler.append=true
|
||||
|
||||
## configures Formatter
|
||||
java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %5$s {%2$s}%6$s%n
|
||||
|
||||
## configures default log level (for all loggers, if not overwritten below)
|
||||
.level = INFO
|
||||
|
||||
## configure root logger ""
|
||||
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
||||
level = FINE
|
||||
|
||||
|
||||
|
||||
#ch.zhaw.prog2.turnierverwaltung.useParentHandlers = false
|
||||
|
||||
# logger level for individual classes
|
||||
ch.zhaw.projekt2.turnierverwaltung.FileIO.level = FINEST
|
||||
+7
-24
@@ -1,18 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?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:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController">
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController">
|
||||
<children>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
@@ -55,7 +48,7 @@
|
||||
</Separator>
|
||||
<VBox fx:id="changeBtn" alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
<Label fx:id="newplaceFormularTitle" text="Teilnehmer ändern/erstellen">
|
||||
<Label fx:id="newplaceFormularTitle" text="Ort ändern/erstellen">
|
||||
<font>
|
||||
<Font name="System Bold" size="21.0" />
|
||||
</font>
|
||||
@@ -86,16 +79,6 @@
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Label fx:id="firstNameLabel" styleClass="lableGrid" text="Vorname" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField fx:id="firstNameTextField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<TextField fx:id="phoneNumberTextField" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<TextField fx:id="birthDateTextField" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
<Label fx:id="phoneNumberLabel" text="Telefonnummer" GridPane.rowIndex="2" />
|
||||
<Label fx:id="birthDateLabel" text="Geb. Datum" GridPane.rowIndex="3" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<Separator prefWidth="200.0" />
|
||||
|
||||
Reference in New Issue
Block a user