Compare commits

...

9 Commits
0.3.1 ... 0.4.4

17 changed files with 826 additions and 214 deletions

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="com.google.code.gson:gson:2.8.6" type="repository">
<properties maven-id="com.google.code.gson:gson:2.8.6" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -12,5 +12,7 @@
<orderEntry type="library" name="log4j:log4j:1.2.17" level="project" /> <orderEntry type="library" name="log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="org.postgresql:postgresql:42.2.19" level="project" /> <orderEntry type="library" name="org.postgresql:postgresql:42.2.19" level="project" />
<orderEntry type="library" name="iText-4.2.0-com.itextpdf" level="project" /> <orderEntry type="library" name="iText-4.2.0-com.itextpdf" level="project" />
<orderEntry type="library" name="org.json:json:20180130" level="project" />
<orderEntry type="library" name="com.google.code.gson:gson:2.8.6" level="project" />
</component> </component>
</module> </module>

View File

@ -24,5 +24,6 @@ javadoc = https://git.dergeorg.at/dergeorg/tourplaner
[map] [map]
key = key =
size = 1500,400 size = 1500,400
sizePdf = 600,400
path = D:\\TourplanerImages\\ path = D:\\TourplanerImages\\
file_pre = file:/// file_pre = file:///

View File

@ -40,3 +40,23 @@ hightmeter = Höhenmeter
hightmetermsg = Höhenmeter des Abschnitts hightmetermsg = Höhenmeter des Abschnitts
bemerkung = Bemerkung 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:

View File

@ -1,17 +1,16 @@
package tourplaner.business; package tourplaner.business;
import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File; import java.io.File;
import java.io.IOException; 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 { public class DirectionMap {
private double dauer, strecke; private double dauer, strecke;
private String start, end, tourname, file; private String start, end, tourname, file, filepdf;
private Image map; private Image map, mappdf;
/** /**
* Holt die Map als image und alle Daten zur berechneten Route * Holt die Map als image und alle Daten zur berechneten Route
@ -22,15 +21,35 @@ public class DirectionMap {
* @throws IOException Fehler beim Image der Map * @throws IOException Fehler beim Image der Map
*/ */
public DirectionMap (String start, String ende, String tourname) throws IOException { public DirectionMap (String start, String ende, String tourname) throws IOException {
this.map = getMap(start, ende); this.map = getMap(start, ende, ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "size"));
this.mappdf = getMap(start, ende, ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "sizePdf"));
this.start = start; this.start = start;
this.end = ende; this.end = ende;
this.tourname = tourname; this.tourname = tourname;
this.file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + this.tourname + ".jpg"; this.file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + this.tourname + ".jpg";
FileHelper.saveImage(this.map, "jpg", new File(file)); this.filepdf = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + this.tourname + "_pdf.jpg";
FileHelper.saveImage(this.map, "jpg", new File(this.file));
FileHelper.saveImage(this.mappdf, "jpg", new File(this.filepdf));
getDirections(start, ende);
FileHelper.openDefault(file); 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;
}
/** /**
* Downloadet die Map von Mapquest * Downloadet die Map von Mapquest
* @param start Startpunkt * @param start Startpunkt
@ -38,11 +57,36 @@ public class DirectionMap {
* @return Image von der Map * @return Image von der Map
* @throws IOException Fehler beim Get der Map * @throws IOException Fehler beim Get der Map
*/ */
private Image getMap(String start, String ende) throws IOException { private Image getMap(String start, String ende, String size) throws IOException {
return HttpHelper.httpGetImage("https://www.mapquestapi.com/staticmap/v5/map?start="+start+"&end="+ende+"&size="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "size")+"&key="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key")); 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 {
System.out.println("LOCS: " + start + ende);
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");
System.out.println("JSON: " + json);
System.out.println("URL 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(":");
minutes += Double.parseDouble(result[0]) * 60;
minutes += Double.parseDouble(result[1]);
minutes += Double.parseDouble(result[2]) / 60;
return minutes;
}
} }

View File

@ -0,0 +1,76 @@
package tourplaner.business;
import tourplaner.data.DbConnect;
import tourplaner.object.Log;
import tourplaner.object.Tour;
import tourplaner.ui.AlertHelper;
import tourplaner.ui.ProgressBar;
import javax.swing.*;
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 {
ProgressBar progressBar = new ProgressBar("Export...");
int step = progressBar.getProgressSize(4, 100);
ArrayList<Tour> data = new DbConnect().getAllTouren();
progressBar.addProgress(step);
FileWriter fileWriter = new FileWriter(path + ".json");
progressBar.addProgress(step);
JsonHelper.getJsonFromObj(data, fileWriter);
progressBar.addProgress(step);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
progressBar.setProgress(100);
bufferedWriter.close();
}
/**
* Führt den Imput aus -> File holen, Daten in db erstellen
* @throws IOException Fehler beim File öffnen
*/
public void doImport() {
ProgressBar progressBar = new ProgressBar("Import...");
try {
this.touren = JsonHelper.getTourenFromJson(new FileReader(this.path));
DbConnect dbConnect = new DbConnect();
dbConnect.delAllData();
progressBar.addProgress(5);
int size = progressBar.getProgressSize(this.touren.size() * 3, 100);
for (Tour tour:this.touren) {
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
progressBar.addProgress(size);
dbConnect.addTour(tour);
progressBar.addProgress(size);
ArrayList<Log> logs = tour.getLogs();
for (Log log:logs) {
dbConnect.addLog(tour.getName(), log);
}
progressBar.addProgress(size);
}
} catch (IOException e) {
LogHelper.error(e);
progressBar.setProgress(100);
}
progressBar.setProgress(100);
}
}

