X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FBabelLoadFromFile.java;h=23ce909fc9dd8e9fd6089465659d980c315a7474;hb=88f2c3647ed9e055090484f01a959d4581f85e7d;hp=f7866efaf0cacc1512dbca0facc3b2aa509df944;hpb=649c5da6ee1bbc590699e11a92316ece2ea8512d;p=GpsPrune.git diff --git a/tim/prune/load/BabelLoadFromFile.java b/tim/prune/load/BabelLoadFromFile.java index f7866ef..23ce909 100644 --- a/tim/prune/load/BabelLoadFromFile.java +++ b/tim/prune/load/BabelLoadFromFile.java @@ -25,6 +25,7 @@ import tim.prune.config.Config; import tim.prune.data.SourceInfo; import tim.prune.data.SourceInfo.FILE_TYPE; import tim.prune.gui.GuiGridLayout; +import tim.prune.load.babel.BabelFilterPanel; /** @@ -40,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; @@ -132,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)); @@ -158,6 +159,15 @@ public class BabelLoadFromFile extends BabelLoader _saveCheckbox.setAlignmentX(Component.CENTER_ALIGNMENT); mainPanel.add(_saveCheckbox); + // Filter panel + _filterPanel = new BabelFilterPanel(_parentFrame); + // Give filter panel the contents of the config + String filter = Config.getConfigString(Config.KEY_GPSBABEL_FILTER); + if (filter != null) { + _filterPanel.setFilterString(filter); + } + mainPanel.add(_filterPanel); + // progress bar (initially invisible) _progressBar = new JProgressBar(0, 10); mainPanel.add(_progressBar); @@ -190,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 */ @@ -197,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); } @@ -216,6 +240,15 @@ public class BabelLoadFromFile extends BabelLoader */ protected void saveConfigValues() { - // nothing needed + // Save the filter string, clear it if it's now blank + final String filter = _filterPanel.getFilterString(); + 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()); + } } }