import tim.prune.I18nManager;
import tim.prune.data.Coordinate;
import tim.prune.data.DataPoint;
-import tim.prune.data.Field;
import tim.prune.data.Track;
/**
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
}
public String getDescription()
{
- return "KML files";
+ return I18nManager.getText("dialog.exportkml.filetype");
}
});
_fileChooser.setAcceptAllFileFilterUsed(false);
{
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()))
{
chooseAgain = true;
}
}
+ else
+ {
+ chooseAgain = true;
+ }
}
} while (chooseAgain);
}
*/
private boolean exportFile(File inFile, String inDescription)
{
+ FileWriter writer = null;
try
{
- FileWriter writer = new FileWriter(inFile);
+ writer = new FileWriter(inFile);
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://earth.google.com/kml/2.1\">\n<Folder>\n");
writer.write("\t<name>");
writer.write(inDescription);
DataPoint point = null;
boolean hasTrackpoints = false;
// Loop over waypoints
+ boolean writtenPhotoHeader = false;
int numPoints = _track.getNumPoints();
for (i=0; i<numPoints; i++)
{
{
exportWaypoint(point, writer);
}
+ else if (point.getPhoto() != null)
+ {
+ if (!writtenPhotoHeader)
+ {
+ writer.write("<Style id=\"camera_icon\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pal4/icon46.png</href></Icon></IconStyle></Style>");
+ writtenPhotoHeader = true;
+ }
+ exportPhotoPoint(point, writer);
+ }
else
{
hasTrackpoints = true;
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);
}
* 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<Placemark>\n\t\t<name>");
- inWriter.write(inPoint.getFieldValue(Field.WAYPT_NAME).trim());
+ inWriter.write(inPoint.getWaypointName().trim());
+ inWriter.write("</name>\n");
+ inWriter.write("\t\t<Point>\n\t\t\t<coordinates>");
+ 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</coordinates>\n\t\t</Point>\n\t</Placemark>\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<Placemark>\n\t\t<name>");
+ inWriter.write(inPoint.getPhoto().getFile().getName());
inWriter.write("</name>\n");
+ inWriter.write("<styleUrl>#camera_icon</styleUrl>\n");
inWriter.write("\t\t<Point>\n\t\t\t<coordinates>");
inWriter.write(inPoint.getLongitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL));
inWriter.write(',');