Compare commits

..

5 Commits

16 changed files with 44 additions and 431 deletions

View File

@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="iText-4.2.0-com.itextpdf">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/iText-4.2.0-com.itextpdf.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -10,7 +10,7 @@
<orderEntry type="library" name="lib" level="project" /> <orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="org.ini4j:ini4j:0.5.4" level="project" /> <orderEntry type="library" name="org.ini4j:ini4j:0.5.4" level="project" />
<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.apache.pdfbox:pdfbox:1.8.9" 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" />
</component> </component>
</module> </module>

View File

@ -19,10 +19,4 @@ path = ./reports/
[hilfe] [hilfe]
gitrepo = https://git.dergeorg.at/dergeorg/tourplaner gitrepo = https://git.dergeorg.at/dergeorg/tourplaner
doxygendoc = https://git.dergeorg.at/dergeorg/tourplaner doxygendoc = https://git.dergeorg.at/dergeorg/tourplaner
javadoc = https://git.dergeorg.at/dergeorg/tourplaner javadoc = https://git.dergeorg.at/dergeorg/tourplaner
[map]
key =
size = 1500,400
path = D:\\TourplanerImages\\
file_pre = file:///

Binary file not shown.

View File

@ -1,33 +0,0 @@
package tourplaner.business;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
public class DirectionMap {
private double dauer, strecke;
private String start, end, tourname, file;
private Image map;
public DirectionMap (String start, String ende, String tourname) throws IOException {
this.map = getMap(start, ende);
this.start = start;
this.end = ende;
this.tourname = tourname;
this.file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + this.tourname + ".jpg";
FileHelper.saveImage(this.map, "jpg", new File(file));
FileHelper.openDefault(file);
}
private Image getMap(String start, String ende) throws IOException {
return HttpHelper.httpGetStaticMap(start, ende);
}
}

View File

