Merge Branch 'vmcontrol' Version 0.2.0 in Branch 'master'

This commit is contained in:
2021-03-17 20:43:57 +01:00
parent a2164dc303
commit e5c9e8dbf0
407 changed files with 68360 additions and 0 deletions

16
src/log4j.properties Normal file
View File

@ -0,0 +1,16 @@
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/log4j/log.out
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

27
src/tourplaner/Main.java Normal file
View File

@ -0,0 +1,27 @@
package tourplaner;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import tourplaner.business.ConfigHelper;
import java.io.IOException;
public class Main extends Application {
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(Main.class.getResource("tourplaner.fxml"));
primaryStage.setTitle(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "apptitle"));
primaryStage.setScene(new Scene(root, 600, 600));
primaryStage.show();
}
}

View File

@ -0,0 +1,177 @@
package tourplaner.business;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDate;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
public class AlertHelper {
/**
* Warning Dialog
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
*/
public static void warn(String title, String header, String msg){
alertType(Alert.AlertType.WARNING, title, header, msg);
}
/**
* Info Dialog
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
*/
public static void inform(String title, String header, String msg){
alertType(Alert.AlertType.INFORMATION, title, header, msg);
}
/**
* Info Dialog ohne Header
* @param title Title des Dialogs
* @param msg Nachricht des Dialogs
*/
public static void informNoHeader(String title, String msg){
inform(title, null, msg);
}
/**
* Error Dialog
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
*/
public static void error(String title, String header, String msg){
alertType(Alert.AlertType.ERROR, title, header, msg);
}
/**
* Ausgabe einer Exception in einem Dialog
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
* @param ex Die exception die ausgegeben werden soll
*/
public static void exerror(String title, String header, String msg, Exception ex){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(msg);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "exceptionstackheader"));
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
/**
*
* @param alertly Typ des Dialogs
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
*/
private static void alertType(Alert.AlertType alertly, String title, String header, String msg){
Alert alert = new Alert(alertly);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(msg);
alert.showAndWait();
}
/**
* Texteingabe
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
* @return Null bei keiner eingabe
*/
public static String inputText(String title, String header, String msg) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle(title);
dialog.setHeaderText(header);
dialog.setContentText(msg);
Optional<String> result = dialog.showAndWait();
AtomicReference<String> returnText = new AtomicReference<>("");
result.ifPresent(returnText::set);
if(!returnText.get().isEmpty()){
return returnText.get();
}else{
return null;
}
}
/**
* Positive Nummer eingabe. Wenn Convertierung zu int nicht klappt -> -1
* @param title Title des Dialogs
* @param header Header des Dialogs
* @param msg Nachricht des Dialogs
* @return -1 bei error sonst ein Int
*/
public static int inputNumber(String title, String header, String msg) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle(title);
dialog.setHeaderText(header);
dialog.setContentText(msg);
Optional<String> result = dialog.showAndWait();
AtomicReference<Integer> returnText = new AtomicReference<Integer>(-1);
result.ifPresent(s -> {
try {
int resultInt = Integer.parseInt(result.get());
returnText.set(resultInt);
}catch (NumberFormatException e){
AlertHelper.warn(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"), "Bitte nur Zahlen eingeben!", "Bitte geben sie nur Zahlen von 0 - 10 an!");
returnText.set(-1);
}
});
return returnText.get();
}
/**
* Date Picker Dialog, sobald ein Datum ausgewählt wurde, wird es automatisch bestätigt und der dialog geschlossen
* @param title Name des Dialogs
* @return Gewähltes datum
*/
public static LocalDate datePicker(String title){
final DatePicker datePicker = new DatePicker(LocalDate.now());
final Stage stage = new Stage();
AtomicReference<LocalDate> selectedDate = new AtomicReference<>();
datePicker.setOnAction(event -> {
LocalDate date = datePicker.getValue();
System.out.println("Selected date: " + date);
selectedDate.set(date);
stage.close();
});
stage.setScene(
new Scene(datePicker)
);
stage.showAndWait();
return selectedDate.get();
}
}

View File