View File

@ -2,7 +2,8 @@ package tourplaner.business;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
/** /**
@ -20,4 +21,33 @@ public class HttpHelper {
URL urls = new URL(url); URL urls = new URL(url);
return ImageIO.read(urls); 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();
}
}
} }

View File

@ -0,0 +1,72 @@
package tourplaner.business;
import com.google.gson.Gson;
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);
}
}

View File

@ -1,33 +1,31 @@
package tourplaner.business; package tourplaner.business;
import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import tourplaner.data.DbConnect;
import tourplaner.object.Log; import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PdfWriter;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; 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 { public class Reporter {
private static Font catFont = new Font(Font.TIMES_ROMAN, 18, private static Font catFont = new Font(Font.TIMES_ROMAN, 18,
@ -39,6 +37,63 @@ public class Reporter {
private static Font smallBold = new Font(Font.TIMES_ROMAN, 12, private static Font smallBold = new Font(Font.TIMES_ROMAN, 12,
Font.BOLD); 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) { public static void createTourReport(String tourname) {
Tour tour = TourPlaner.getTour(tourname); Tour tour = TourPlaner.getTour(tourname);
tour.setLog(TourPlaner.getLogs(tourname)); tour.setLog(TourPlaner.getLogs(tourname));
@ -61,159 +116,128 @@ public class Reporter {
// Reader // Reader
// under File -> Properties // under File -> Properties
private static void addMetaData(Document document, Tour tour) { private static void addMetaData(Document document, Tour tour) {
document.addTitle("Tour Report -> " + tour.getName()); document.addTitle(ConfigHelper.getLangIniString("tourreportvon") + tour.getName());
document.addSubject("Tourplaner by DerGeorg"); document.addSubject(ConfigHelper.getLangIniString("tourplanervon"));
document.addKeywords("Tourplaner, Tour, Report"); document.addKeywords(ConfigHelper.getLangIniString("reportkeywords"));
document.addAuthor("Tourplaner"); document.addAuthor(ConfigHelper.getLangIniString("tourplaner"));
document.addCreator("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 { private static void addContent(Document document, Tour tour) throws DocumentException {
Anchor anchor = new Anchor("Tour Report von -> " + tour.getName(), catFont); Anchor anchor = new Anchor(ConfigHelper.getLangIniString("tourreportvon") + tour.getName(), catFont);
anchor.setName("Tour Report von -> " + tour.getName()); anchor.setName(ConfigHelper.getLangIniString("tourreportvon") + tour.getName());
// Second parameter is the number of the chapter // Second parameter is the number of the chapter
Chapter catPart = new Chapter(new Paragraph(anchor), 1); 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); Section subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Report erstellt von: " + System.getProperty("user.name") + ", " + new Date())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportvon") + System.getProperty("user.name") + ", " + new Date()));
subCatPart.add(new Paragraph("Startpunkt der Tour: " + tour.getStart())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportstart") + tour.getStart()));
subCatPart.add(new Paragraph("Zielpunkt der Tour: " + tour.getZiel())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportziel") + tour.getZiel()));
subCatPart.add(new Paragraph("Berechnete Dauer der Tour: " + tour.getDauer())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportdauercal") + tour.getDauer()));
subCatPart.add(new Paragraph("Berechnete Strecke der Tour: " + tour.getStrecke())); 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 // now add all this to the document
document.add(catPart); document.add(catPart);
Image image1 = null;
try {
image1 = Image.getInstance(TourPlaner.getImagePdfPath(tour.getName()));
image1.setAlignment(Element.ALIGN_CENTER);
image1.scaleAbsolute(600, 400);
document.add(image1);
} catch (IOException e) {
LogHelper.error(e);
}
ArrayList<Log> logs = tour.getLogs(); ArrayList<Log> logs = tour.getLogs();
// Second parameter is the number of the chapter // Second parameter is the number of the chapter
anchor = new Anchor("Logs", catFont); anchor = new Anchor(ConfigHelper.getLangIniString("logs"), catFont);
anchor.setName("Logs"); anchor.setName(ConfigHelper.getLangIniString("logs"));
catPart = new Chapter(new Paragraph(anchor), 2); 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) { 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 = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Dauer: " + log.getDauer())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logdauer") + log.getDauer()));
subCatPart.add(new Paragraph("Davon Pause: " + log.getPause())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logpause") + log.getPause()));
subCatPart.add(new Paragraph("Davon gegangen: " + log.getGegangen())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("loggegangen") + log.getGegangen()));
subCatPart.add(new Paragraph("Berechnete Durchschnittliche Geschwindigkeit: " + log.getAvgspeed())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logavg")+ log.getAvgspeed()));
subCatPart.add(new Paragraph("Entfernung: " + log.getStrecke())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logstrecke") + log.getStrecke()));
subCatPart.add(new Paragraph("Höhenmeter: " + log.getHightmeter())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("loghight") + log.getHightmeter()));
subCatPart.add(new Paragraph("Bemerkung: " + log.getBemerkung())); subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("logbemerkung") + log.getBemerkung()));
} }
// now add all this to the document // now add all this to the document
document.add(catPart); document.add(catPart);
} }
private static void createTable(Section subCatPart) /**
throws BadElementException { * Fügt eine leere zeile an den Paragraph an
PdfPTable table = new PdfPTable(5); * @param paragraph Hier wird hinzugefügt
* @param number Um wie viele Leere Zeilen hinzugefügt werden soll
// 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);
}
private static void addEmptyLine(Paragraph paragraph, int number) { private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" ")); 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);
//
// }
} }

View File

@ -4,9 +4,11 @@ import org.apache.log4j.Logger;
import tourplaner.data.DbConnect; import tourplaner.data.DbConnect;
import tourplaner.object.Log; import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import tourplaner.ui.ProgressBar;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -38,67 +40,171 @@ public class TourPlaner{
* @return false bei error * @return false bei error
*/ */
public static boolean editTour(String oldname, Tour tour) throws IOException { public static boolean editTour(String oldname, Tour tour) throws IOException {
ProgressBar progressBar = new ProgressBar("Edit...");
int step = progressBar.getProgressSize(3, 100);
FileHelper.delFile(new File(getImagePath(oldname))); FileHelper.delFile(new File(getImagePath(oldname)));
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName()); FileHelper.delFile(new File(getImagePdfPath(oldname)));
return new DbConnect().editTour(oldname, tour); progressBar.addProgress(step);
DirectionMap directionMap = new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
progressBar.addProgress(step);
tour.setDauer(directionMap.getDauer()+"");
tour.setStrecke(directionMap.getStrecke());
boolean ret = new DbConnect().editTour(oldname, tour);
progressBar.setProgress(100);
return ret;
} }
/**
* Löscht eine Tour
* @param tourname Tourname
* @return false bei error
*/
public static boolean delTour(String tourname){ public static boolean delTour(String tourname){
ProgressBar progressBar = new ProgressBar("Del...");
int step = progressBar.getProgressSize(3, 100);
FileHelper.delFile(new File(getImagePath(tourname))); FileHelper.delFile(new File(getImagePath(tourname)));
return new DbConnect().delTour(tourname); progressBar.addProgress(step);
FileHelper.delFile(new File(getImagePdfPath(tourname)));
progressBar.addProgress(step);
boolean ret = new DbConnect().delTour(tourname);
progressBar.setProgress(100);
return ret;
} }
/** /**
* Fügt eine Tour hinzu * Fügt eine Tour hinzu
* @param newTour Neue Tour * @param newTour Neue Tour
* @return false bei error * @return false bei error
*/ */
public static boolean addTour(Tour newTour) throws IOException { public static boolean addTour(Tour newTour, ProgressBar progressBar) throws IOException {
int step = progressBar.getProgressSize(2, 100);
DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName()); DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName());
return new DbConnect().addTour(newTour); progressBar.addProgress(step);
newTour.setDauer(directionMap.getDauer()+"");
newTour.setStrecke(directionMap.getStrecke());
boolean ret = new DbConnect().addTour(newTour);
progressBar.setProgress(100);
return ret;
} }
/**
* 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 { public static Image getImage(String tourname) throws IOException {
return FileHelper.getImage(new File(getImagePath(tourname))); 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){ public static String getImagePath(String tourname){
return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg"; 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){ public static void openImage(String tourname){
FileHelper.openDefault(getImagePath(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){ public static ArrayList<Log> getLogs(String tourname){
return new DbConnect().getLogs(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){ public static void doReport(String tourname){
Reporter.createTourReport(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){ public static Tour getTour(String tourname){
return new DbConnect().getTour(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){ public static boolean addLog(String tourname, Log log){
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0); if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
return new DbConnect().addLog(tourname, log); 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){ public static boolean delLog(String tourname, String id){
return new DbConnect().delLog(tourname, 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){ public static boolean editLog(String tourname, Log log){
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0); if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
return new DbConnect().editLog(tourname, log); return new DbConnect().editLog(tourname, log);
} }
/**
public static String getMapJson(String start, String ziel){ * Exportiert die Daten
// TODO: 14.04.2021 Map Quest * @param path Path zu den Daten
return start + " " + ziel; * @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);
} }
/**
* Sucht alle touren die den gegebenen tournamen enthalten
* @param tourname Name der zu suchen ist
* @return Alle touren die auf den Suchterm passen
*/
public static ArrayList<Tour> sucheTour(String tourname){
ArrayList<Tour> touren = new ArrayList<>();
getAllTours().forEach(t ->{
if(t.getName().contains(tourname)){
touren.add(t);
}
});
return touren;
}
} }

