import javax.swing.JProgressBar;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
-import javax.swing.filechooser.FileFilter;
+import tim.prune.Config;
import tim.prune.I18nManager;
+import tim.prune.UpdateMessageBroker;
import tim.prune.data.Altitude;
import tim.prune.data.Coordinate;
import tim.prune.data.DataPoint;
import tim.prune.data.Track;
import tim.prune.data.TrackInfo;
import tim.prune.gui.ImageUtils;
+import tim.prune.load.GenericFileFilter;
/**
* Class to export track information
{
// OK pressed, so choose output file
if (_fileChooser == null)
- {_fileChooser = new JFileChooser();}
- _fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
- _fileChooser.setFileFilter(new FileFilter() {
- public boolean accept(File f)
- {
- return (f != null && (f.isDirectory()
- || f.getName().toLowerCase().endsWith(".kml") || f.getName().toLowerCase().endsWith(".kmz")));
- }
- public String getDescription()
- {
- return I18nManager.getText("dialog.exportkml.filetype");
- }
- });
+ {
+ _fileChooser = new JFileChooser();
+ _fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ _fileChooser.setFileFilter(new GenericFileFilter("filetype.kmlkmz", new String[] {"kml", "kmz"}));
+ // start from directory in config which should be set
+ File configDir = Config.getWorkingDirectory();
+ if (configDir != null) {_fileChooser.setCurrentDirectory(configDir);}
+ }
String requiredExtension = null, otherExtension = null;
if (_kmzCheckbox.isSelected())
{
// close file
writer.close();
- JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.save.ok1")
- + " " + numPoints + " " + I18nManager.getText("dialog.save.ok2")
- + " " + _exportFile.getAbsolutePath(),
- I18nManager.getText("dialog.save.oktitle"), JOptionPane.INFORMATION_MESSAGE);
+ // Store directory in config for later
+ Config.setWorkingDirectory(_exportFile.getParentFile());
+ // show confirmation
+ UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.save.ok1")
+ + " " + numPoints + " " + I18nManager.getText("confirm.save.ok2")
+ + " " + _exportFile.getAbsolutePath());
// export successful so need to close dialog and return
_dialog.dispose();
return;
private int exportData(OutputStreamWriter inWriter, boolean inExportImages)
throws IOException
{
- // TODO: Look at segments of track, and split into separate lines in Kml if necessary
inWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://earth.google.com/kml/2.1\">\n<Folder>\n");
inWriter.write("\t<name>");
if (_descriptionField != null && _descriptionField.getText() != null && !_descriptionField.getText().equals(""))
// Make a line for the track, if there is one
if (hasTrackpoints)
{
- inWriter.write("\t<Placemark>\n\t\t<name>track</name>\n\t\t<Style>\n\t\t\t<LineStyle>\n"
+ // Set up strings for start and end of track segment
+ String trackStart = "\t<Placemark>\n\t\t<name>track</name>\n\t\t<Style>\n\t\t\t<LineStyle>\n"
+ "\t\t\t\t<color>cc0000cc</color>\n\t\t\t\t<width>4</width>\n\t\t\t</LineStyle>\n"
+ "\t\t\t<PolyStyle><color>33cc0000</color></PolyStyle>\n"
- + "\t\t</Style>\n\t\t<LineString>\n");
+ + "\t\t</Style>\n\t\t<LineString>\n";
if (exportAltitudes) {
- inWriter.write("\t\t\t<extrude>1</extrude>\n\t\t\t<altitudeMode>absolute</altitudeMode>\n");
+ trackStart += "\t\t\t<extrude>1</extrude>\n\t\t\t<altitudeMode>absolute</altitudeMode>\n";
}
- inWriter.write("\t\t\t<coordinates>");
+ trackStart += "\t\t\t<coordinates>";
+ String trackEnd = "\t\t\t</coordinates>\n\t\t</LineString>\n\t</Placemark>";
+
+ // Start segment
+ inWriter.write(trackStart);
// Loop over track points
+ boolean firstTrackpoint = true;
for (i=0; i<numPoints; i++)
{
point = _track.getPoint(i);
+ // start new track segment if necessary
+ if (point.getSegmentStart() && !firstTrackpoint) {
+ inWriter.write(trackEnd);
+ inWriter.write(trackStart);
+ }
if (!point.isWaypoint() && point.getPhoto() == null)
{
exportTrackpoint(point, inWriter, exportAltitudes);
+ firstTrackpoint = false;
}
}
- inWriter.write("\t\t\t</coordinates>\n\t\t</LineString>\n\t</Placemark>");
+ // end segment
+ inWriter.write(trackEnd);
}
inWriter.write("</Folder>\n</kml>");
return numPoints;
inWriter.write(inPoint.getLatitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL));
inWriter.write(",");
if (inExportAltitude && inPoint.hasAltitude()) {
- inWriter.write("" + inPoint.getAltitude().getValue(Altitude.FORMAT_METRES));
+ inWriter.write("" + inPoint.getAltitude().getStringValue(Altitude.FORMAT_METRES));
}
else {
inWriter.write("0");
inWriter.write(inPoint.getLatitude().output(Coordinate.FORMAT_DEG_WITHOUT_CARDINAL));
inWriter.write(",");
if (inExportAltitude && inPoint.hasAltitude()) {
- inWriter.write("" + inPoint.getAltitude().getValue(Altitude.FORMAT_METRES));
+ inWriter.write("" + inPoint.getAltitude().getStringValue(Altitude.FORMAT_METRES));
}
else {
inWriter.write("0");
// Altitude either absolute or locked to ground by Google Earth
inWriter.write(",");
if (inExportAltitude && inPoint.hasAltitude()) {
- inWriter.write("" + inPoint.getAltitude().getValue(Altitude.FORMAT_METRES));
+ inWriter.write("" + inPoint.getAltitude().getStringValue(Altitude.FORMAT_METRES));
}
else {
inWriter.write("0");