@ -0,0 +1,95 @@
package tourplaner.business;
import org.ini4j.Wini;
import java.io.File;
import java.io.IOException;
/**
* Dient dem ein und auslesen von .ini Dateien
*/
public class ConfigHelper {
public static String standartConfig = "conf.ini"; // Config.ini befindet sich im Root Verzeichnis
/**
* Liest einen Int aus der Config aus
* @param filename Speicherort
* @param sectionName Sections Name
* @param optionName Options Name
* @return Den angeforderten String
*/
public static int getIniInt(String filename, String sectionName, String optionName){
Wini ini = null;
try {
ini = new Wini(new File(filename));
} catch (IOException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
assert ini != null;
return ini.get(sectionName, optionName, int.class);
}
/**
* Liest einen String aus der Config aus
* @param filename Speicherort
* @param sectionName Sections Name
* @param optionName Options Name
* @return Den angeforderten String
*/
public static String getIniString(String filename, String sectionName, String optionName){
Wini ini = null;
try {
ini = new Wini(new File(filename));
} catch (IOException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
assert ini != null;
return ini.get(sectionName, optionName, String.class);
}
/**
* Setzt ein String in der Config
* @param filename Speicherort
* @param sectionName Sections Name
* @param optionName Options Name
* @param value Wert der eingetragen werden soll
*/
public static void setIniString(String filename, String sectionName, String optionName, String value) {
Wini ini = null;
try {
ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
ini.store();
} catch (IOException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
}
/**
* Setzt ein int in der Config
* @param filename Speicherort
* @param sectionName Sections Name
* @param optionName Options Name
* @param value Wert der eingetragen werden soll
*/
public static void setIniInt(String filename, String sectionName, String optionName, int value){
Wini ini = null;
try {
ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
ini.store();
} catch (IOException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
}
/**
* Gibt den namen des standard Config file zurück
* @return Name des standard config files
*/
public static String getStandartConfig() {
return standartConfig;
}
}

View File

@ -0,0 +1,54 @@
package tourplaner.business;
import org.apache.log4j.*;
/**
* Hilft beim Logging mit log4j
*/
public class LogHelper{
/**
* Log info in file und Console
* @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/
public static void info(String msg, String name){
getLog(name).info(msg);
}
/**
* Log info in file und Console
* @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/
public static void warn(String msg, String name){
getLog(name).warn(msg);
}
/**
* Log info in file und Console
* @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/
public static void error(String msg, String name){
getLog(name).error(msg);
}
/**
* Log info in file und Console
* @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/
public static void fatal(String msg, String name){
getLog(name).fatal(msg);
}
/**
* Instanziert den Logger
* @param name Name des Loggers
* @return Den Logger
*/
private static Logger getLog(String name){
return Logger.getLogger(name); // Instanziert den Logger
}
}

View File

@ -0,0 +1,60 @@
package tourplaner.business;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
* Hilfsfunktionen für die verwendung der Postgres DB
*/
public class PostgresHelper {
/**
* Verbindet mit der Datenbank
* @return Das Connection Objekt
*/
public static Connection con() {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "url") + ":" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "port") + "/" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "dbname"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "user"), ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "pw"));
} catch (Exception e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
return c;
}
/**
* Führt ein Sql statement ohne rückgabe aus, mit message nachricht
* @param sql Sql command
* @param message Mesasage die vor dem Durchführen angezeigt wird
* @return True bei erfolg, sonst false
*/
public static boolean executeUpdateMessage(String sql, String message){
LogHelper.info(message, "PostgresHelper");
return executeUpdate(sql);
}
/**
* Führt ein Sql statement ohne rückgabe aus
* @param sql Sql command
* @return True bei erfolg, sonst false
*/
public static boolean executeUpdate(String sql){
Connection c = con();
Statement stmt;
try {
stmt = c.createStatement();
stmt.executeUpdate(sql);
stmt.close();
c.close();
} catch (Exception e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
return false;
}
return true;
}
}

View File

@ -0,0 +1,22 @@
package tourplaner.business;
import org.apache.log4j.Logger;
import tourplaner.data.DbConnect;
/**
* Haupt Logik des Tourplaners
*/
public class TourPlaner{
private Logger logger;
public TourPlaner(){
LogHelper.info(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "message"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "app"));
new DbConnect().init();
}
public String getMapJson(String start, String ziel){
return start + " " + ziel;
}
}

View File