View File

@ -1,13 +1,13 @@
package tourplaner.data; package tourplaner.data;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import tourplaner.business.LogHelper;
import tourplaner.object.Log; import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import tourplaner.ui.AlertHelper;
import tourplaner.ui.ProgressBar;
import java.sql.Connection; import java.sql.*;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
@ -84,6 +84,21 @@ public class DbConnect {
return !result.contains(false); 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){ public ArrayList<Log> getLogs(String tourname){
this.c = PostgresHelper.con(); this.c = PostgresHelper.con();
@ -140,21 +155,38 @@ public class DbConnect {
} }
public boolean delLog(String tourname, String id){ public boolean delLog(String tourname, String id){
System.out.println("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'");
return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'"); return PostgresHelper.executeUpdate("DELETE FROM public.log WHERE tourname = '"+tourname+"' and id = '"+id+"'");
} }
private int getTourSize() throws SQLException {
Connection con = PostgresHelper.con();
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM tour;");
int size =0;
if (rs != null)
{
rs.last(); // moves cursor to the last row
size = rs.getInt("count"); // get row id
con.close();
return size;
}
con.close();
return -1;
}
/** /**
* Holt alle Touren aus der Datenbank * Holt alle Touren aus der Datenbank
* @return Null bei fehler, sonst eine List aus den IDs * @return Null bei fehler, sonst eine List aus den IDs
*/ */
public ArrayList<Tour> getAllTouren(){ public ArrayList<Tour> getAllTouren() {
this.c = PostgresHelper.con(); this.c = PostgresHelper.con();
String tourname, mapjson, start, ziel; String tourname, mapjson, start, ziel;
double dauer, strecke; double dauer, strecke;
ArrayList<Tour> touren = new ArrayList<>(); ArrayList<Tour> touren = new ArrayList<>();
ProgressBar progressBar = new ProgressBar("Get...");
try { try {
int tourSize = getTourSize();
int step = progressBar.getProgressSize(tourSize, 100);
stmt = this.c.createStatement(); stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from tour;"); ResultSet rs = stmt.executeQuery("select * from tour;");
while (rs.next()) { while (rs.next()) {
@ -165,17 +197,21 @@ public class DbConnect {
dauer = rs.getDouble("dauer"); dauer = rs.getDouble("dauer");
strecke = rs.getDouble("strecke"); strecke = rs.getDouble("strecke");
if (!tourname.isEmpty()) { 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)));
progressBar.addProgress(step);
}else { }else {
progressBar.setProgress(100);
return null; return null;
} }
} }
progressBar.setProgress(100);
rs.close(); rs.close();
stmt.close(); stmt.close();
this.c.close(); this.c.close();
return touren; return touren;
} catch (Exception e) { } catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage()); LogHelper.error(e);
progressBar.setProgress(100);
return null; return null;
} }
} }

