X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fsave%2FGpxExporter.java;h=8203593b0d6d72387293df350e1366a8ddf097ae;hb=3745d70b1427bb8ac1a085e47cbdc566936784e1;hp=7f75aeb17689397eccef5d1f45ba01a363f4f3c2;hpb=140e9d165f85c3d4f0435a311e091209313faa2a;p=GpsPrune.git diff --git a/tim/prune/save/GpxExporter.java b/tim/prune/save/GpxExporter.java index 7f75aeb..8203593 100644 --- a/tim/prune/save/GpxExporter.java +++ b/tim/prune/save/GpxExporter.java @@ -6,11 +6,14 @@ import java.awt.FlowLayout; 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; @@ -129,6 +132,14 @@ public class GpxExporter extends GenericFunction implements Runnable 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)); @@ -144,8 +155,7 @@ public class GpxExporter extends GenericFunction implements Runnable 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(); } }); @@ -290,8 +300,9 @@ public class GpxExporter extends GenericFunction implements Runnable // 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("")) @@ -303,12 +314,7 @@ public class GpxExporter extends GenericFunction implements Runnable } // Description field inWriter.write("\t"); - 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("\n"); int i = 0; @@ -489,11 +495,26 @@ public class GpxExporter extends GenericFunction implements Runnable } /** - * 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 "\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();} @@ -505,7 +526,7 @@ public class GpxExporter extends GenericFunction implements Runnable + " 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 "\n" + gpxHeader + "\n"; + return gpxHeader + "\n"; } /**