X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FBabelLoadFromFile.java;h=23ce909fc9dd8e9fd6089465659d980c315a7474;hb=88f2c3647ed9e055090484f01a959d4581f85e7d;hp=1897e0cdcf9d717e442ffe2522c43223a2d466fb;hpb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;p=GpsPrune.git diff --git a/tim/prune/load/BabelLoadFromFile.java b/tim/prune/load/BabelLoadFromFile.java index 1897e0c..23ce909 100644 --- a/tim/prune/load/BabelLoadFromFile.java +++ b/tim/prune/load/BabelLoadFromFile.java @@ -41,7 +41,7 @@ public class BabelLoadFromFile extends BabelLoader // Label for filename private JLabel _inputFileLabel = null; // Dropdown for format of file - private JComboBox _formatDropdown = null; + private JComboBox _formatDropdown = null; // Last used file suffix private String _lastSuffix = null; @@ -133,7 +133,7 @@ public class BabelLoadFromFile extends BabelLoader grid.add(_inputFileLabel); JLabel formatLabel = new JLabel(I18nManager.getText("dialog.gpsload.format")); grid.add(formatLabel); - _formatDropdown = new JComboBox(BabelFileFormats.getDescriptions()); + _formatDropdown = new JComboBox(BabelFileFormats.getDescriptions()); grid.add(_formatDropdown); gridPanel.setAlignmentX(Component.CENTER_ALIGNMENT); gridPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 20)); @@ -200,6 +200,17 @@ public class BabelLoadFromFile extends BabelLoader return outerPanel; } + /** + * @return the suffix of the selected filename + */ + private String getSelectedSuffix() + { + String filename = _inputFile.getName(); + if (filename == null) {return "";} + int dotPos = filename.lastIndexOf('.'); + return (dotPos > 0 ? filename.substring(dotPos) : ""); + } + /** * Initialise dialog */ @@ -207,13 +218,16 @@ public class BabelLoadFromFile extends BabelLoader { _inputFileLabel.setText(_inputFile.getName()); // Get suffix of filename and compare with previous one - String filename = _inputFile.getName(); - int dotPos = filename.lastIndexOf('.'); - String suffix = (dotPos > 0 ? filename.substring(dotPos) : null); - if (suffix != null && !suffix.equals(".") && (_lastSuffix == null || !suffix.equalsIgnoreCase(_lastSuffix))) + String suffix = getSelectedSuffix(); + if (_lastSuffix == null || !suffix.equalsIgnoreCase(_lastSuffix)) { - // New suffix chosen, so select first appropriate format (if any) + // New suffix has been chosen, so select first appropriate format (if any) int selIndex = BabelFileFormats.getIndexForFileSuffix(suffix); + if (selIndex < 0) + { + // Use the previous one from the Config (if any) + selIndex = Config.getConfigInt(Config.KEY_IMPORT_FILE_FORMAT); + } if (selIndex >= 0) { _formatDropdown.setSelectedIndex(selIndex); } @@ -226,10 +240,15 @@ public class BabelLoadFromFile extends BabelLoader */ protected void saveConfigValues() { - // Save the filter string (but don't remove it if it's now blank) + // Save the filter string, clear it if it's now blank final String filter = _filterPanel.getFilterString(); - if (filter != null && !filter.equals("")) { - Config.setConfigString(Config.KEY_GPSBABEL_FILTER, filter); + Config.setConfigString(Config.KEY_GPSBABEL_FILTER, filter); + + // Check if there is a standard file type for the selected suffix + int selIndex = BabelFileFormats.getIndexForFileSuffix(getSelectedSuffix()); + // If there is none, then get the index which the user chose and set in the Config + if (selIndex < 0) { + Config.setConfigInt(Config.KEY_IMPORT_FILE_FORMAT, _formatDropdown.getSelectedIndex()); } } }