Compare commits

...

5 Commits
0.3.0 ... Map

16 changed files with 410 additions and 161 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

@ -39,4 +39,24 @@ pausemsg = Dauer der Pause
hightmeter = Höhenmeter 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,33 +1,89 @@
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
*
* @param start Startpunkt
* @param ende Endpunkt
* @param tourname Name der Aktuellen Tour
* @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);
} }
private Image getMap(String start, String ende) throws IOException { /**
return HttpHelper.httpGetStaticMap(start, ende); * 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
* @param start Startpunkt
* @param ende Endpunkt
* @return Image von der Map
* @throws IOException Fehler beim Get der Map
*/
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="+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(":");
minutes += Double.parseDouble(result[0]) * 60;
minutes += Double.parseDouble(result[1]);
minutes += Double.parseDouble(result[2]) / 60;
return minutes;
}
} }

View File

@ -0,0 +1,25 @@
package tourplaner.business;
import tourplaner.object.Data;
import java.io.FileWriter;
import java.io.IOException;
public class Exporter {
private Data data;
private String path;
public Exporter(Data data, String path) {
this.data = data;
this.path = path;
}
public void doExport() throws IOException {
JsonHelper.getJsonFromObj(data, new FileWriter(path));
}
public void doImport(){
}
}

View File

@ -9,6 +9,10 @@ import java.io.IOException;
public class FileHelper { public class FileHelper {
/**
* Öffnet ein File mit dem Standart Program
* @param f File Path als string
*/
public static void openDefault(String f){ public static void openDefault(String f){
// A reference to a text file // A reference to a text file
File file = new File(f); File file = new File(f);
@ -26,11 +30,33 @@ public class FileHelper {
} }
} }
/**
* Speichert ein Image
* @param img Das zu speichernde Bild
* @param type Dateityp z.b. jpg
* @param file Wo die datei zu speichern ist
* @throws IOException
*/
public static void saveImage(Image img, String type, File file) throws IOException { public static void saveImage(Image img, String type, File file) throws IOException {
ImageIO.write(ImgHelper.toBufferedImage(img), type, file); ImageIO.write(ImgHelper.toBufferedImage(img), type, file);
} }
/**
* Holt ein image von einem File
* @param file File mit dem image
* @return Das buffered image
* @throws IOException Fehler beim öffnen des bildes
*/
public static BufferedImage getImage(File file) throws IOException { public static BufferedImage getImage(File file) throws IOException {
return ImageIO.read(file); return ImageIO.read(file);
} }
/**
* Löscht ein File
* @param file File das zu löschen ist
* @return false bei error
*/
public static boolean delFile(File file){
return file.delete();
}
} }

View File

@ -2,13 +2,52 @@ 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;
/**
* Http Hilfsfunktionen
*/
public class HttpHelper { public class HttpHelper {
public static Image httpGetStaticMap(String start, String end) throws IOException { /**
URL url = new URL("https://www.mapquestapi.com/staticmap/v5/map?start="+start+"&end="+end+"&size="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "size")+"&key="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key")); * Holt ein Image von gegebener URL
return ImageIO.read(url); * @param url Url als Sting
* @return Image von der Url
* @throws IOException Fehler beim Bild holen
*/
public static Image httpGetImage(String url) throws IOException {
URL urls = new URL(url);
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

@ -3,6 +3,9 @@ package tourplaner.business;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
/**
* Image Hilfsfunktionen
*/
public class ImgHelper { public class ImgHelper {
/** /**

View File

@ -0,0 +1,59 @@
package tourplaner.business;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.FileWriter;
/**
* 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);
}
/**
* 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,30 @@
package tourplaner.business; package tourplaner.business;
import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
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 +36,10 @@ 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 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 +62,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

@ -37,11 +37,18 @@ public class TourPlaner{
* @param tour Neuer Tourname * @param tour Neuer Tourname
* @return false bei error * @return false bei error
*/ */
public static boolean editTour(String oldname, Tour tour){ public static boolean editTour(String oldname, Tour tour) throws IOException {
FileHelper.delFile(new File(getImagePath(oldname)));
FileHelper.delFile(new File(getImagePdfPath(oldname)));
DirectionMap directionMap = new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
tour.setDauer(directionMap.getDauer()+"");
tour.setStrecke(directionMap.getStrecke());
return new DbConnect().editTour(oldname, tour); return new DbConnect().editTour(oldname, tour);
} }
public static boolean delTour(String tourname){ public static boolean delTour(String tourname){
FileHelper.delFile(new File(getImagePath(tourname)));
FileHelper.delFile(new File(getImagePdfPath(tourname)));
return new DbConnect().delTour(tourname); return new DbConnect().delTour(tourname);
} }
/** /**
@ -51,6 +58,8 @@ public class TourPlaner{
*/ */
public static boolean addTour(Tour newTour) throws IOException { public static boolean addTour(Tour newTour) throws IOException {
DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName()); DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName());
newTour.setDauer(directionMap.getDauer()+"");
newTour.setStrecke(directionMap.getStrecke());
return new DbConnect().addTour(newTour); return new DbConnect().addTour(newTour);
} }
@ -61,6 +70,9 @@ public class TourPlaner{
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";
} }
public static String getImagePdfPath(String tourname){
return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + "_pdf.jpg";
}
public static void openImage(String tourname){ public static void openImage(String tourname){
FileHelper.openDefault(getImagePath(tourname)); FileHelper.openDefault(getImagePath(tourname));

View File

@ -0,0 +1,21 @@
package tourplaner.object;
import java.util.ArrayList;
public class Data {
private ArrayList<Log> logs;
private ArrayList<Tour> touren;
public Data(ArrayList<Log> logs, ArrayList<Tour> touren){
this.logs = logs;
this.touren = touren;
}
public ArrayList<Log> getLogs() {
return logs;
}
public ArrayList<Tour> getTouren() {
return touren;
}
}

View File

@ -115,7 +115,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

@ -51,7 +51,11 @@ public class TourplanerController implements Initializable {
@FXML @FXML
private void editTourBtn(){ private void editTourBtn(){
this.viewModel.editTour(); try {
this.viewModel.editTour();
} catch (IOException e) {
LogHelper.error(e);
}
syncTour(this.viewModel.getSelectedTour().getName()); syncTour(this.viewModel.getSelectedTour().getName());
} }
@ -90,6 +94,7 @@ 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().removeIf(s -> true); //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));
} }
private void syncTourNamen(){ private void syncTourNamen(){
@ -163,6 +168,7 @@ public class TourplanerController implements Initializable {
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")));
mapImageView.setImage(null);
} }
/** /**

View File

@ -40,7 +40,7 @@ public class ViewModel {
* Bearbeitet eine bereits bestehende Tour * Bearbeitet eine bereits bestehende Tour
* prüft ob eine tour ausgewählt ist * prüft ob eine tour ausgewählt ist
*/ */
public void editTour(){ public void editTour() throws IOException {
if (this.selectedTour == null){ if (this.selectedTour == null){
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"), AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
ConfigHelper.getLangIniString("keinetourselected"), ConfigHelper.getLangIniString("keinetourselected"),
@ -481,7 +481,6 @@ public class ViewModel {
public ObservableList<Tour> getTourData() { public ObservableList<Tour> getTourData() {
tourData.removeAll(); tourData.removeAll();
// ObservableList<Tour> data = ;
tourData.addAll(TourPlaner.getAllTours()); tourData.addAll(TourPlaner.getAllTours());
return tourData; return tourData;
} }