Compare commits
	
		
			4 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f4e9b16792 | |||
| c261652ce6 | |||
| a0224b9870 | |||
| ae93f365d5 | 
							
								
								
									
										22
									
								
								langde.ini
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								langde.ini
									
									
									
									
									
								
							@@ -39,4 +39,24 @@ pausemsg = Dauer der Pause
 | 
			
		||||
hightmeter = Höhenmeter
 | 
			
		||||
hightmetermsg = Höhenmeter des Abschnitts
 | 
			
		||||
bemerkung = Bemerkung
 | 
			
		||||
bemerkungheader = Bitte geben Sie die Bemerkungen zu diesem Log eintrag ein, kann auch leer bleiben.
 | 
			
		||||
bemerkungheader = Bitte geben Sie die Bemerkungen zu diesem Log eintrag ein, kann auch leer bleiben.
 | 
			
		||||
tourreportvon = Tour Report von ->
 | 
			
		||||
tourplanervon = Tourplaner by DerGeorg
 | 
			
		||||
reportkeywords = Tourplaner, Tour, Report
 | 
			
		||||
tourplaner = Tourplaner"
 | 
			
		||||
tour = Tour
 | 
			
		||||
reportvon = Report erstellt von:
 | 
			
		||||
reportstart = Startpunkt der Tour:
 | 
			
		||||
reportziel = Zielpunkt der Tour:
 | 
			
		||||
reportdauercal = Berechnete Dauer der Tour:
 | 
			
		||||
reportstreckecal = Berechnete Strecke der Tour:
 | 
			
		||||
logs = Logs
 | 
			
		||||
countlog = Anzahl der Logeinträge:
 | 
			
		||||
logvom = Log vom:
 | 
			
		||||
logdauer = Dauer:
 | 
			
		||||
logpause = Davon Pause:
 | 
			
		||||
loggegangen = Davon gegangen:
 | 
			
		||||
logavg = Berechnete Durchschnittliche Geschwindigkeit:
 | 
			
		||||
logstrecke = Entfernung:
 | 
			
		||||
loghight = Höhenmeter:
 | 
			
		||||
logbemerkung = Bemerkung:
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
package tourplaner.business;
 | 
			
		||||
 | 
			
		||||
import javax.imageio.ImageIO;
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.awt.image.BufferedImage;
 | 
			
		||||
import java.awt.image.RenderedImage;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Zuständig für das besorgen der Map für die UI und PDF-Reports und für die Berechneten infos der Tour (Dauer, Strecke)
 | 
			
		||||
 */
 | 
			
		||||
public class DirectionMap {
 | 
			
		||||
 | 
			
		||||
    private double dauer, strecke;
 | 
			
		||||
    private String start, end, tourname, file, filepdf;
 | 
			
		||||
    private Image map, mappdf;
 | 
			