@ -1,36 +0,0 @@
package tourplaner.business;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class FileHelper {
public static void openDefault(String f){
// A reference to a text file
File file = new File(f);
try {
Desktop desktop = Desktop.getDesktop();
// Open a file using the default program for the file type. In the example
// we will launch a default registered program to open a text file. For
// example on Windows operating system this call might launch a notepad.exe
// to open the file.
desktop.open(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void saveImage(Image img, String type, File file) throws IOException {
ImageIO.write(ImgHelper.toBufferedImage(img), type, file);
}
public static BufferedImage getImage(File file) throws IOException {
return ImageIO.read(file);
}
}

View File

@ -1,14 +0,0 @@
package tourplaner.business;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
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"));
return ImageIO.read(url);
}
}

View File

@ -1,32 +0,0 @@
package tourplaner.business;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ImgHelper {
/**
* Converts a given Image into a BufferedImage
*
* @param img The Image to be converted
* @return The converted BufferedImage
*/
public static BufferedImage toBufferedImage(Image img)
{
if (img instanceof BufferedImage)
{
return (BufferedImage) img;
}
// Create a buffered image with transparency
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();
// Return the buffered image
return bimage;
}
}

View File

@ -33,14 +33,6 @@ public class LogHelper{
getLog(name).error(msg); getLog(name).error(msg);
} }
/**
* Log info in file und Console
* @param e Exception
*/
public static void error(Exception e){
getLog(e.getClass().getName()).error(e.getMessage());
}
/** /**
* Log info in file und Console * Log info in file und Console
* @param msg Nachricht in dem Log * @param msg Nachricht in dem Log

View File

@ -1,219 +1,34 @@
package tourplaner.business; package tourplaner.business;
import tourplaner.object.Log; import org.apache.pdfbox.exceptions.COSVisitorException;
import tourplaner.object.Tour; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
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.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
public class Reporter { public class Reporter {
private static Font catFont = new Font(Font.TIMES_ROMAN, 18, public static void createTourReport(String tourname) throws IOException, COSVisitorException {
Font.BOLD); PDDocument document = new PDDocument();
private static Font redFont = new Font(Font.TIMES_ROMAN, 12, PDPage page = new PDPage();
Font.NORMAL, Color.RED); document.addPage(page);
private static Font subFont = new Font(Font.TIMES_ROMAN, 16,
Font.BOLD);
private static Font smallBold = new Font(Font.TIMES_ROMAN, 12,
Font.BOLD);
public static void createTourReport(String tourname) { PDFont font = PDType1Font.HELVETICA;
Tour tour = TourPlaner.getTour(tourname); PDPageContentStream contentStream = new PDPageContentStream(document, page);
tour.setLog(TourPlaner.getLogs(tourname)); contentStream.beginText();
String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + tourname+".pdf"; contentStream.setFont(font, 12);
try { contentStream.moveTextPositionByAmount(100,700);
Document document = new Document(); contentStream.drawString(tourname);
PdfWriter.getInstance(document, new FileOutputStream(file)); // contentStream.drawString();
document.open(); contentStream.endText();
addMetaData(document, tour);
// addTitlePage(document, tour); contentStream.close();
addContent(document, tour);
document.close(); document.save(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + "test.pdf");
} catch (DocumentException | FileNotFoundException e) { document.close();
LogHelper.error(e.getMessage(), e.getClass().getName());
}
FileHelper.openDefault(file);
} }
// iText allows to add metadata to the PDF which can be viewed in your Adobe
// Reader
// under File -> Properties
private static void addMetaData(Document document, Tour tour) {
document.addTitle("Tour Report -> " + tour.getName());
document.addSubject("Tourplaner by DerGeorg");
document.addKeywords("Tourplaner, Tour, Report");
document.addAuthor("Tourplaner");
document.addCreator("Tourplaner");
}
private static void addContent(Document document, Tour tour) throws DocumentException {
Anchor anchor = new Anchor("Tour Report von -> " + tour.getName(), catFont);
anchor.setName("Tour Report von -> " + tour.getName());
// Second parameter is the number of the chapter
Chapter catPart = new Chapter(new Paragraph(anchor), 1);
Paragraph subPara = new Paragraph("Tour", subFont);
Section subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Report erstellt von: " + System.getProperty("user.name") + ", " + new Date()));
subCatPart.add(new Paragraph("Startpunkt der Tour: " + tour.getStart()));
subCatPart.add(new Paragraph("Zielpunkt der Tour: " + tour.getZiel()));
subCatPart.add(new Paragraph("Berechnete Dauer der Tour: " + tour.getDauer()));
subCatPart.add(new Paragraph("Berechnete Strecke der Tour: " + tour.getStrecke()));
// now add all this to the document
document.add(catPart);
ArrayList<Log> logs = tour.getLogs();
// Second parameter is the number of the chapter
anchor = new Anchor("Logs", catFont);
anchor.setName("Logs");
catPart = new Chapter(new Paragraph(anchor), 2);
catPart.add(new Paragraph("Anzahl der Logeinträge: " + logs.size()));
for (Log log: logs) {
subPara = new Paragraph("Log vom: " + log.getDatum() , subFont);
subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Dauer: " + log.getDauer()));
subCatPart.add(new Paragraph("Davon Pause: " + log.getPause()));
subCatPart.add(new Paragraph("Davon gegangen: " + log.getGegangen()));
subCatPart.add(new Paragraph("Berechnete Durchschnittliche Geschwindigkeit: " + log.getAvgspeed()));
subCatPart.add(new Paragraph("Entfernung: " + log.getStrecke()));
subCatPart.add(new Paragraph("Höhenmeter: " + log.getHightmeter()));
subCatPart.add(new Paragraph("Bemerkung: " + log.getBemerkung()));
}
// now add all this to the document
document.add(catPart);
}
private static void createTable(Section subCatPart)
throws BadElementException {
PdfPTable table = new PdfPTable(5);
// t.setBorderColor(BaseColor.GRAY);
// t.setPadding(4);
// t.setSpacing(4);
// t.setBorderWidth(1);
PdfPCell c1 = new PdfPCell(new Phrase("NR"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Datum"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Entfernung"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Höhenmeter"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("AVG Geschwindigkeit"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);
table.addCell("1.0");
table.addCell("1.1");
table.addCell("1.2");
table.addCell("1.3");
table.addCell("1.4");
table.addCell("1.5");
table.addCell("2.0");
table.addCell("2.1");
table.addCell("2.2");
table.addCell("2.3");
table.addCell("2.4");
table.addCell("2.5");
subCatPart.add(table);
}
private static void createTable2(Section subCatPart)
throws BadElementException {
PdfPTable table = new PdfPTable(5);
// t.setBorderColor(BaseColor.GRAY);
// t.setPadding(4);
// t.setSpacing(4);
// t.setBorderWidth(1);
PdfPCell c1 = new PdfPCell(new Phrase("NR"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Dauer"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Davon Gegangen"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Davon Pause"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Bemerkung"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);
table.addCell("1.0");
table.addCell("1.1");
table.addCell("1.2");
table.addCell("1.3");
table.addCell("1.4");
table.addCell("1.5");
table.addCell("2.0");
table.addCell("2.1");
table.addCell("2.2");
table.addCell("2.3");
table.addCell("2.4");
table.addCell("2.5");
subCatPart.add(table);
}
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" "));
}
}
} }

View File

@ -1,12 +1,12 @@
package tourplaner.business; package tourplaner.business;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.pdfbox.exceptions.COSVisitorException;
import tourplaner.data.DbConnect; import tourplaner.data.DbConnect;
import tourplaner.data.PostgresHelper;
import tourplaner.object.Log; import tourplaner.object.Log;
import tourplaner.object.Tour; import tourplaner.object.Tour;
import java.awt.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,39 +44,29 @@ public class TourPlaner{
public static boolean delTour(String tourname){ public static boolean delTour(String tourname){
return new DbConnect().delTour(tourname); return new DbConnect().delTour(tourname);
} }
/** /**
* 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){
DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName());
return new DbConnect().addTour(newTour); return new DbConnect().addTour(newTour);
} }
public static Image getImage(String tourname) throws IOException {
return FileHelper.getImage(new File(getImagePath(tourname)));
}
public static String getImagePath(String tourname){
return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg";
}
public static void openImage(String tourname){
FileHelper.openDefault(getImagePath(tourname));
}
public static ArrayList<Log> getLogs(String tourname){ public static ArrayList<Log> getLogs(String tourname){
return new DbConnect().getLogs(tourname); return new DbConnect().getLogs(tourname);
} }
public static void doReport(String tourname){ public static void doReport(String tourname){
Reporter.createTourReport(tourname); try {
} Reporter.createTourReport(tourname);
} catch (IOException e) {
public static Tour getTour(String tourname){ LogHelper.error(e.getMessage(), e.getClass().getName());
return new DbConnect().getTour(tourname); } catch (COSVisitorException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
} }
public static boolean addLog(String tourname, Log log){ public static boolean addLog(String tourname, Log log){

View File

@ -180,41 +180,4 @@ public class DbConnect {
} }
} }
/**
* Holt eine Tour aus der Datenbank
* @param tn Tourname
* @return Null bei fehler, sonst eine List aus den IDs
*/
public Tour getTour(String tn){
this.c = PostgresHelper.con();
String tourname, mapjson, start, ziel;
double dauer, strecke;
Tour touren = null;
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from tour where tourname = '"+tn+"';");
while (rs.next()) {
tourname = rs.getString("tourname");
mapjson = rs.getString("mapjson");
start = rs.getString("start");
ziel = rs.getString("ziel");
dauer = rs.getDouble("dauer");
strecke = rs.getDouble("strecke");
if (!tourname.isEmpty()) {
touren = new Tour(tourname, dauer + "", mapjson, strecke, start, ziel);
}else {
return null;
}
}
rs.close();
stmt.close();
this.c.close();
return touren;
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
return null;
}
}
} }

