X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fsave%2FKmlExporter.java;h=16624ad1495dd26c549a0af26a3c087fbb0364c7;hp=6c95b4c5163c6908a536431429792716698f66ab;hb=d3679d647d57c2ee7376ddbf6def2d5b23c04307;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c diff --git a/tim/prune/save/KmlExporter.java b/tim/prune/save/KmlExporter.java index 6c95b4c..16624ad 100644 --- a/tim/prune/save/KmlExporter.java +++ b/tim/prune/save/KmlExporter.java @@ -14,7 +14,6 @@ import tim.prune.App; import tim.prune.I18nManager; import tim.prune.data.Coordinate; import tim.prune.data.DataPoint; -import tim.prune.data.Field; import tim.prune.data.Track; /** @@ -53,6 +52,7 @@ public class KmlExporter I18nManager.getText("dialog.exportkml.text"), I18nManager.getText("dialog.exportkml.title"), JOptionPane.QUESTION_MESSAGE, null, null, ""); + // TODO: Make dialog window including colour selection, line width, track description if (description != null) { // OK pressed, so choose output file @@ -66,7 +66,7 @@ public class KmlExporter } public String getDescription() { - return "KML files"; + return I18nManager.getText("dialog.exportkml.filetype"); } }); _fileChooser.setAcceptAllFileFilterUsed(false); @@ -83,14 +83,13 @@ public class KmlExporter { file = new File(file.getAbsolutePath() + ".kml"); } - // Check if file exists - if so don't overwrite - if (file.exists()) - { - JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.fileexists"), - I18nManager.getText("error.save.dialogtitle"), JOptionPane.ERROR_MESSAGE); - chooseAgain = true; - } - else + // Check if file exists and if necessary prompt for overwrite + Object[] buttonTexts = {I18nManager.getText("button.overwrite"), I18nManager.getText("button.cancel")}; + if (!file.exists() || JOptionPane.showOptionDialog(_parentFrame, + I18nManager.getText("dialog.save.overwrite.text"), + I18nManager.getText("dialog.save.overwrite.title"), JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]) + == JOptionPane.YES_OPTION) { if (exportFile(file, description.toString())) { @@ -101,6 +100,10 @@ public class KmlExporter chooseAgain = true; } } + else + { + chooseAgain = true; + } } } while (chooseAgain); } @@ -115,9 +118,10 @@ public class KmlExporter */ private boolean exportFile(File inFile, String inDescription) { + FileWriter writer = null; try { - FileWriter writer = new FileWriter(inFile); + writer = new FileWriter(inFile); writer.write("\n\n\n"); writer.write("\t"); writer.write(inDescription); @@ -127,6 +131,7 @@ public class KmlExporter DataPoint point = null; boolean hasTrackpoints = false; // Loop over waypoints + boolean writtenPhotoHeader = false; int numPoints = _track.getNumPoints(); for (i=0; ihttp://maps.google.com/mapfiles/kml/pal4/icon46.png"); + writtenPhotoHeader = true; + } + exportPhotoPoint(point, writer); + } else { hasTrackpoints = true; @@ -160,12 +174,16 @@ public class KmlExporter writer.close(); JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.save.ok1") + " " + numPoints + " " + I18nManager.getText("dialog.save.ok2") - + inFile.getAbsolutePath(), + + " " + inFile.getAbsolutePath(), I18nManager.getText("dialog.save.oktitle"), JOptionPane.INFORMATION_MESSAGE); return true; } catch (IOException ioe) { + try { + if (writer != null) writer.close(); + } + catch (IOException ioe2) {} JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + ioe.getMessage(), I18nManager.getText("error.save.dialogtitle"), JOptionPane.ERROR_MESSAGE); } @@ -177,12 +195,34 @@ public class KmlExporter * Export the specified waypoint into the file * @param inPoint waypoint to export * @param inWriter writer object + * @throws IOException on write failure */ private void exportWaypoint(DataPoint inPoint, Writer inWriter) throws IOException { inWriter.write("\t\n\t\t"); - inWriter.write(inPoint.getFieldValue(Field.WAYPT_NAME).trim()); + inWriter.write(inPoint.getWaypointName().trim()); + inWriter.write("\n"); + inWriter.write("\t\t\n\t\t\t"); + inWriter.write(inPoint.getLongitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL)); + inWriter.write(','); + inWriter.write(inPoint.getLatitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL)); + inWriter.write(",0\n\t\t\n\t\n"); + } + + + /** + * Export the specified photo into the file + * @param inPoint data point including photo + * @param inWriter writer object + * @throws IOException on write failure + */ + private void exportPhotoPoint(DataPoint inPoint, Writer inWriter) throws IOException + { + // TODO: Export photos to KML too - for photos need kmz! + inWriter.write("\t\n\t\t"); + inWriter.write(inPoint.getPhoto().getFile().getName()); inWriter.write("\n"); + inWriter.write("#camera_icon\n"); inWriter.write("\t\t\n\t\t\t"); inWriter.write(inPoint.getLongitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL)); inWriter.write(',');