@ -0,0 +1,37 @@
package tourplaner.data;
import tourplaner.business.PostgresHelper;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
/**
* Verwaltet die Datenbankverbindung zu dem Postgres Server
*/
public class DbConnect {
private Connection c;
private Statement stmt;
/**
* Erstellt alle Beispieldaten und simuliert somit den
* Verbindungsaufbau zu einer DB
*/
public DbConnect() {
this.c = null;
}
/**
* Erstellt alle Tabellen die für den Betrieb der Software bennötigt werden
* @return True bei erfolg, sonst error
*/
public boolean init() {
// TODO: 26.02.2021 Alle sql im init sind noch falsch
ArrayList<Boolean> errors = new ArrayList<>();
errors.add(PostgresHelper.executeUpdateMessage("CREATE TABLE IF NOT EXISTS USERS (username TEXT PRIMARY KEY NOT NULL, nachname TEXT NOT NULL, email TEXT NOT NULL, password TEXT NOT NULL, bio TEXT, image TEXT, coins integer default 20 not null)", "User Table created"));
return !errors.contains(false);
}
}

View File

@ -0,0 +1,51 @@
package tourplaner.object;
import jdk.jshell.spi.ExecutionControl;
import java.time.LocalDate;
import java.util.Date;
public class Log {
private String id, dauer;
private LocalDate datum;
private double strecke;
public Log(String id, String dauer, LocalDate datum, double strecke) {
this.id = id;
this.dauer = dauer;
this.datum = datum;
this.strecke = strecke;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDauer() {
return dauer;
}
public void setDauer(String dauer) {
this.dauer = dauer;
}
public LocalDate getDatum() {
return datum;
}
public void setDatum(LocalDate datum) {
this.datum = datum;
}
public double getStrecke() {
return strecke;
}
public void setStrecke(double strecke) {
this.strecke = strecke;
}
}

View File

@ -0,0 +1,110 @@
package tourplaner.object;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicReference;
/**
* Model einer Tour
*/
public class Tour {
private String dauer, mapJson, name, start, ziel;
private double strecke;
private ArrayList<Log> log;
public Tour(String name, String dauer, String mapJson, double strecke, String start, String ziel) {
this.dauer = dauer;
this.mapJson = mapJson;
this.strecke = strecke;
this.name = name;
this.start = start;
this.ziel = ziel;
this.log = new ArrayList<>();
}
/**
* Holt einen einzigen Log Eintrag anhand der Id
* @param id Id des Eintrags der zu besorgen ist
* @return Der gefundene Log Eintrag
*/
public Log getLog(String id){
AtomicReference<Log> returnLog = new AtomicReference<>();
this.log.forEach(s -> {
if(s.getId().equals(id)){
returnLog.set(s);
}
});
return returnLog.get();
}
/**
* Fügt ein Log Eintrag hinzu
* @param newLog Der neue Log Eintrag
*/
public void addLog(Log newLog){
this.log.add(newLog);
}
/**
* Gibt alle log Einträge zurück
* @return Alle log Einträge in einer Arraylist
*/
public ArrayList<Log> getLogs(){
return this.log;
}
/**
* Löscht einen Log eintrag anhand der ID
* @param id Id die zum löschen ist
*/
public void delLog(String id){
this.log.removeIf(s -> s.getId().equals(id));
}
public String getDauer() {
return dauer;
}
public void setDauer(String dauer) {
this.dauer = dauer;
}
public String getMapJson() {
return mapJson;
}
public void setMapJson(String mapJson) {
this.mapJson = mapJson;
}
public double getStrecke() {
return strecke;
}
public void setStrecke(double strecke) {
this.strecke = strecke;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getZiel() {
return ziel;
}
public void setZiel(String ziel) {
this.ziel = ziel;
}
}

View File

@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015, 2019, Gluon and/or its affiliates.
All rights reserved. Use is subject to license terms.
This file is available and licensed under the following license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
- Neither the name of Oracle Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tourplaner.ui.TourplanerController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
<Menu fx:id="menueFile" mnemonicParsing="false" text="Datei">
<items>
<MenuItem fx:id="beendenButton" mnemonicParsing="false" onAction="#quitApp" text="Beenden" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Bearbeiten">
<items>
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Optionen">
<items>
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Hilfe">
<items>
<MenuItem mnemonicParsing="false" onAction="#gitWebBrowser" text="Git Repo" />
<MenuItem mnemonicParsing="false" onAction="#javaDocBrowser" text="JavaDoc" />
<MenuItem mnemonicParsing="false" onAction="#doxygenDocBrowser" text="Doxygen Doc" />
</items>
</Menu>
</menus>
</MenuBar>
<HBox id="HBox" alignment="CENTER_LEFT" layoutX="10.0" layoutY="588.0" spacing="5.0">
<children>
<AnchorPane prefWidth="-1.0" HBox.hgrow="ALWAYS">
<children>
<Button fx:id="tourAdd" layoutX="58.0" mnemonicParsing="false" onAction="#addTour" text="+" />
<Label layoutX="14.0" layoutY="4.0" text="Tours" />
<Button fx:id="tourDel" layoutX="89.0" mnemonicParsing="false" onAction="#delTour" text="-" />
</children></AnchorPane>
<TextField fx:id="sucheInput" promptText="Suche..." />
<Button fx:id="sucheButton" mnemonicParsing="false" onAction="#suche" text="Suchen" />
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</HBox>
<SplitPane dividerPositions="0.21492204899777284" focusTraversable="true" prefHeight="522.0" prefWidth="900.0" VBox.vgrow="ALWAYS">
<items>
<AnchorPane prefWidth="239.0">
<children>
<ListView fx:id="TourListView" layoutX="-1.0" onMouseClicked="#tourListSelectedItem" prefHeight="520.0" prefWidth="190.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="496.0" prefWidth="620.0">
<items>
<VBox prefWidth="100.0">
<children>
<AnchorPane prefWidth="676.0">
<children>
<HBox id="HBox" alignment="CENTER_LEFT" prefHeight="7.0" prefWidth="44.0" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label text="Title:">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
<TextField fx:id="titleTextView" editable="false" />
</children>
</HBox>
</children>
</AnchorPane>
<AnchorPane prefWidth="200.0">
<children>
<TabPane fx:id="viewTabPane" layoutX="1.0" layoutY="69.0" prefWidth="702.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="-67.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab fx:id="kartenTab" text="Karte">
<content>
<AnchorPane />
</content></Tab>
<Tab fx:id="beschreibungTab" text="Beschreibung">
<content>
<AnchorPane>
<children>
<TableView fx:id="beschreibungTableView" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="nameCol" maxWidth="1.7976931348623157E308" minWidth="70.0" prefWidth="-1.0" text="Tourname" />
<TableColumn fx:id="dauerCol" maxWidth="1.7976931348623157E308" minWidth="40.0" prefWidth="-1.0" text="Dauer" />
<TableColumn fx:id="streckeCol" maxWidth="1.7976931348623157E308" minWidth="50.0" prefWidth="-1.0" text="Strecke" />
<TableColumn fx:id="startCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Startpunk" />
<TableColumn fx:id="zielCol" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="-1.0" text="Zielpunkt" />
</columns>
</TableView>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
</children>
</VBox>
<AnchorPane prefWidth="200.0">
<children>
<VBox prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<AnchorPane prefWidth="676.0">
<children>
<HBox id="HBox" alignment="CENTER_LEFT" prefWidth="702.0" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label text="Logs:">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
<Button mnemonicParsing="false" onAction="#addLog" text="+" textAlignment="CENTER">
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
<Button fx:id="logDel" mnemonicParsing="false" onAction="#delLog" prefWidth="21.0" text="-" textAlignment="CENTER">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Button>
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</HBox>
</children>
</AnchorPane>
<AnchorPane prefWidth="200.0">
<children>
<TableView fx:id="logTableView" onMouseClicked="#logItemSelected" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="logDatumCol" prefWidth="238.0" text="Datum" />
<TableColumn fx:id="logDauerCol" prefWidth="223.0" text="Dauer" />
<TableColumn fx:id="logStreckeCol" prefWidth="240.0" text="Entfernung" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
</children>
</VBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</items>
</SplitPane>
<HBox id="HBox" alignment="CENTER_LEFT" spacing="5.0" VBox.vgrow="NEVER">
<children>
<Label maxHeight="1.7976931348623157E308" maxWidth="-1.0" text="Left status" HBox.hgrow="ALWAYS">
<font>
<Font size="11.0" fx:id="x3" />
</font>
<textFill>
<Color red="0.625" green="0.625" blue="0.625" fx:id="x4" />
</textFill>
</Label>
<AnchorPane prefHeight="-1.0" prefWidth="-1.0" HBox.hgrow="ALWAYS" />
<Label font="$x3" maxWidth="-1.0" text="Right status" textFill="$x4" HBox.hgrow="NEVER" />
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</HBox>
</children>
</VBox>

View File

@ -0,0 +1,259 @@
package tourplaner.ui;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Orientation;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import tourplaner.business.AlertHelper;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import tourplaner.viewmodels.ViewModel;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
public class TourplanerController implements Initializable {
//VM
public ViewModel viewModel = new ViewModel();
//Tour list -> links
public ListView<String> TourListView = new ListView<>();
//Tabs zu Tour -> rechts oben
public TabPane viewTabPane;
public Tab kartenTab, beschreibungTab;
public TableView<Tour> beschreibungTableView;
public TableColumn<Tour, String> startCol, zielCol, dauerCol, streckeCol, nameCol;
public TextField titleTextView, sucheInput;
//Log -> rechts unten
public TableView<Log> logTableView;
public TableColumn<Log, String> logDauerCol, logStreckeCol, logDatumCol;
/**
* Öffnet github im standart browser
*
*/
@FXML
private void gitWebBrowser(){
openBrowser(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "hilfe", "gitrepo"), "Git");
}
/**
* Öffnet Java Doc im standart browser
*
*/
@FXML
private void javaDocBrowser(){
openBrowser(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "hilfe", "javadoc"), "JavaDoc");
}
/**
* Öffnet Doxygen Doc im standart browser
*
*/
@FXML
private void doxygenDocBrowser(){
openBrowser(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "hilfe", "doxygendoc"), "Doxygen");
}
/**
* Öffnet einen link im Standart Browser
* @param uriString
* @param appname
*/
private void openBrowser(String uriString, String appname){
Desktop desktop = java.awt.Desktop.getDesktop();
try {
URI oURL = new URI(
uriString);
desktop.browse(oURL);
} catch (URISyntaxException | IOException e) {
LogHelper.error(e.getMessage(), ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "openbrowsererror") + appname);
AlertHelper.exerror(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "browserexception"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "openbrowsererror") + appname,
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "browserexceptionmsg"), e);
}
}
/**
* Wird gestartet wenn eine Tour in der Tour listView ausgewählt wird
* @param mouseEvent Triggered Event
*/
@FXML
private void tourListSelectedItem(MouseEvent mouseEvent){
String selectedItem = TourListView.getSelectionModel().getSelectedItem();
this.viewModel.selectTour(selectedItem);
titleTextView.setText(selectedItem);
beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
startCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("start"));
zielCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("ziel"));
dauerCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("dauer"));
streckeCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("strecke"));
nameCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("name"));
//Log anzeigen
logTableView.setPlaceholder(new Label( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinelogsvorhanden")));
logTableView.setItems(this.viewModel.getLogData());
logDauerCol.setCellValueFactory(new PropertyValueFactory<Log, String>("dauer"));
logStreckeCol.setCellValueFactory(new PropertyValueFactory<Log, String>("strecke"));
logDatumCol.setCellValueFactory(new PropertyValueFactory<Log, String>("datum"));
}
/**
* Beendet die App
* Verbunden mit dem Menu -> Datei -> Beenden
*/
@FXML
private void quitApp(){
System.exit(0);
}
/**
* Fügt eine Tour hinzu
* Verbunden mit Button -> Tour -> +
*/
@FXML
private void addTour(){
this.viewModel.addTour();
}
/**
* Entfernt eine ausgewählte Tour
* Verbunden mit Button -> Tour -> -
*/
@FXML
private void delTour(){
this.beschreibungTableView.getItems().removeIf(s -> true); //löscht alles aus der tabelle
this.titleTextView.setText(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected"));
this.viewModel.delTour();
logTableView.setPlaceholder(new Label( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected")));
}
/**
* Sucht eine Tour
* Verbunden mit Button -> Suche
*/
@FXML
private void suche(){
String sucheInput = this.sucheInput.getText();
if(sucheInput.isEmpty()){
AlertHelper.warn(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "suchfeldleer"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "suchtextzuerst"));
}else {
this.viewModel.suche(sucheInput);
}
}
/**
* Fügt einen Log eintrag zu einer Tour hinzu.
* Ist keine Tour ausgewählt, dann kommt eine Warnung an den User!
*/
@FXML
private void addLog(){
Tour selectedTour = this.viewModel.getSelectedTour();
if (selectedTour == null){
AlertHelper.warn(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "logtournotselectedmsg"));
}else {
ObservableList<Tour> tourData = this.viewModel.getTourData();
tourData.forEach(s -> {
if (s.getName().equals(selectedTour.getName())) {
ObservableList<Log> logData = this.viewModel.getLogData();
AtomicReference<String> newId = new AtomicReference<>();
newId.set(UUID.randomUUID().toString());
logData.forEach(ss -> {
if (ss.getId().equals(newId.get())) {
newId.set(UUID.randomUUID().toString());
}
});
double neueDauer = -1;
double neueStrecke = -1;
LocalDate neuesDatum = null;
while (neuesDatum == null) {
neuesDatum = AlertHelper.datePicker(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "datum"));
}
while (neueDauer == -1) {
neueDauer = AlertHelper.inputNumber(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "dauer"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "dauermsg"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "dauer") +
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "doppelpunkt"));
}
while (neueStrecke == -1) {
neueStrecke = AlertHelper.inputNumber(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "strecke"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "streckemsg"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "strecke") +
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "doppelpunkt"));
}
Log newLog = new Log(newId.get(), neueDauer + "", neuesDatum, neueStrecke);
logData.add(newLog);
s.addLog(newLog);
}
});
}
}
@FXML
private void delLog(){
Log selectedLog = this.viewModel.getSelectedLog();
if(selectedLog != null) {
this.viewModel.delLog(selectedLog.getId());
}
}
/**
* Ein Log eintrag wurde ausgewählt
* @param mouseEvent Aktuelles Mouse Event
*/
@FXML
private void logItemSelected(MouseEvent mouseEvent){
String selectedItem = logTableView.getSelectionModel().getSelectedItem().getId();
this.viewModel.selectLog(selectedItem);
System.out.println(selectedItem);
}
/**
* Wird beim Start ausgeführt
* @param url
* @param resourceBundle
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
//Tour list -> links
TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
TourListView.setOrientation(Orientation.VERTICAL);
TourListView.setItems(this.viewModel.getTourNamen());
//Tabs zu Tour -> rechts oben
beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected")));
titleTextView.setText( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected"));
//Log -> rechts unten
logTableView.setPlaceholder(new Label( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected")));
}
/**
* Funktion für noch nicht implementierte sachen wie im Menu der 'Bearbeiten' und 'Optionen' Knopf
*/
@FXML
public void nimpButton(){
AlertHelper.inform(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "fktnichtimplementiert"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "vergessenodernochnichtsoweit"));
}
}

