Compare commits

..

2 Commits
0.3.1 ... 0.3.3

Author SHA1 Message Date
93cb83e33e Get Mapquest Directions -> Strecke, Dauer 2021-04-16 17:07:49 +02:00
9fe6f34ba3 Kleine Map für Report 2021-04-15 23:24:31 +02:00
9 changed files with 132 additions and 26 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

@ -10,8 +10,8 @@ import java.io.IOException;
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 +22,27 @@ 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);
} }
public double getDauer() {
return dauer;
}
public double getStrecke() {
return strecke;
}
/** /**
* Downloadet die Map von Mapquest * Downloadet die Map von Mapquest
* @param start Startpunkt * @param start Startpunkt
@ -38,11 +50,22 @@ 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"));
} }
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"));
}
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

@ -1,8 +1,11 @@
package tourplaner.business; 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 +23,38 @@ public class HttpHelper {
URL urls = new URL(url); URL urls = new URL(url);
return ImageIO.read(urls); return ImageIO.read(urls);
} }
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,20 @@
package tourplaner.business;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public class JsonHelper {
public static String getStingFromJson(String json, String gets){
return getJObj(json).get("route").getAsJsonObject().get(gets).getAsString();
}
public static double getDoubleFromJson(String json, String gets){
return getJObj(json).get("route").getAsJsonObject().get(gets).getAsDouble();
}
private static JsonObject getJObj(String json){
return new Gson().fromJson(json, JsonObject.class);
}
}

View File

@ -1,21 +1,13 @@
package tourplaner.business; 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.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;
@ -28,6 +20,9 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
/**
* 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,
@ -82,15 +77,24 @@ public class Reporter {
subCatPart.add(new Paragraph("Zielpunkt der Tour: " + tour.getZiel())); subCatPart.add(new Paragraph("Zielpunkt der Tour: " + tour.getZiel()));
subCatPart.add(new Paragraph("Berechnete Dauer der Tour: " + tour.getDauer())); subCatPart.add(new Paragraph("Berechnete Dauer der Tour: " + tour.getDauer()));
subCatPart.add(new Paragraph("Berechnete Strecke der Tour: " + tour.getStrecke())); subCatPart.add(new Paragraph("Berechnete Strecke der Tour: " + 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("Logs", catFont);

View File

@ -39,12 +39,16 @@ public class TourPlaner{
*/ */
public static boolean editTour(String oldname, Tour tour) throws IOException { public static boolean editTour(String oldname, Tour tour) throws IOException {
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)));
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(getImagePath(tourname)));
FileHelper.delFile(new File(getImagePdfPath(tourname)));
return new DbConnect().delTour(tourname); return new DbConnect().delTour(tourname);
} }
/** /**
@ -54,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);
} }
@ -64,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

@ -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">