X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fsave%2FFileSaver.java;h=f5f92bcc91af9ba6aec94e26877400b0bc4598c2;hp=b1ea368c03678f1b535a49ad146acabee97e9be3;hb=d3679d647d57c2ee7376ddbf6def2d5b23c04307;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c diff --git a/tim/prune/save/FileSaver.java b/tim/prune/save/FileSaver.java index b1ea368..f5f92bc 100644 --- a/tim/prune/save/FileSaver.java +++ b/tim/prune/save/FileSaver.java @@ -17,6 +17,7 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -56,6 +57,7 @@ public class FileSaver private JButton _moveUpButton = null, _moveDownButton = null; private JRadioButton[] _delimiterRadios = null; private JTextField _otherDelimiterText = null; + private JCheckBox _headerRowCheckbox = null; private JRadioButton[] _coordUnitsRadios = null; private JRadioButton[] _altitudeUnitsRadios = null; private static final int[] FORMAT_COORDS = {Coordinate.FORMAT_NONE, Coordinate.FORMAT_DEG_MIN_SEC, @@ -214,6 +216,12 @@ public class FileSaver } delimsPanel.add(otherPanel); firstCard.add(delimsPanel); + + // header checkbox + firstCard.add(Box.createRigidArea(new Dimension(0,10))); + _headerRowCheckbox = new JCheckBox(I18nManager.getText("dialog.save.headerrow")); + firstCard.add(_headerRowCheckbox); + _cards.add(firstCard, "card1"); JPanel secondCard = new JPanel(); @@ -260,6 +268,7 @@ public class FileSaver } altUnitsPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); secondCardHolder.add(altUnitsPanel); + // TODO: selection of format of timestamps secondCard.add(secondCardHolder, BorderLayout.NORTH); _cards.add(secondCard, "card2"); @@ -270,10 +279,10 @@ public class FileSaver _backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - CardLayout cl = (CardLayout)(_cards.getLayout()); - cl.previous(_cards); - _backButton.setEnabled(false); - _nextButton.setEnabled(true); + CardLayout cl = (CardLayout)(_cards.getLayout()); + cl.previous(_cards); + _backButton.setEnabled(false); + _nextButton.setEnabled(true); } }); _backButton.setEnabled(false); @@ -283,10 +292,10 @@ public class FileSaver _nextButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - CardLayout cl = (CardLayout)(_cards.getLayout()); - cl.next(_cards); - _backButton.setEnabled(true); - _nextButton.setEnabled(false); + CardLayout cl = (CardLayout)(_cards.getLayout()); + cl.next(_cards); + _backButton.setEnabled(true); + _nextButton.setEnabled(false); } }); buttonPanel.add(_nextButton); @@ -336,11 +345,20 @@ public class FileSaver coordFormat = FORMAT_COORDS[i]; int altitudeFormat = Altitude.FORMAT_NONE; for (int i=0; i<_altitudeUnitsRadios.length; i++) + { if (_altitudeUnitsRadios[i].isSelected()) + { altitudeFormat = FORMAT_ALTS[i]; - - // Check if file exists, don't overwrite any files for v1! - if (!saveFile.exists()) + } + } + + // Check if file exists, and confirm overwrite if necessary + Object[] buttonTexts = {I18nManager.getText("button.overwrite"), I18nManager.getText("button.cancel")}; + if (!saveFile.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) { try { @@ -350,14 +368,39 @@ public class FileSaver char delimiter = getDelimiter(); FieldInfo info = null; Field field = null; + StringBuffer buffer = null; - // For now, just spit out to console - int numPoints = _track.getNumPoints(); int numFields = _model.getRowCount(); + boolean firstField = true; + // Write header row if required + if (_headerRowCheckbox.isSelected()) + { + buffer = new StringBuffer(); + for (int f=0; f