View File

@ -0,0 +1,219 @@
package tourplaner.viewmodels;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import tourplaner.business.AlertHelper;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
public class ViewModel {
//Tour
private final ObservableList<Tour> tourData = FXCollections.observableArrayList(new Tour("Test 1", "120", "json dings", 22.3, "Wien", "Graz"),new Tour("Test 2", "210", "json dings", 42.3, "Da", "Dort"));
private final ObservableList<String> tourNamen = FXCollections.observableArrayList("Test 1", "Test 2");
private Tour selectedTour;
private String neueTourName, neueTourStart, neueTourZiel;
//Log
private final ObservableList<Log> logData = FXCollections.observableArrayList();
private Log selectedLog;
/**
* Fügt eine neue Tour hinzu
*/
public void addTour(){
while(this.neueTourName == null) {
this.neueTourName = AlertHelper.inputText(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "tournametitle"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "tournameheader"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "tournamemsg"));
if (getTour(this.neueTourName) != null) {
AlertHelper.warn(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "namevergebenheader"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "namevergebenmsg1")
+ this.neueTourName +
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "namevergebenmsg2"));
this.neueTourName = null;
}
}
while(this.neueTourStart == null){
this.neueTourStart = AlertHelper.inputText(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "startpunkttitle"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "startpunktheader"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "startpunktmsg"));
}
while(this.neueTourZiel == null){
this.neueTourZiel = AlertHelper.inputText(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "zielpunkttitle"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "zielpunktheader"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "zielpunktmsg"));
}
if (getTour(this.neueTourName) == null) {
tourData.add(new Tour(this.neueTourName, "TBD", "TBD", 0, this.neueTourStart, this.neueTourZiel));
tourNamen.add(this.neueTourName);
}
this.neueTourStart = null;
this.neueTourZiel = null;
this.neueTourName = null;
}
/**
* Entfernt ein Log anhand dessen Id
* @param id Id des Logs welches entfernt werden soll
*/
public void delLog(String id){
this.logData.removeIf(s -> s.getId().equals(id));
AtomicReference<Tour> tourToEdit = new AtomicReference<>();
this.tourData.forEach(s -> {
if (s.getLogs() != null) {
s.getLogs().forEach(ss -> {
if (ss.getId().equals(id)) {
tourToEdit.set(s);
}
});
}
});
if (tourToEdit.get() != null){
Tour toEdit = tourToEdit.get();
toEdit.delLog(id);
this.tourData.removeIf(s -> s.getName().equals(toEdit.getName()));
this.tourData.add(toEdit);
}
}
/**
* Selectiert ein Log anhand der Id
* @param id Id welche zu selectieren ist
*/
public void selectLog(String id){
this.selectedLog = getLog(id);
}
/**
* Holt das selectierte Log als Log Objekt
* @return Das selectierte Log Objekt
*/
public Log getSelectedLog(){
return this.selectedLog;
}
/**
* Holt ein Log anhand seiner ID
* @param id Id des Log Eintrags
* @return Das gefundene Log
*/
public Log getLog(String id){
AtomicReference<Log> returnLog = new AtomicReference<>();
this.logData.forEach(s -> {
if(s.getId().equals(id)){
returnLog.set(s);
}
});
return returnLog.get();
}
public ObservableList<Log> getLogData() {
return logData;
}
public void setSelectedTour(Tour selectedTour) {
this.selectedTour = selectedTour;
}
/**
* Holt das Tourobjekt anhand des Namens
* @param tourname Name der Tour
* @return Gefundene Tour
*/
public Tour getTour(String tourname){
AtomicReference<Tour> returnTour = new AtomicReference<>();
tourData.forEach(s -> {
if(s.getName().equals(tourname)){
returnTour.set(s);
}
});
return returnTour.get();
}
/**
* Selectiert eine Tour anhand des eindeutigen Namens
* @param tourname Der Name der Tour
*/
public void selectTour(String tourname){
this.selectedTour = getTour(tourname);
this.logData.removeIf(s -> true); // Löscht alles aus dem Array
this.logData.addAll(this.selectedTour.getLogs());
}
// /**
// * Selectiert eine Tour anhand des Tour Objects.
// * Kann z.b. verwerndet werden um das selectierte Tour Object zu bearbeiten
// * @param selected
// */
// public void setSelectedTour(Tour selected){
// this.selectedTour = selected;
// }
public Tour getSelectedTour() {
return selectedTour;
}
public String getNeueTourZiel() {
return neueTourZiel;
}
public void setNeueTourZiel(String neueTourZiel) {
this.neueTourZiel = neueTourZiel;
}
public ObservableList<String> getTourNamen() {
return tourNamen;
}
public String getNeueTourName() {
return neueTourName;
}
public void setNeueTourName(String neueTourName) {
this.neueTourName = neueTourName;
}
public String getNeueTourStart() {
return neueTourStart;
}
public void setNeueTourStart(String neueTourStart) {
this.neueTourStart = neueTourStart;
}
public ObservableList<Tour> getTourData() {
return tourData;
}
/**
* Entfernt eine Tour anhand der ausgewählten Tour
*/
public void delTour(){
try {
String tourname = this.selectedTour.getName();
tourData.removeIf(s -> s.getName().equals(tourname));
tourNamen.removeIf(s -> s.equals(tourname));
logData.removeIf(s -> true);
}catch (NullPointerException e){
LogHelper.error(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "deltournoselect"));
AlertHelper.warn(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "achtung"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "keinetourselected"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "langde", "deltournoselectmsg"));
}
}
/**
* Sucht eine Tour
*/
public void suche(String suchString){
}
}