Static map -> Tour edit, del
This commit is contained in:
parent
39c4244668
commit
3f60d618ff
@ -13,6 +13,14 @@ public class DirectionMap {
|
||||
private String start, end, tourname, file;
|
||||
private Image map;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
this.map = getMap(start, ende);
|
||||
this.start = start;
|
||||
@ -23,8 +31,15 @@ public class DirectionMap {
|
||||
FileHelper.openDefault(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) throws IOException {
|
||||
return HttpHelper.httpGetStaticMap(start, ende);
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,6 +9,10 @@ import java.io.IOException;
|
||||
|
||||
public class FileHelper {
|
||||
|
||||
/**
|
||||
* Öffnet ein File mit dem Standart Program
|
||||
* @param f File Path als string
|
||||
*/
|
||||
public static void openDefault(String f){
|
||||
// A reference to a text file
|
||||
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 {
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,19 @@ import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Http Hilfsfunktionen
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* Holt ein Image von gegebener 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);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package tourplaner.business;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Image Hilfsfunktionen
|
||||
*/
|
||||
public class ImgHelper {
|
||||
|
||||
/**
|
||||
|
@ -37,11 +37,14 @@ public class TourPlaner{
|
||||
* @param tour Neuer Tourname
|
||||
* @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)));
|
||||
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
|
||||
return new DbConnect().editTour(oldname, tour);
|
||||
}
|
||||
|
||||
public static boolean delTour(String tourname){
|
||||
FileHelper.delFile(new File(getImagePath(tourname)));
|
||||
return new DbConnect().delTour(tourname);
|
||||
}
|
||||
/**
|
||||
|
@ -51,7 +51,11 @@ public class TourplanerController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private void editTourBtn(){
|
||||
this.viewModel.editTour();
|
||||
try {
|
||||
this.viewModel.editTour();
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
syncTour(this.viewModel.getSelectedTour().getName());
|
||||
}
|
||||
|
||||
@ -90,6 +94,7 @@ public class TourplanerController implements Initializable {
|
||||
private void syncTour(String selectedItem){
|
||||
beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
|
||||
beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
|
||||
mapImageView.setImage(this.viewModel.getImage(selectedItem));
|
||||
}
|
||||
|
||||
private void syncTourNamen(){
|
||||
@ -163,6 +168,7 @@ public class TourplanerController implements Initializable {
|
||||
this.titleTextView.setText(ConfigHelper.getLangIniString("keinetourselected"));
|
||||
this.viewModel.delTour();
|
||||
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
|
||||
mapImageView.setImage(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ public class ViewModel {
|
||||
* Bearbeitet eine bereits bestehende Tour
|
||||
* prüft ob eine tour ausgewählt ist
|
||||
*/
|
||||
public void editTour(){
|
||||
public void editTour() throws IOException {
|
||||
if (this.selectedTour == null){
|
||||
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
|
||||
ConfigHelper.getLangIniString("keinetourselected"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user