import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
import javax.swing.BorderFactory;
import javax.swing.Box;
mainPanel.add(checkPanel);
dialogPanel.add(mainPanel, BorderLayout.CENTER);
+ // close dialog if escape pressed
+ _nameField.addKeyListener(new KeyAdapter() {
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ _dialog.dispose();
+ }
+ }
+ });
// button panel at bottom
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPanel.add(okButton);
JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
+ public void actionPerformed(ActionEvent e) {
_dialog.dispose();
}
});
// Instantiate source file cachers in case we want to copy output
GpxCacherList gpxCachers = null;
if (inUseCopy) gpxCachers = new GpxCacherList(inInfo.getFileInfo());
- // Write or copy header
- inWriter.write(getHeaderString(gpxCachers));
+ // Write or copy headers
+ inWriter.write(getXmlHeaderString(inWriter));
+ inWriter.write(getGpxHeaderString(gpxCachers));
// Name field
String trackName = "PruneTrack";
if (inName != null && !inName.equals(""))
}
// Description field
inWriter.write("\t<desc>");
- if (inDesc != null && !inDesc.equals("")) {
- inWriter.write(inDesc);
- }
- else {
- inWriter.write("Export from Prune");
- }
+ inWriter.write((inDesc != null && !inDesc.equals(""))?inDesc:"Export from Prune");
inWriter.write("</desc>\n");
int i = 0;
}
/**
- * Get the header string for the gpx
+ * Get the header string for the xml document including encoding
+ * @param inWriter writer object
+ * @return header string defining encoding
+ */
+ private static String getXmlHeaderString(OutputStreamWriter inWriter)
+ {
+ String encoding = inWriter.getEncoding();
+ try {
+ encoding = Charset.forName(encoding).name();
+ }
+ catch (Exception e) {} // ignore failure to find encoding
+ return "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n";
+ }
+
+ /**
+ * Get the header string for the gpx tag
* @param inCachers cacher list to ask for headers, if available
* @return header string from cachers or as default
*/
- private static String getHeaderString(GpxCacherList inCachers)
+ private static String getGpxHeaderString(GpxCacherList inCachers)
{
String gpxHeader = null;
if (inCachers != null) {gpxHeader = inCachers.getFirstHeader();}
+ " xmlns=\"http://www.topografix.com/GPX/1/0\""
+ " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n";
}
- return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + gpxHeader + "\n";
+ return gpxHeader + "\n";
}
/**