View File

@ -21,6 +21,16 @@ public class Tour {
this.log = new ArrayList<>(); 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){ public void setTour(Tour tour){
this.dauer = tour.getDauer(); this.dauer = tour.getDauer();
this.mapJson = tour.getMapJson(); this.mapJson = tour.getMapJson();

View File

@ -45,18 +45,27 @@
<menus> <menus>
<Menu fx:id="menueFile" mnemonicParsing="false" text="Datei"> <Menu fx:id="menueFile" mnemonicParsing="false" text="Datei">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#reportSum" text="Report Summary" />
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report" />
<MenuItem fx:id="beendenButton" mnemonicParsing="false" onAction="#quitApp" text="Beenden" /> <MenuItem fx:id="beendenButton" mnemonicParsing="false" onAction="#quitApp" text="Beenden" />
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Bearbeiten"> <Menu mnemonicParsing="false" text="Bearbeiten">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" /> <MenuItem mnemonicParsing="false" onAction="#importBtn" text="Import" />
<MenuItem mnemonicParsing="false" onAction="#exportBtn" text="Export" />
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Optionen"> <Menu mnemonicParsing="false" text="Optionen">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" /> <CheckMenuItem mnemonicParsing="false" text="Map automatisch öffnen" />
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" /> <CheckMenuItem mnemonicParsing="false" text="Report automatisch öffnen" />
<Menu mnemonicParsing="false" text="Sprache">
<items>
<RadioMenuItem mnemonicParsing="false" text="Deutsch" />
<RadioMenuItem mnemonicParsing="false" text="Englisch" />
</items>
</Menu>
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Hilfe"> <Menu mnemonicParsing="false" text="Hilfe">
@ -115,7 +124,7 @@
<tabs> <tabs>
<Tab fx:id="kartenTab" text="Karte"> <Tab fx:id="kartenTab" text="Karte">
<AnchorPane> <AnchorPane>
<ImageView fx:id="mapImageView" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="13.0" AnchorPane.rightAnchor="825.0" AnchorPane.topAnchor="0.0" /> <ImageView fx:id="mapImageView" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</AnchorPane> </AnchorPane>
</Tab> </Tab>
<Tab fx:id="beschreibungTab" text="Beschreibung"> <Tab fx:id="beschreibungTab" text="Beschreibung">

View File

@ -11,6 +11,11 @@ import javafx.stage.Stage;
import javafx.stage.WindowEvent; import javafx.stage.WindowEvent;
import tourplaner.business.ConfigHelper; import tourplaner.business.ConfigHelper;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.time.LocalDate; import java.time.LocalDate;
@ -229,4 +234,24 @@ public class AlertHelper {
stage.showAndWait(); stage.showAndWait();
return selectedDate.get(); 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;
}
} }