		||||
@@ -35,10 +34,18 @@ public class DirectionMap {
 | 
			
		||||
        FileHelper.openDefault(file);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get berechnete Dauer in Minuten
 | 
			
		||||
     * @return Berechnete Dauer der Tour
 | 
			
		||||
     */
 | 
			
		||||
    public double getDauer() {
 | 
			
		||||
        return dauer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get berechnete Strecke
 | 
			
		||||
     * @return Berechnete Strecke der Tour
 | 
			
		||||
     */
 | 
			
		||||
    public double getStrecke() {
 | 
			
		||||
        return strecke;
 | 
			
		||||
    }
 | 
			
		||||
@@ -54,12 +61,23 @@ public class DirectionMap {
 | 
			
		||||
        return HttpHelper.httpGetImage("https://www.mapquestapi.com/staticmap/v5/map?start="+start+"&end="+ende+"&size="+size+"&key="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Besorgt die Infos der Tour von Mapquest Directions
 | 
			
		||||
     * @param start Start der Tour
 | 
			
		||||
     * @param ende Ende der Tour
 | 
			
		||||
     * @throws IOException Fehler beim besorgen der infos über die Tour
 | 
			
		||||
     */
 | 
			
		||||
    private void getDirections(String start, String ende) throws IOException {
 | 
			
		||||
        String json = HttpHelper.httpGetJsonString("https://www.mapquestapi.com/directions/v2/route?key="+ ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key")+"&from="+start+"&to="+ende+"&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=false&avoidTimedConditions=false");
 | 
			
		||||
        this.strecke = JsonHelper.getDoubleFromJson(json, "distance");
 | 
			
		||||
        this.dauer = formatetTimeToMinutes(JsonHelper.getStingFromJson(json, "formattedTime"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Formatet time HH:MM:SS in Minuten umwandeln
 | 
			
		||||
     * @param formatetTime Formatet time HH:MM:SS
 | 
			
		||||
     * @return Zeit in Minuten
 | 
			
		||||
     */
 | 
			
		||||
    private double formatetTimeToMinutes(String formatetTime){
 | 
			
		||||
        double minutes = 0;
 | 
			
		||||
        String[] result = formatetTime.split(":");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										55
									
								
								src/tourplaner/business/Exporter.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/tourplaner/business/Exporter.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
package tourplaner.business;
 | 
			
		||||
 | 
			
		||||
import tourplaner.data.DbConnect;
 | 
			
		||||
import tourplaner.object.Log;
 | 
			
		||||
import tourplaner.object.Tour;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Ist für das importieren und Exportieren der Daten zuständig
 | 
			
		||||
 */
 | 
			
		||||
public class Exporter {
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Tour> touren;
 | 
			
		||||
    private String path;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erstellt den Exporter mit dem gegebenen Path
 | 
			
		||||
     * @param path Gegebener Path
 | 
			
		||||
     */
 | 
			
		||||
    public Exporter(String path) {
 | 
			
		||||
        this.path = path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Führt den Export aus -> Holt daten, erstellt file
 | 
			
		||||
     * @throws IOException Fehler beim File erstellen
 | 
			
		||||
     */
 | 
			
		||||
    public void doExport() throws IOException {
 | 
			
		||||
        ArrayList<Tour> data = new DbConnect().getAllTouren();
 | 
			
		||||
        FileWriter fileWriter = new FileWriter(path + ".json");
 | 
			
		||||
        JsonHelper.getJsonFromObj(data, fileWriter);
 | 
			
		||||
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
 | 
			
		||||
        bufferedWriter.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Führt den Imput aus -> File holen, Daten in db erstellen
 | 
			
		||||
     * @throws IOException Fehler beim File öffnen
 | 
			
		||||
     */
 | 
			
		||||
    public void doImport() throws IOException {
 | 
			
		||||
        this.touren = JsonHelper.getTourenFromJson(new FileReader(this.path));
 | 
			
		||||
        DbConnect dbConnect = new DbConnect();
 | 
			
		||||
        dbConnect.delAllData();
 | 
			
		||||
        for (Tour tour:this.touren) {
 | 
			
		||||
            new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
 | 
			
		||||
            dbConnect.addTour(tour);
 | 
			
		||||
            ArrayList<Log> logs = tour.getLogs();
 | 
			
		||||
            for (Log log:logs) {
 | 
			
		||||
                dbConnect.addLog(tour.getName(), log);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package tourplaner.business;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import javax.imageio.ImageIO;
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.io.*;
 | 
			
		||||
@@ -24,37 +22,32 @@ public class HttpHelper {
 | 
			
		||||
        return ImageIO.read(urls);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Http GET Json string vom Url string
 | 
			
		||||
     * @param url Url als String
 | 
			
		||||
     * @return Json als String
 | 
			
		||||
     * @throws IOException Fehler beim Json holen
 | 
			
		||||
     */
 | 
			
		||||
    public static String httpGetJsonString(String url) throws IOException {
 | 
			
		||||
        HttpURLConnection con = null;
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
            var myurl = new URL(url);
 | 
			
		||||
            con = (HttpURLConnection) myurl.openConnection();
 | 
			
		||||
 | 
			
		||||
            con.setRequestMethod("GET");
 | 
			
		||||
 | 
			
		||||
            StringBuilder content;
 | 
			
		||||
 | 
			
		||||
            try (BufferedReader in = new BufferedReader(
 | 
			
		||||
                    new InputStreamReader(con.getInputStream()))) {
 | 
			
		||||
 | 
			
		||||
                String line;
 | 
			
		||||
                content = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
                while ((line = in.readLine()) != null) {
 | 
			
		||||
 | 
			
		||||
                    content.append(line);
 | 
			
		||||
                    content.append(System.lineSeparator());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return content.toString();
 | 
			
		||||
        } finally {
 | 
			
		||||
 | 
			
		||||
            assert con != null;
 | 
			
		||||
            con.disconnect();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,71 @@
 | 
			
		||||
package tourplaner.business;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.Gson;
 | 
			
		||||
import com.google.gson.JsonElement;
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
import com.google.gson.reflect.TypeToken;
 | 
			
		||||
import tourplaner.object.Tour;
 | 
			
		||||
 | 
			
		||||
import java.io.FileReader;
 | 
			
		||||
import java.io.FileWriter;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Hilfsklasse für Json (Gson)
 | 
			
		||||
 */
 | 
			
		||||
public class JsonHelper {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * String aus json extrahieren
 | 
			
		||||
     * @param json Json als String
 | 
			
		||||
     * @param gets Eintrag im Json unter "route"
 | 
			
		||||
     * @return Gesammelter String
 | 
			
		||||
     */
 | 
			
		||||
    public static String getStingFromJson(String json, String gets){
 | 
			
		||||
        return getJObj(json).get("route").getAsJsonObject().get(gets).getAsString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Double aus json extrahieren
 | 
			
		||||
     * @param json Json als String
 | 
			
		||||
     * @param gets Eintrag im Json unter "route"
 | 
			
		||||
     * @return Gesammelter Double Wert
 | 
			
		||||
     */
 | 
			
		||||
    public static double getDoubleFromJson(String json, String gets){
 | 
			
		||||
        return getJObj(json).get("route").getAsJsonObject().get(gets).getAsDouble();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erzeugt ein Json aus einem Object
 | 
			
		||||
     * @param obj Das Objekt
 | 
			
		||||
     * @return Json des Objektes
 | 
			
		||||
     */
 | 
			
		||||
    public static String getJsonFromObj(Object obj){
 | 
			
		||||
        return new Gson().toJson(obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erzeugt ein Json aus einem Object
 | 
			
		||||
     * @param obj Das Objekt
 | 
			
		||||
     * @param writer File in das geschrieben werden soll
 | 
			
		||||
     */
 | 
			
		||||
    public static void getJsonFromObj(Object obj , FileWriter writer){
 | 
			
		||||
        new Gson().toJson(obj, writer);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Wandelt ein Json file in ein Data Objekt um
 | 
			
		||||
     * @param reader File aus dem gelesen wird
 | 
			
		||||
     * @return Data objekt das gelesen wurde
 | 
			
		||||
     */
 | 
			
		||||
    public static ArrayList<Tour> getTourenFromJson(FileReader reader){
 | 
			
		||||
        return new Gson().fromJson(reader, new TypeToken<ArrayList<Tour>>() {}.getType());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Json String to JsonObject
 | 
			
		||||
     * @param json Json string
 | 
			
		||||
     * @return Neues JsonObject aus String
 | 
			
		||||
     */
 | 
			
		||||
    private static JsonObject getJObj(String json){
 | 
			
		||||
       return new Gson().fromJson(json, JsonObject.class);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,17 +3,15 @@ package tourplaner.business;
 | 
			
		||||
import com.itextpdf.text.*;
 | 
			
		||||
import com.itextpdf.text.Font;
 | 
			
		||||
import com.itextpdf.text.Image;
 | 
			
		||||
import com.sun.scenario.effect.ImageData;
 | 
			
		||||
import tourplaner.data.DbConnect;
 | 
			
		||||
import tourplaner.object.Log;
 | 
			
		||||
import tourplaner.object.Tour;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.itextpdf.text.pdf.PdfPCell;
 | 
			
		||||
import com.itextpdf.text.pdf.PdfPTable;
 | 
			
		||||
import com.itextpdf.text.pdf.PdfWriter;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileNotFoundException;
 | 
			
		||||
import java.io.FileOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
@@ -21,6 +19,11 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * PDF Report generierung mit iText
 | 
			
		||||
 *
 | 
			
		||||
 * Erstellt Reports über einzelne Touren und fasst alle Touren zusammen
 | 
			
		||||
 *
 | 
			
		||||
 * iText 4 ist gratis verfügbar, siehe:
 | 
			
		||||
 * https://github.com/ymasory/iText-4.2.0
 | 
			
		||||
 */
 | 
			
		||||
public class Reporter {
 | 
			
		||||
@@ -34,6 +37,63 @@ public class Reporter {
 | 
			
		||||
    private static Font smallBold = new Font(Font.TIMES_ROMAN, 12,
 | 
			
		||||
            Font.BOLD);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erstellt den Summary Report
 | 
			
		||||
     */
 | 
			
		||||
    public static void sumReport(){
 | 
			
		||||
        ArrayList<Tour> tours = TourPlaner.getAllTours();
 | 
			
		||||
        String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + "summary.pdf";
 | 
			
		||||
        try {
 | 
			
		||||
            Document document = new Document();
 | 
			
		||||
            PdfWriter.getInstance(document, new FileOutputStream(file));
 | 
			
		||||
            document.open();
 | 
			
		||||
            addSumRepo(document, tours);
 | 
			
		||||
 | 
			
		||||
            document.close();
 | 
			
		||||
        } catch (DocumentException | FileNotFoundException e) {
 | 
			
		||||
            LogHelper.error(e.getMessage(), e.getClass().getName());
 | 
			
		||||
        }
 | 
			
		||||
        FileHelper.openDefault(file);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Content des Sumary reports
 | 
			
		||||
     * @param document Document auf das geschrieben wird
 | 
			
		||||
     * @param touren Touren die berechnet werden
 | 
			
		||||
     * @throws DocumentException Fehler beim schreiben auf das Dokument
 | 
			
		||||
     */
 | 
			
		||||
    private static void addSumRepo(Document document, ArrayList<Tour> touren) throws DocumentException {
 | 
			
		||||
        double dauer = 0;
 | 
			
		||||
        double strecke = 0;
 | 
			
		||||
        double calDauer = 0;
 | 
			
		||||
        double calStecke = 0;
 | 
			
		||||
        for (Tour tour:touren) {
 | 
			
		||||
            calStecke += tour.getStrecke();
 | 
			
		||||
            calDauer += Double.parseDouble(tour.getDauer());
 | 
			
		||||
            ArrayList<Log> logs = tour.getLogs();
 | 
			
		||||
            for (Log log:logs) {
 | 
			
		||||
                dauer += log.getDauer();
 | 
			
		||||
                strecke += log.getStrecke();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        Anchor anchor = new Anchor("Zusammengefasster Report", catFont);
 | 
			
		||||
        anchor.setName("Zusammengefasster Report");
 | 
			
		||||
        // Second parameter is the number of the chapter
 | 
			
		||||
        Chapter catPart = new Chapter(new Paragraph(anchor), 1);
 | 
			
		||||
        Paragraph subPara = new Paragraph("Daten", subFont);
 | 
			
		||||
        Section subCatPart = catPart.addSection(subPara);
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportvon") + System.getProperty("user.name") + ", " + new Date()));
 | 
			
		||||
        subCatPart.add(new Paragraph("Gesammte Zeit aller Logs: " + dauer));
 | 
			
		||||
        subCatPart.add(new Paragraph("gesammte Strecke aller Logs: " + strecke));
 | 
			
		||||
        subCatPart.add(new Paragraph("Berechnete Zeit aller Logs: " + calDauer));
 | 
			
		||||
        subCatPart.add(new Paragraph("Berechnete Strecke aller Touren: " + calStecke));
 | 
			
		||||
        document.add(catPart);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erstellt einen Tour Report
 | 
			
		||||
     * @param tourname Name der Tour die Gereportet werden soll
 | 
			
		||||
     */
 | 
			
		||||
    public static void createTourReport(String tourname)   {
 | 
			
		||||
        Tour tour = TourPlaner.getTour(tourname);
 | 
			
		||||
        tour.setLog(TourPlaner.getLogs(tourname));
 | 
			
		||||
@@ -56,32 +116,36 @@ public class Reporter {
 | 
			
		||||
    // Reader
 | 
			
		||||
    // under File -> Properties
 | 
			
		||||
    private static void addMetaData(Document document, Tour tour) {
 | 
			
		||||
        document.addTitle("Tour Report -> " + tour.getName());
 | 
			
		||||
        document.addSubject("Tourplaner by DerGeorg");
 | 
			
		||||
        document.addKeywords("Tourplaner, Tour, Report");
 | 
			
		||||
        document.addAuthor("Tourplaner");
 | 
			
		||||
        document.addCreator("Tourplaner");
 | 
			
		||||
        document.addTitle(ConfigHelper.getLangIniString("tourreportvon") + tour.getName());
 | 
			
		||||
        document.addSubject(ConfigHelper.getLangIniString("tourplanervon"));
 | 
			
		||||
        document.addKeywords(ConfigHelper.getLangIniString("reportkeywords"));
 | 
			
		||||
        document.addAuthor(ConfigHelper.getLangIniString("tourplaner"));
 | 
			
		||||
        document.addCreator(ConfigHelper.getLangIniString("tourplaner"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erstellt den inhalt des Reports
 | 
			
		||||
     * @param document Aktuelles Dokument
 | 
			
		||||
     * @param tour Aktuelle Tour
 | 
			
		||||
     * @throws DocumentException Fehler beim hinzufügen des Inhaltes
 | 
			
		||||
     */
 | 
			
		||||
    private static void addContent(Document document, Tour tour) throws DocumentException {
 | 
			
		||||
        Anchor anchor = new Anchor("Tour Report von -> " + tour.getName(), catFont);
 | 
			
		||||
        anchor.setName("Tour Report von -> " + tour.getName());
 | 
			
		||||
        Anchor anchor = new Anchor(ConfigHelper.getLangIniString("tourreportvon") + tour.getName(), catFont);
 | 
			
		||||
        anchor.setName(ConfigHelper.getLangIniString("tourreportvon") + tour.getName());
 | 
			
		||||
 | 
			
		||||
        // Second parameter is the number of the chapter
 | 
			
		||||
        Chapter catPart = new Chapter(new Paragraph(anchor), 1);
 | 
			
		||||
 | 
			
		||||
        Paragraph subPara = new Paragraph("Tour", subFont);
 | 
			
		||||
        Paragraph subPara = new Paragraph(ConfigHelper.getLangIniString("tour"), subFont);
 | 
			
		||||
        Section subCatPart = catPart.addSection(subPara);
 | 
			
		||||
        subCatPart.add(new Paragraph("Report erstellt von: " + System.getProperty("user.name") + ", " + new Date()));
 | 
			
		||||
        subCatPart.add(new Paragraph("Startpunkt der Tour: " + tour.getStart()));
 | 
			
		||||
        subCatPart.add(new Paragraph("Zielpunkt der Tour: " + tour.getZiel()));
 | 
			
		||||
        subCatPart.add(new Paragraph("Berechnete Dauer der Tour: " + tour.getDauer()));
 | 
			
		||||
        subCatPart.add(new Paragraph("Berechnete Strecke der Tour: " + tour.getStrecke()));
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportvon") + System.getProperty("user.name") + ", " + new Date()));
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportstart") + tour.getStart()));
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportziel") + tour.getZiel()));
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportdauercal") + tour.getDauer()));
 | 
			
		||||
        subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportstreckecal") + tour.getStrecke()));
 | 
			
		||||
        Paragraph emptyLine = new Paragraph();
 | 
			
		||||
        addEmptyLine(emptyLine, 5);
 | 
			
		||||
        subCatPart.add(emptyLine);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        // now add all this to the document
 | 
			
		||||
        document.add(catPart);
 | 
			
		||||
 | 
			
		||||
@@ -97,127 +161,83 @@ public class Reporter {
 | 
			
		||||
        }
 | 
			
		||||
        ArrayList<Log> logs = tour.getLogs();
 | 
			
		||||
        // Second parameter is the number of the chapter
 | 
			
		||||
        anchor = new Anchor("Logs", catFont);
 | 
			
		||||
        anchor.setName("Logs");
 | 
			
		||||
        anchor = new Anchor(ConfigHelper.getLangIniString("logs"), catFont);
 | 
			
		||||
        anchor.setName(ConfigHelper.getLangIniString("logs"));
 | 
			
		||||
        catPart = new Chapter(new Paragraph(anchor), 2);
 | 
			
		||||
        catPart.add(new Paragraph("Anzahl der Logeinträge: " + logs.size()));
 | 
			
		||||
        catPart.add(new Paragraph(ConfigHelper.getLangIniString("countlog") + logs.size()));
 | 
			
		||||
 | 
			
		||||
        for (Log log: logs) {
 | 
			
		||||
            subPara = new Paragraph("Log vom: " + log.getDatum() , subFont);
 | 
			
		||||
            subPara = new Paragraph(ConfigHelper.getLangIniString("logvom") + log.getDatum() , subFont);
 | 
			
		||||
            subCatPart = catPart.addSection(subPara);
 | 
			
		||||
            subCatPart.add(new Paragraph("Dauer: " + log.getDauer()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Davon Pause: " + log.getPause()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Davon gegangen: " + log.getGegangen()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Berechnete Durchschnittliche Geschwindigkeit: " + log.getAvgspeed()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Entfernung: " + log.getStrecke()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Höhenmeter: " + log.getHightmeter()));
 | 
			
		||||
            subCatPart.add(new Paragraph("Bemerkung: " + log.getBemerkung()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logdauer") + log.getDauer()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logpause") + log.getPause()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("loggegangen") + log.getGegangen()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logavg")+ log.getAvgspeed()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logstrecke") + log.getStrecke()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("loghight") + log.getHightmeter()));
 | 
			
		||||
            subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logbemerkung") + log.getBemerkung()));
 | 
			
		||||
        }
 | 
			
		||||
        // now add all this to the document
 | 
			
		||||
        document.add(catPart);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void createTable(Section subCatPart)
 | 
			
		||||
            throws BadElementException {
 | 
			
		||||
        PdfPTable table = new PdfPTable(5);
 | 
			
		||||
 | 
			
		||||
        // t.setBorderColor(BaseColor.GRAY);
 | 
			
		||||
        // t.setPadding(4);
 | 
			
		||||
        // t.setSpacing(4);
 | 
			
		||||
        // t.setBorderWidth(1);
 | 
			
		||||
 | 
			
		||||
        PdfPCell c1 = new PdfPCell(new Phrase("NR"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Datum"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Entfernung"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Höhenmeter"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("AVG Geschwindigkeit"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        table.setHeaderRows(1);
 | 
			
		||||
 | 
			
		||||
        table.addCell("1.0");
 | 
			
		||||
        table.addCell("1.1");
 | 
			
		||||
        table.addCell("1.2");
 | 
			
		||||
        table.addCell("1.3");
 | 
			
		||||
        table.addCell("1.4");
 | 
			
		||||
        table.addCell("1.5");
 | 
			
		||||
 | 
			
		||||
        table.addCell("2.0");
 | 
			
		||||
        table.addCell("2.1");
 | 
			
		||||
        table.addCell("2.2");
 | 
			
		||||
        table.addCell("2.3");
 | 
			
		||||
        table.addCell("2.4");
 | 
			
		||||
        table.addCell("2.5");
 | 
			
		||||
 | 
			
		||||
        subCatPart.add(table);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    private static void createTable2(Section subCatPart)
 | 
			
		||||
            throws BadElementException {
 | 
			
		||||
        PdfPTable table = new PdfPTable(5);
 | 
			
		||||
 | 
			
		||||
        // t.setBorderColor(BaseColor.GRAY);
 | 
			
		||||
        // t.setPadding(4);
 | 
			
		||||
        // t.setSpacing(4);
 | 
			
		||||
        // t.setBorderWidth(1);
 | 
			
		||||
 | 
			
		||||
        PdfPCell c1 = new PdfPCell(new Phrase("NR"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Dauer"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Davon Gegangen"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Davon Pause"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
        c1 = new PdfPCell(new Phrase("Bemerkung"));
 | 
			
		||||
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
        table.addCell(c1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        table.setHeaderRows(1);
 | 
			
		||||
 | 
			
		||||
        table.addCell("1.0");
 | 
			
		||||
        table.addCell("1.1");
 | 
			
		||||
        table.addCell("1.2");
 | 
			
		||||
        table.addCell("1.3");
 | 
			
		||||
        table.addCell("1.4");
 | 
			
		||||
        table.addCell("1.5");
 | 
			
		||||
 | 
			
		||||
        table.addCell("2.0");
 | 
			
		||||
        table.addCell("2.1");
 | 
			
		||||
        table.addCell("2.2");
 | 
			
		||||
        table.addCell("2.3");
 | 
			
		||||
        table.addCell("2.4");
 | 
			
		||||
        table.addCell("2.5");
 | 
			
		||||
 | 
			
		||||
        subCatPart.add(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Fügt eine leere zeile an den Paragraph an
 | 
			
		||||
     * @param paragraph Hier wird hinzugefügt
 | 
			
		||||
     * @param number Um wie viele Leere Zeilen hinzugefügt werden soll
 | 
			
		||||
     */
 | 
			
		||||
    private static void addEmptyLine(Paragraph paragraph, int number) {
 | 
			
		||||
        for (int i = 0; i < number; i++) {
 | 
			
		||||
            paragraph.add(new Paragraph(" "));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
//    private static void createTable(Section subCatPart)
 | 
			
		||||
//            throws BadElementException {
 | 
			
		||||
//        PdfPTable table = new PdfPTable(5);
 | 
			
		||||
//
 | 
			
		||||
//        // t.setBorderColor(BaseColor.GRAY);
 | 
			
		||||
//        // t.setPadding(4);
 | 
			
		||||
//        // t.setSpacing(4);
 | 
			
		||||
//        // t.setBorderWidth(1);
 | 
			
		||||
//
 | 
			
		||||
//        PdfPCell c1 = new PdfPCell(new Phrase("NR"));
 | 
			
		||||
//        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
//        table.addCell(c1);
 | 
			
		||||
//
 | 
			
		||||
//        c1 = new PdfPCell(new Phrase("Datum"));
 | 
			
		||||
//        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
//        table.addCell(c1);
 | 
			
		||||
//
 | 
			
		||||
//        c1 = new PdfPCell(new Phrase("Entfernung"));
 | 
			
		||||
//        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
//        table.addCell(c1);
 | 
			
		||||
//
 | 
			
		||||
//        c1 = new PdfPCell(new Phrase("Höhenmeter"));
 | 
			
		||||
//        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
//        table.addCell(c1);
 | 
			
		||||
//
 | 
			
		||||
//        c1 = new PdfPCell(new Phrase("AVG Geschwindigkeit"));
 | 
			
		||||
//        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
 | 
			
		||||
//        table.addCell(c1);
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//        table.setHeaderRows(1);
 | 
			
		||||
//
 | 
			
		||||
//        table.addCell("1.0");
 | 
			
		||||
//        table.addCell("1.1");
 | 
			
		||||
//        table.addCell("1.2");
 | 
			
		||||
//        table.addCell("1.3");
 | 
			
		||||
//        table.addCell("1.4");
 | 
			
		||||
//        table.addCell("1.5");
 | 
			
		||||
//
 | 
			
		||||
//        table.addCell("2.0");
 | 
			
		||||
//        table.addCell("2.1");
 | 
			
		||||
//        table.addCell("2.2");
 | 
			
		||||
//        table.addCell("2.3");
 | 
			
		||||
//        table.addCell("2.4");
 | 
			
		||||
//        table.addCell("2.5");
 | 
			
		||||
//
 | 
			
		||||
//        subCatPart.add(table);
 | 
			
		||||
//
 | 
			
		||||
//    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import tourplaner.object.Tour;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileNotFoundException;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
@@ -46,6 +47,11 @@ public class TourPlaner{
 | 
			
		||||
        return new DbConnect().editTour(oldname, tour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Löscht eine Tour
 | 
			
		||||
     * @param tourname Tourname
 | 
			
		||||
     * @return false bei error
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean delTour(String tourname){
 | 
			
		||||
        FileHelper.delFile(new File(getImagePath(tourname)));
 | 
			
		||||
        FileHelper.delFile(new File(getImagePdfPath(tourname)));
 | 
			
		||||
@@ -63,51 +69,110 @@ public class TourPlaner{
 | 
			
		||||
        return new DbConnect().addTour(newTour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Holt das Gui Bild
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @return Das Bild
 | 
			
		||||
     * @throws IOException Error beim Bild holen
 | 
			
		||||
     */
 | 
			
		||||
    public static Image getImage(String tourname) throws IOException {
 | 
			
		||||
        return FileHelper.getImage(new File(getImagePath(tourname)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
     /**
 | 
			
		||||
     * Path zu dem Bild für die GUI
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @return Path zu dem Bild für die GUI
 | 
			
		||||
     */
 | 
			
		||||
    public static String getImagePath(String tourname){
 | 
			
		||||
        return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Path zu dem Bild für die PDF
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @return Path zu dem Bild für die PDF
 | 
			
		||||
     */
 | 
			
		||||
    public static String getImagePdfPath(String tourname){
 | 
			
		||||
        return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + "_pdf.jpg";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Öffnet ein Bild einer Tour
 | 
			
		||||
     * @param tourname Tourname
 | 
			
		||||
     */
 | 
			
		||||
    public static void openImage(String tourname){
 | 
			
		||||
        FileHelper.openDefault(getImagePath(tourname));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Holt alle Logs einer Tour
 | 
			
		||||
     * @param tourname Tourname
 | 
			
		||||
     * @return Alle Logs der Tour
 | 
			
		||||
     */
 | 
			
		||||
    public static ArrayList<Log> getLogs(String tourname){
 | 
			
		||||
        return new DbConnect().getLogs(tourname);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Führt einen Rport aus
 | 
			
		||||
     * @param tourname Name der Tour die gereportet wird
 | 
			
		||||
     */
 | 
			
		||||
    public static void doReport(String tourname){
 | 
			
		||||
        Reporter.createTourReport(tourname);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Holt eine Tour
 | 
			
		||||
     * @param tourname Name der zu holenden Tour
 | 
			
		||||
     * @return Tour die geholt werden soll
 | 
			
		||||
     */
 | 
			
		||||
    public static Tour getTour(String tourname){
 | 
			
		||||
        return new DbConnect().getTour(tourname);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Fügt ein Log hinzu
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @param log Neues Log
 | 
			
		||||
     * @return false bei error
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean addLog(String tourname, Log log){
 | 
			
		||||
        if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
 | 
			
		||||
        return new DbConnect().addLog(tourname, log);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Löscht ein Log
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @param id Id des Logs
 | 
			
		||||
     * @return false bei error
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean delLog(String tourname, String id){
 | 
			
		||||
        return new DbConnect().delLog(tourname, id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Editiert ein Log
 | 
			
		||||
     * @param tourname Name der Tour
 | 
			
		||||
     * @param log Neues Log
 | 
			
		||||
     * @return false bei error
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean editLog(String tourname, Log log){
 | 
			
		||||
        if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
 | 
			
		||||
        return new DbConnect().editLog(tourname, log);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static String getMapJson(String start, String ziel){
 | 
			
		||||
        // TODO: 14.04.2021 Map Quest
 | 
			
		||||
        return start + " " + ziel;
 | 
			
		||||
    /**
 | 
			
		||||
     * Exportiert die Daten
 | 
			
		||||
     * @param path Path zu den Daten
 | 
			
		||||
     * @throws IOException Fehler beim schreiben der Daten
 | 
			
		||||
     */
 | 
			
		||||
    public static void exportData(String path) throws IOException {
 | 
			
		||||
            Exporter exporter = new Exporter(path);
 | 
			
		||||
            exporter.doExport();
 | 
			
		||||
            FileHelper.openDefault(path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -84,6 +84,21 @@ public class DbConnect {
 | 
			
		||||
        return !result.contains(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean delAllData(){
 | 
			
		||||
        ArrayList<Boolean> result = new ArrayList<>();
 | 
			
		||||
        result.add(delAllLog());
 | 
			
		||||
        result.add(delAllTour());
 | 
			
		||||
        return !result.contains(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean delAllTour(){
 | 
			
		||||
        return PostgresHelper.executeUpdate("DELETE FROM public.tour");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean delAllLog(){
 | 
			
		||||
        return  PostgresHelper.executeUpdate("DELETE FROM public.log");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ArrayList<Log> getLogs(String tourname){
 | 
			
		||||
 | 
			
		||||
        this.c = PostgresHelper.con();
 | 
			
		||||
@@ -165,7 +180,7 @@ public class DbConnect {
 | 
			
		||||
                dauer = rs.getDouble("dauer");
 | 
			
		||||
                strecke = rs.getDouble("strecke");
 | 
			
		||||
                if (!tourname.isEmpty()) {
 | 
			
		||||
                    touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel));
 | 
			
		||||
                    touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel, getLogs(tourname)));
 | 
			
		||||
                }else {
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,16 @@ public class Tour {
 | 
			
		||||
        this.log = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Tour(String name, String dauer, String mapJson, double strecke, String start, String ziel, ArrayList<Log> logs) {
 | 
			
		||||
        this.dauer = dauer;
 | 
			
		||||
        this.mapJson = mapJson;
 | 
			
		||||
        this.strecke = strecke;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.start = start;
 | 
			
		||||
        this.ziel = ziel;
 | 
			
		||||
        this.log = logs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTour(Tour tour){
 | 
			
		||||
        this.dauer = tour.getDauer();
 | 
			
		||||
        this.mapJson = tour.getMapJson();
 | 
			
		||||
 
 | 
			
		||||
@@ -50,12 +50,14 @@
 | 
			
		||||
        </Menu>
 | 
			
		||||
        <Menu mnemonicParsing="false" text="Bearbeiten">
 | 
			
		||||
               <items>
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#importBtn" text="Import" />
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#exportBtn" text="Export" />
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#reportSum" text="Report alles" />
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
 | 
			
		||||
               </items>
 | 
			
		||||
        </Menu>
 | 
			
		||||
            <Menu mnemonicParsing="false" text="Optionen">
 | 
			
		||||
               <items>
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
 | 
			
		||||
                  <MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
 | 
			
		||||
               </items>
 | 
			
		||||
            </Menu>
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ import javafx.stage.Stage;
 | 
			
		||||
import javafx.stage.WindowEvent;
 | 
			
		||||
import tourplaner.business.ConfigHelper;
 | 
			
		||||
 | 
			
		||||
import javax.swing.*;
 | 
			
		||||
import java.io.PrintWriter;
 | 
			
		||||
import java.io.StringWriter;
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
@@ -229,4 +230,24 @@ public class AlertHelper {
 | 
			
		||||
        stage.showAndWait();
 | 
			
		||||
        return selectedDate.get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * File Auswahl
 | 
			
		||||
     * @param btn Text des Speichern/Öffnen Btn
 | 
			
		||||
     * @return String des Files, bei error null
 | 
			
		||||
     */
 | 
			
		||||
    public static String fileChooser(String btn){
 | 
			
		||||
        // JFileChooser-Objekt erstellen
 | 
			
		||||
        JFileChooser chooser = new JFileChooser();
 | 
			
		||||
        // Dialog zum Oeffnen von Dateien anzeigen
 | 
			
		||||
        int rueckgabeWert = chooser.showDialog(null, btn);
 | 
			
		||||
 | 
			
		||||
        /* Abfrage, ob auf "Öffnen" geklickt wurde */
 | 
			
		||||
        if(rueckgabeWert == JFileChooser.APPROVE_OPTION)
 | 
			
		||||
        {
 | 
			
		||||
            return chooser.getSelectedFile().getAbsolutePath();
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -98,6 +98,7 @@ public class TourplanerController implements Initializable {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void syncTourNamen(){
 | 
			
		||||
        TourListView.getItems().removeIf(s -> true);
 | 
			
		||||
        TourListView.setItems(this.viewModel.getTourNamen());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -216,12 +217,33 @@ public class TourplanerController implements Initializable {
 | 
			
		||||
        TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
 | 
			
		||||
        TourListView.setOrientation(Orientation.VERTICAL);
 | 
			
		||||
        syncTourNamen();
 | 
			
		||||
        deselectAll();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void deselectAll(){
 | 
			
		||||
        //Tabs zu Tour -> rechts oben
 | 
			
		||||
        beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
 | 
			
		||||
        titleTextView.setText( ConfigHelper.getLangIniString("keinetourselected"));
 | 
			
		||||
        //Log -> rechts unten
 | 
			
		||||
        logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @FXML
 | 
			
		||||
    private void exportBtn(){
 | 
			
		||||
        this.viewModel.exportData();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @FXML
 | 
			
		||||
    private void importBtn(){
 | 
			
		||||
        deselectAll();
 | 
			
		||||
        this.viewModel.importData();
 | 
			
		||||
        syncTourNamen();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @FXML
 | 
			
		||||
    private void reportSum(){
 | 
			
		||||
        this.viewModel.sumReport();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -3,14 +3,13 @@ package tourplaner.viewmodels;
 | 
			
		||||
import javafx.collections.FXCollections;
 | 
			
		||||
import javafx.collections.ObservableList;
 | 
			
		||||
import javafx.scene.image.Image;
 | 
			
		||||
import tourplaner.business.TourPlaner;
 | 
			
		||||
import tourplaner.business.*;
 | 
			
		||||
import tourplaner.ui.AlertHelper;
 | 
			
		||||
import tourplaner.business.ConfigHelper;
 | 
			
		||||
import tourplaner.business.LogHelper;
 | 
			
		||||
import tourplaner.object.Log;
 | 
			
		||||
import tourplaner.object.Tour;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.io.FileNotFoundException;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.URI;
 | 
			
		||||
import java.net.URISyntaxException;
 | 
			
		||||
@@ -23,7 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
 | 
			
		||||
public class ViewModel {
 | 
			
		||||
    //Tour
 | 
			
		||||
    private final ObservableList<Tour> tourData = FXCollections.observableArrayList();
 | 
			
		||||
    private final ObservableList<String> tourNamen = FXCollections.observableArrayList();
 | 
			
		||||
    private ObservableList<String> tourNamen = FXCollections.observableArrayList();
 | 
			
		||||
    private Tour selectedTour;
 | 
			
		||||
    private String neueTourName, neueTourStart, neueTourZiel, neueBemerkung;
 | 
			
		||||
    //Log
 | 
			
		||||
@@ -481,7 +480,6 @@ public class ViewModel {
 | 
			
		||||
 | 
			
		||||
    public ObservableList<Tour> getTourData() {
 | 
			
		||||
        tourData.removeAll();
 | 
			
		||||
//        ObservableList<Tour> data = ;
 | 
			
		||||
        tourData.addAll(TourPlaner.getAllTours());
 | 
			
		||||
        return tourData;
 | 
			
		||||
    }
 | 
			
		||||
@@ -583,4 +581,44 @@ public class ViewModel {
 | 
			
		||||
           TourPlaner.doReport(this.selectedTour.getName());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Exportiert alle daten in ein File das hier gewählt wird
 | 
			
		||||
     */
 | 
			
		||||
    public void exportData(){
 | 
			
		||||
        String file = AlertHelper.fileChooser("Exportiere");
 | 
			
		||||
        System.out.println("EXPORT: " + file);
 | 
			
		||||
        if(file != null){
 | 
			
		||||
            try {
 | 
			
		||||
                new Exporter(file).doExport();
 | 
			
		||||
            } catch (IOException e) {
 | 
			
		||||
                AlertHelper.error("Error", "Export Error", "Fehler beim Exportieren");
 | 
			
		||||
                LogHelper.error(e);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Importiert alle daten von einem File das hier gewählt wird
 | 
			
		||||
     */
 | 
			
		||||
    public void importData() {
 | 
			
		||||
        String file = AlertHelper.fileChooser("Importiere");
 | 
			
		||||
        System.out.println("IMPORT: " + file);
 | 
			
		||||
        if (file != null){
 | 
			
		||||
            try {
 | 
			
		||||
                this.tourNamen = FXCollections.observableArrayList();
 | 
			
		||||
                new Exporter(file).doImport();
 | 
			
		||||
            } catch (IOException e) {
 | 
			
		||||
                AlertHelper.error("Error", "Import Error", "Fehler beim Importieren");
 | 
			
		||||
                LogHelper.error(e);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Erstellt einen Summary Report
 | 
			
		||||
     */
 | 
			
		||||
    public void sumReport(){
 | 
			
		||||
        Reporter.sumReport();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user