View File

@ -31,10 +31,6 @@ public class Tour {
this.log = tour.getLogs(); this.log = tour.getLogs();
} }
public void setLog(ArrayList<Log> log) {
this.log = log;
}
/** /**
* Holt einen einzigen Log Eintrag anhand der Id * Holt einen einzigen Log Eintrag anhand der Id
* @param id Id des Eintrags der zu besorgen ist * @param id Id des Eintrags der zu besorgen ist

View File

@ -34,7 +34,6 @@
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?> <?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
@ -113,11 +112,10 @@
<children> <children>
<TabPane fx:id="viewTabPane" layoutX="1.0" layoutY="69.0" prefWidth="702.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="-67.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0"> <TabPane fx:id="viewTabPane" layoutX="1.0" layoutY="69.0" prefWidth="702.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="-67.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0">
<tabs> <tabs>
<Tab fx:id="kartenTab" text="Karte"> <Tab fx:id="kartenTab" text="Karte">
<AnchorPane> <content>
<ImageView fx:id="mapImageView" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="13.0" AnchorPane.rightAnchor="825.0" AnchorPane.topAnchor="0.0" /> <AnchorPane />
</AnchorPane> </content></Tab>
</Tab>
<Tab fx:id="beschreibungTab" text="Beschreibung"> <Tab fx:id="beschreibungTab" text="Beschreibung">
<content> <content>
<AnchorPane> <AnchorPane>

View File

@ -8,7 +8,6 @@ import javafx.scene.control.*;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import tourplaner.business.ConfigHelper; import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper; import tourplaner.business.LogHelper;
@ -38,7 +37,6 @@ public class TourplanerController implements Initializable {
public TableView<Tour> beschreibungTableView; public TableView<Tour> beschreibungTableView;
public TableColumn<Tour, String> startCol, zielCol, dauerCol, streckeCol, nameCol; public TableColumn<Tour, String> startCol, zielCol, dauerCol, streckeCol, nameCol;
public TextField titleTextView, sucheInput; public TextField titleTextView, sucheInput;
public ImageView mapImageView;
//Log -> rechts unten //Log -> rechts unten
public TableView<Log> logTableView; public TableView<Log> logTableView;
public TableColumn<Log, String> logDauerCol, logStreckeCol, logDatumCol, logAvgCol, logHightCol, logPauseCol, logGegangenCol, logBemerkungCol; public TableColumn<Log, String> logDauerCol, logStreckeCol, logDatumCol, logAvgCol, logHightCol, logPauseCol, logGegangenCol, logBemerkungCol;
@ -131,7 +129,6 @@ public class TourplanerController implements Initializable {
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"));
mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
} }
/** /**
@ -150,7 +147,6 @@ public class TourplanerController implements Initializable {
@FXML @FXML
private void addTour(){ private void addTour(){
this.viewModel.addTour(); this.viewModel.addTour();
this.mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
} }
/** /**

View File

@ -2,8 +2,10 @@ 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 org.apache.pdfbox.exceptions.COSVisitorException;
import tourplaner.business.Reporter;
import tourplaner.business.TourPlaner; import tourplaner.business.TourPlaner;
import tourplaner.data.DbConnect;
import tourplaner.ui.AlertHelper; import tourplaner.ui.AlertHelper;
import tourplaner.business.ConfigHelper; import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper; import tourplaner.business.LogHelper;
@ -32,10 +34,6 @@ public class ViewModel {
public Image getImage(String tourname){
return new Image( ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "file_pre") + TourPlaner.getImagePath(tourname));
}
/** /**
* 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
@ -160,12 +158,7 @@ public class ViewModel {
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; TourPlaner.addTour(newTour);
try {
TourPlaner.addTour(newTour);
} catch (IOException e) {
e.printStackTrace();
}
} }
this.neueTourStart = null; this.neueTourStart = null;
this.neueTourZiel = null; this.neueTourZiel = null;