View File

@ -0,0 +1,52 @@
package tourplaner.ui;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
public class ProgressBar {
private int status;
private JFrame frame;
private JProgressBar progressBar;
public ProgressBar(String title){
this.frame = new JFrame(title);
this.frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
Container content = this.frame.getContentPane();
this.progressBar = new JProgressBar();
this.progressBar.setValue(0);
this.progressBar.setStringPainted(true);
TitledBorder border = BorderFactory.createTitledBorder("Laden....");
this.progressBar.setBorder(border);
content.add(this.progressBar, BorderLayout.NORTH);
this.frame.setSize(300, 100);
this.frame.setVisible(true);
}
public void addProgress(int add){
this.status += add;
this.progressBar.setValue(this.status);
closeOnFinish();
}
private void closeOnFinish(){
if(this.status >= 100){
closeProgress();
}
}
public void setProgress(int set){
this.status = set;
closeOnFinish();
}
public void closeProgress(){
this.frame.setVisible(false);
}
public int getProgressSize(int todo, int maxLevel){
int steps = (progressBar.getValue() - maxLevel) / todo;
if(steps < 0) steps = steps*-1;
return steps;
}
}

View File

@ -17,6 +17,7 @@ import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import tourplaner.viewmodels.ViewModel; import tourplaner.viewmodels.ViewModel;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -92,17 +93,18 @@ public class TourplanerController implements Initializable {
} }
private void syncTour(String selectedItem){ private void syncTour(String selectedItem){
beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett beschreibungTableView.getItems().clear(); //Leert die Table View komplett
beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem)); beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
mapImageView.setImage(this.viewModel.getImage(selectedItem)); mapImageView.setImage(this.viewModel.getImage(selectedItem));
} }
private void syncTourNamen(){ private void syncTourNamen(){
TourListView.getItems().clear();
TourListView.setItems(this.viewModel.getTourNamen()); TourListView.setItems(this.viewModel.getTourNamen());
} }
private void syncLogs(){ private void syncLogs(){
logTableView.getItems().removeIf(s -> true); logTableView.getItems().clear();
logTableView.setItems(this.viewModel.getLogData()); logTableView.setItems(this.viewModel.getLogData());
} }
@ -113,10 +115,13 @@ public class TourplanerController implements Initializable {
*/ */
@FXML @FXML
private void tourListSelectedItem(MouseEvent mouseEvent){ private void tourListSelectedItem(MouseEvent mouseEvent){
ProgressBar progressBar = new ProgressBar("Tour auswählen...");
String selectedItem = TourListView.getSelectionModel().getSelectedItem(); String selectedItem = TourListView.getSelectionModel().getSelectedItem();
this.viewModel.selectTour(selectedItem); this.viewModel.selectTour(selectedItem);
titleTextView.setText(selectedItem); titleTextView.setText(selectedItem);
progressBar.addProgress(10);
syncTour(selectedItem); syncTour(selectedItem);
progressBar.addProgress(10);
startCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("start")); startCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("start"));
zielCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("ziel")); zielCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("ziel"));
dauerCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("dauer")); dauerCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("dauer"));
@ -125,8 +130,10 @@ public class TourplanerController implements Initializable {
//Log anzeigen //Log anzeigen
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinelogsvorhanden"))); logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinelogsvorhanden")));
logTableView.getItems().removeIf(s -> true); logTableView.getItems().clear();
progressBar.addProgress(10);
logTableView.setItems(this.viewModel.getLogData()); logTableView.setItems(this.viewModel.getLogData());
progressBar.addProgress(10);
logDauerCol.setCellValueFactory(new PropertyValueFactory<Log, String>("dauer")); logDauerCol.setCellValueFactory(new PropertyValueFactory<Log, String>("dauer"));
logStreckeCol.setCellValueFactory(new PropertyValueFactory<Log, String>("strecke")); logStreckeCol.setCellValueFactory(new PropertyValueFactory<Log, String>("strecke"));
logDatumCol.setCellValueFactory(new PropertyValueFactory<Log, String>("datum")); logDatumCol.setCellValueFactory(new PropertyValueFactory<Log, String>("datum"));
@ -135,8 +142,16 @@ public class TourplanerController implements Initializable {
logPauseCol.setCellValueFactory(new PropertyValueFactory<Log, String>("pause")); logPauseCol.setCellValueFactory(new PropertyValueFactory<Log, String>("pause"));
logGegangenCol.setCellValueFactory(new PropertyValueFactory<Log, String>("gegangen")); logGegangenCol.setCellValueFactory(new PropertyValueFactory<Log, String>("gegangen"));
logBemerkungCol.setCellValueFactory(new PropertyValueFactory<Log, String>("bemerkung")); logBemerkungCol.setCellValueFactory(new PropertyValueFactory<Log, String>("bemerkung"));
progressBar.addProgress(10);
mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName())); mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
if(this.viewModel.isSucheAktiv()){
this.viewModel.setSucheAktiv(false);
progressBar.addProgress(10);
syncTourNamen();
progressBar.addProgress(40);
this.sucheInput.setText("");
}
progressBar.addProgress(50);
} }
/** /**
@ -154,8 +169,7 @@ public class TourplanerController implements Initializable {
*/ */
@FXML @FXML
private void addTour(){ private void addTour(){
this.viewModel.addTour(); if(this.viewModel.addTour()) this.mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
this.mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
} }
/** /**
@ -164,7 +178,7 @@ public class TourplanerController implements Initializable {
*/ */
@FXML @FXML
private void delTour(){ private void delTour(){
this.beschreibungTableView.getItems().removeIf(s -> true); //löscht alles aus der tabelle this.beschreibungTableView.getItems().clear(); //löscht alles aus der tabelle
this.titleTextView.setText(ConfigHelper.getLangIniString("keinetourselected")); this.titleTextView.setText(ConfigHelper.getLangIniString("keinetourselected"));
this.viewModel.delTour(); this.viewModel.delTour();
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected"))); logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
@ -177,7 +191,10 @@ public class TourplanerController implements Initializable {
*/ */
@FXML @FXML
private void suche(){ private void suche(){
ProgressBar progressBar = new ProgressBar("Suche");
this.viewModel.suche(this.sucheInput.getText()); this.viewModel.suche(this.sucheInput.getText());
progressBar.addProgress(100);
progressBar.closeProgress();
} }
/** /**
@ -216,12 +233,33 @@ public class TourplanerController implements Initializable {
TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
TourListView.setOrientation(Orientation.VERTICAL); TourListView.setOrientation(Orientation.VERTICAL);
syncTourNamen(); syncTourNamen();
deselectAll();
}
private void deselectAll(){
//Tabs zu Tour -> rechts oben //Tabs zu Tour -> rechts oben
beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected"))); beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
titleTextView.setText( ConfigHelper.getLangIniString("keinetourselected")); titleTextView.setText( ConfigHelper.getLangIniString("keinetourselected"));
//Log -> rechts unten //Log -> rechts unten
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected"))); 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();
} }
/** /**

View File

@ -3,12 +3,11 @@ package tourplaner.viewmodels;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import tourplaner.business.TourPlaner; import tourplaner.business.*;
import tourplaner.ui.AlertHelper; import tourplaner.ui.AlertHelper;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import tourplaner.object.Log; import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import tourplaner.ui.ProgressBar;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
@ -23,13 +22,14 @@ import java.util.concurrent.atomic.AtomicReference;
public class ViewModel { public class ViewModel {
//Tour //Tour
private final ObservableList<Tour> tourData = FXCollections.observableArrayList(); private final ObservableList<Tour> tourData = FXCollections.observableArrayList();
private final ObservableList<String> tourNamen = FXCollections.observableArrayList(); private ObservableList<String> tourNamen = FXCollections.observableArrayList();
private Tour selectedTour; private Tour selectedTour;
private String neueTourName, neueTourStart, neueTourZiel, neueBemerkung; private String neueTourName, neueTourStart, neueTourZiel, neueBemerkung;
//Log //Log
private final ObservableList<Log> logData = FXCollections.observableArrayList(); private final ObservableList<Log> logData = FXCollections.observableArrayList();
private Log selectedLog; private Log selectedLog;
// Suche
private boolean sucheAktiv;
public Image getImage(String tourname){ public Image getImage(String tourname){
@ -79,9 +79,10 @@ public class ViewModel {
/** /**
* Input mit duplications check des Namens und ohne content im input feld * Input mit duplications check des Namens und ohne content im input feld
* @return false beim schließen
*/ */
private void tourNameInput(){ private boolean tourNameInput(){
tourNameInputDuplicatCheck("", true); return tourNameInputDuplicatCheck("", true);
} }
/** /**
@ -152,24 +153,31 @@ public class ViewModel {
/** /**
* Fügt eine neue Tour hinzu * Fügt eine neue Tour hinzu
*/ */
public void addTour(){ public boolean addTour(){
tourNameInput(); if(tourNameInput()) {
tourStartInput(""); if(tourStartInput("")) {
tourZielInput(""); if (tourZielInput("")) {
if (getTour(this.neueTourName) == null) { if (getTour(this.neueTourName) == null) {
ProgressBar progressBar = new ProgressBar("Add Tour...");
Tour newTour = new Tour(this.neueTourName, "1", "1", 0, this.neueTourStart, this.neueTourZiel); Tour newTour = new Tour(this.neueTourName, "1", "1", 0, this.neueTourStart, this.neueTourZiel);
tourData.add(newTour); tourData.add(newTour);
tourNamen.add(this.neueTourName); tourNamen.add(this.neueTourName);
this.selectedTour = newTour; this.selectedTour = newTour;
progressBar.addProgress(10);
try { try {
TourPlaner.addTour(newTour); TourPlaner.addTour(newTour, progressBar);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LogHelper.error(e);
return false;
} }
} }
}else return false;
}else return false;
}else return false;
this.neueTourStart = null; this.neueTourStart = null;
this.neueTourZiel = null; this.neueTourZiel = null;
this.neueTourName = null; this.neueTourName = null;
return true;
} }
private boolean keineTourSelected(){ private boolean keineTourSelected(){
@ -208,11 +216,11 @@ public class ViewModel {
if (dauer >= 0) { if (dauer >= 0) {
strecke = streckeInput(this.selectedLog.getStrecke() + ""); strecke = streckeInput(this.selectedLog.getStrecke() + "");
if (strecke >= 0) { if (strecke >= 0) {
pause = pauseInput(""); pause = pauseInput(this.selectedLog.getPause() + "");
if(pause >= 0.0) { if(pause >= 0.0) {
hightmeter = hightmeterInput(""); hightmeter = hightmeterInput(this.selectedLog.getHightmeter() + "");
if (hightmeter >= 0.0) { if (hightmeter >= 0.0) {
bemerkung = bemerkungInput(""); bemerkung = bemerkungInput(this.selectedLog.getBemerkung());
if (bemerkung) { if (bemerkung) {
datum = dateInput(this.selectedLog.getDatum()); datum = dateInput(this.selectedLog.getDatum());
if (datum != null) { if (datum != null) {
@ -458,7 +466,7 @@ public class ViewModel {
getTourData().forEach(s -> { getTourData().forEach(s -> {
namen.add(s.getName()); namen.add(s.getName());
}); });
tourNamen.removeAll(); tourNamen.clear();
tourNamen.addAll(namen); tourNamen.addAll(namen);
return tourNamen; return tourNamen;
} }
@ -480,9 +488,11 @@ public class ViewModel {
} }
public ObservableList<Tour> getTourData() { public ObservableList<Tour> getTourData() {
tourData.removeAll(); tourData.clear();
// ObservableList<Tour> data = ; ArrayList<Tour> touren = TourPlaner.getAllTours();
tourData.addAll(TourPlaner.getAllTours()); if(touren != null) {
tourData.addAll(touren);
}
return tourData; return tourData;
} }
@ -516,7 +526,20 @@ public class ViewModel {
ConfigHelper.getLangIniString("suchfeldleer"), ConfigHelper.getLangIniString("suchfeldleer"),
ConfigHelper.getLangIniString("suchtextzuerst")); ConfigHelper.getLangIniString("suchtextzuerst"));
} }
// TODO: 19.03.2021 Suchlogik ArrayList<Tour> result = TourPlaner.sucheTour(sucheInput);
tourNamen.clear();
for (Tour tour:result) {
tourNamen.add(tour.getName());
}
this.sucheAktiv = true;
}
public boolean isSucheAktiv() {
return sucheAktiv;
}
public void setSucheAktiv(boolean sucheAktiv) {
this.sucheAktiv = sucheAktiv;
} }
/** /**
@ -583,4 +606,38 @@ public class ViewModel {
TourPlaner.doReport(this.selectedTour.getName()); 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");
if (file != null){
this.tourNamen = FXCollections.observableArrayList();
new Exporter(file).doImport();
}
}
/**
* Erstellt einen Summary Report
*/
public void sumReport(){
Reporter.sumReport();
}
} }