Progressbar Bugfixes
This commit is contained in:
parent
49b6407ce6
commit
d8c4680e16
@ -68,7 +68,10 @@ public class DirectionMap {
|
||||
* @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"));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class Exporter {
|
||||
* @throws IOException Fehler beim File erstellen
|
||||
*/
|
||||
public void doExport() throws IOException {
|
||||
ProgressBar progressBar = new ProgressBar("Exportieren");
|
||||
ProgressBar progressBar = new ProgressBar("Export...");
|
||||
int step = progressBar.getProgressSize(4, 100);
|
||||
ArrayList<Tour> data = new DbConnect().getAllTouren();
|
||||
progressBar.addProgress(step);
|
||||
@ -40,7 +40,7 @@ public class Exporter {
|
||||
JsonHelper.getJsonFromObj(data, fileWriter);
|
||||
progressBar.addProgress(step);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
||||
progressBar.addProgress(step);
|
||||
progressBar.setProgress(100);
|
||||
bufferedWriter.close();
|
||||
}
|
||||
|
||||
@ -48,25 +48,29 @@ public class Exporter {
|
||||
* Führt den Imput aus -> File holen, Daten in db erstellen
|
||||
* @throws IOException Fehler beim File öffnen
|
||||
*/
|
||||
public void doImport() throws IOException {
|
||||
this.touren = JsonHelper.getTourenFromJson(new FileReader(this.path));
|
||||
ProgressBar progressBar = new ProgressBar("Importiere Daten");
|
||||
DbConnect dbConnect = new DbConnect();
|
||||
progressBar.addProgress(5);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
progressBar.addProgress(size);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
progressBar.setProgress(100);
|
||||
}
|
||||
progressBar.addProgress(size);
|
||||
progressBar.setProgress(100);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.apache.log4j.Logger;
|
||||
import tourplaner.data.DbConnect;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
@ -39,12 +40,18 @@ public class TourPlaner{
|
||||
* @return false bei error
|
||||
*/
|
||||
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(getImagePdfPath(oldname)));
|
||||
progressBar.addProgress(step);
|
||||
DirectionMap directionMap = new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
|
||||
progressBar.addProgress(step);
|
||||
tour.setDauer(directionMap.getDauer()+"");
|
||||
tour.setStrecke(directionMap.getStrecke());
|
||||
return new DbConnect().editTour(oldname, tour);
|
||||
boolean ret = new DbConnect().editTour(oldname, tour);
|
||||
progressBar.setProgress(100);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,20 +60,30 @@ public class TourPlaner{
|
||||
* @return false bei error
|
||||
*/
|
||||
public static boolean delTour(String tourname){
|
||||
ProgressBar progressBar = new ProgressBar("Del...");
|
||||
int step = progressBar.getProgressSize(3, 100);
|
||||
FileHelper.delFile(new File(getImagePath(tourname)));
|
||||
progressBar.addProgress(step);
|
||||
FileHelper.delFile(new File(getImagePdfPath(tourname)));
|
||||
return new DbConnect().delTour(tourname);
|
||||
progressBar.addProgress(step);
|
||||
boolean ret = new DbConnect().delTour(tourname);
|
||||
progressBar.setProgress(100);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Fügt eine Tour hinzu
|
||||
* @param newTour Neue Tour
|
||||
* @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());
|
||||
progressBar.addProgress(step);
|
||||
newTour.setDauer(directionMap.getDauer()+"");
|
||||
newTour.setStrecke(directionMap.getStrecke());
|
||||
return new DbConnect().addTour(newTour);
|
||||
boolean ret = new DbConnect().addTour(newTour);
|
||||
progressBar.setProgress(100);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,13 +1,13 @@
|
||||
package tourplaner.data;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import tourplaner.business.LogHelper;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.AlertHelper;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -155,21 +155,38 @@ public class DbConnect {
|
||||
}
|
||||
|
||||
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+"'");
|
||||
}
|
||||
|
||||
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
|
||||
* @return Null bei fehler, sonst eine List aus den IDs
|
||||
*/
|
||||
public ArrayList<Tour> getAllTouren(){
|
||||
public ArrayList<Tour> getAllTouren() {
|
||||
this.c = PostgresHelper.con();
|
||||
String tourname, mapjson, start, ziel;
|
||||
double dauer, strecke;
|
||||
|
||||
ArrayList<Tour> touren = new ArrayList<>();
|
||||
ProgressBar progressBar = new ProgressBar("Get...");
|
||||
try {
|
||||
int tourSize = getTourSize();
|
||||
int step = progressBar.getProgressSize(tourSize, 100);
|
||||
stmt = this.c.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("select * from tour;");
|
||||
while (rs.next()) {
|
||||
@ -181,16 +198,20 @@ public class DbConnect {
|
||||
strecke = rs.getDouble("strecke");
|
||||
if (!tourname.isEmpty()) {
|
||||
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel, getLogs(tourname)));
|
||||
progressBar.addProgress(step);
|
||||
}else {
|
||||
progressBar.setProgress(100);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
progressBar.setProgress(100);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
this.c.close();
|
||||
return touren;
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
||||
LogHelper.error(e);
|
||||
progressBar.setProgress(100);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -45,9 +45,9 @@
|
||||
<menus>
|
||||
<Menu fx:id="menueFile" mnemonicParsing="false" text="Datei">
|
||||
<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 mnemonicParsing="false" onAction="#reportSum" text="Report alles" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Bearbeiten">
|
||||
@ -58,7 +58,6 @@
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Optionen">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
|
||||
<CheckMenuItem mnemonicParsing="false" text="Map automatisch öffnen" />
|
||||
<CheckMenuItem mnemonicParsing="false" text="Report automatisch öffnen" />
|
||||
<Menu mnemonicParsing="false" text="Sprache">
|
||||
|
@ -25,13 +25,21 @@ public class ProgressBar {
|
||||
|
||||
public void addProgress(int add){
|
||||
this.status += add;
|
||||
System.out.println("PROGRESS: " + this.status);
|
||||
this.progressBar.setValue(this.status);
|
||||
if(this.status == 100){
|
||||
frame.setVisible(false);
|
||||
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);
|
||||
}
|
||||
@ -39,7 +47,6 @@ public class ProgressBar {
|
||||
public int getProgressSize(int todo, int maxLevel){
|
||||
int steps = (progressBar.getValue() - maxLevel) / todo;
|
||||
if(steps < 0) steps = steps*-1;
|
||||
System.out.println("STEPS: " + steps);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
@ -169,8 +169,7 @@ public class TourplanerController implements Initializable {
|
||||
*/
|
||||
@FXML
|
||||
private void addTour(){
|
||||
this.viewModel.addTour();
|
||||
this.mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
|
||||
if(this.viewModel.addTour()) this.mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,10 +7,9 @@ import tourplaner.business.*;
|
||||
import tourplaner.ui.AlertHelper;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@ -80,9 +79,10 @@ public class ViewModel {
|
||||
|
||||
/**
|
||||
* Input mit duplications check des Namens und ohne content im input feld
|
||||
* @return false beim schließen
|
||||
*/
|
||||
private void tourNameInput(){
|
||||
tourNameInputDuplicatCheck("", true);
|
||||
private boolean tourNameInput(){
|
||||
return tourNameInputDuplicatCheck("", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,24 +153,31 @@ public class ViewModel {
|
||||
/**
|
||||
* Fügt eine neue Tour hinzu
|
||||
*/
|
||||
public void addTour(){
|
||||
tourNameInput();
|
||||
tourStartInput("");
|
||||
tourZielInput("");
|
||||
if (getTour(this.neueTourName) == null) {
|
||||
Tour newTour = new Tour(this.neueTourName, "1", "1", 0, this.neueTourStart, this.neueTourZiel);
|
||||
tourData.add(newTour);
|
||||
tourNamen.add(this.neueTourName);
|
||||
this.selectedTour = newTour;
|
||||
try {
|
||||
TourPlaner.addTour(newTour);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public boolean addTour(){
|
||||
if(tourNameInput()) {
|
||||
if(tourStartInput("")) {
|
||||
if (tourZielInput("")) {
|
||||
if (getTour(this.neueTourName) == null) {
|
||||
ProgressBar progressBar = new ProgressBar("Add Tour...");
|
||||
Tour newTour = new Tour(this.neueTourName, "1", "1", 0, this.neueTourStart, this.neueTourZiel);
|
||||
tourData.add(newTour);
|
||||
tourNamen.add(this.neueTourName);
|
||||
this.selectedTour = newTour;
|
||||
progressBar.addProgress(10);
|
||||
try {
|
||||
TourPlaner.addTour(newTour, progressBar);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else return false;
|
||||
}else return false;
|
||||
}else return false;
|
||||
this.neueTourStart = null;
|
||||
this.neueTourZiel = null;
|
||||
this.neueTourName = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean keineTourSelected(){
|
||||
@ -209,11 +216,11 @@ public class ViewModel {
|
||||
if (dauer >= 0) {
|
||||
strecke = streckeInput(this.selectedLog.getStrecke() + "");
|
||||
if (strecke >= 0) {
|
||||
pause = pauseInput("");
|
||||
pause = pauseInput(this.selectedLog.getPause() + "");
|
||||
if(pause >= 0.0) {
|
||||
hightmeter = hightmeterInput("");
|
||||
hightmeter = hightmeterInput(this.selectedLog.getHightmeter() + "");
|
||||
if (hightmeter >= 0.0) {
|
||||
bemerkung = bemerkungInput("");
|
||||
bemerkung = bemerkungInput(this.selectedLog.getBemerkung());
|
||||
if (bemerkung) {
|
||||
datum = dateInput(this.selectedLog.getDatum());
|
||||
if (datum != null) {
|
||||
@ -482,7 +489,10 @@ public class ViewModel {
|
||||
|
||||
public ObservableList<Tour> getTourData() {
|
||||
tourData.clear();
|
||||
tourData.addAll(TourPlaner.getAllTours());
|
||||
ArrayList<Tour> touren = TourPlaner.getAllTours();
|
||||
if(touren != null) {
|
||||
tourData.addAll(touren);
|
||||
}
|
||||
return tourData;
|
||||
}
|
||||
|
||||
@ -619,13 +629,8 @@ public class ViewModel {
|
||||
public void importData() {
|
||||
String file = AlertHelper.fileChooser("Importiere");
|
||||
if (file != null){
|
||||
try {
|
||||
this.tourNamen = FXCollections.observableArrayList();
|
||||
new Exporter(file).doImport();
|
||||
} catch (IOException e) {
|
||||
AlertHelper.error("Error", "Import Error", "Fehler beim Importieren");
|
||||
LogHelper.error(e);
|
||||
}
|
||||
this.tourNamen = FXCollections.observableArrayList();
|
||||
new Exporter(file).doImport();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user