X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FSaveConfig.java;h=7d730d1b5763d5f819a1dfdf5a1cda70ea0e4b3b;hb=a6197ddcaac11c0b943183da7d46169742d024af;hp=125b4b7496b0558c487cf87c2f63a83fbd2fae70;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;p=GpsPrune.git diff --git a/tim/prune/function/SaveConfig.java b/tim/prune/function/SaveConfig.java index 125b4b7..7d730d1 100644 --- a/tim/prune/function/SaveConfig.java +++ b/tim/prune/function/SaveConfig.java @@ -86,13 +86,16 @@ public class SaveConfig extends GenericFunction { mainPanel.add(new JLabel(keyLabel)); String val = conf.getProperty(key); + String tipText = val; if (Config.isKeyBoolean(key)) { val = Config.getConfigBoolean(key)?I18nManager.getText("dialog.about.yes"):I18nManager.getText("dialog.about.no"); } else if (val != null && val.length() > 30) { val = val.substring(0, 30) + " ..."; } - mainPanel.add(new JLabel(val)); + JLabel label = new JLabel(val); + label.setToolTipText(tipText); + mainPanel.add(label); } } dialogPanel.add(mainPanel, BorderLayout.CENTER); @@ -128,23 +131,47 @@ public class SaveConfig extends GenericFunction private void finish() { File configFile = Config.getConfigFile(); - if (configFile == null) {configFile = new File(".pruneconfig");} + if (configFile == null) {configFile = Config.HOME_CONFIG_FILE;} JFileChooser chooser = new JFileChooser(configFile.getAbsoluteFile().getParent()); chooser.setSelectedFile(configFile); int response = chooser.showSaveDialog(_parentFrame); if (response == JFileChooser.APPROVE_OPTION) { File saveFile = chooser.getSelectedFile(); - try - { - Config.getAllConfig().store(new FileOutputStream(saveFile), "Prune config file"); - } - catch (IOException ioe) { - _app.showErrorMessageNoLookup(getNameKey(), - I18nManager.getText("error.save.failed") + " : " + ioe.getMessage()); - } + saveConfig(saveFile); } _dialog.dispose(); _dialog = null; } + + /** + * Autosave the settings file without any prompts + */ + public void silentSave() + { + saveConfig(Config.getConfigFile()); + } + + /** + * Actually save the config file + * @param inSaveFile file to save to + */ + private void saveConfig(File inSaveFile) + { + // TODO: Check for null inSaveFile, then just call finish() ? + FileOutputStream outStream = null; + try + { + outStream = new FileOutputStream(inSaveFile); + Config.getAllConfig().store(outStream, "GpsPrune config file"); + } + catch (IOException ioe) { + _app.showErrorMessageNoLookup(getNameKey(), + I18nManager.getText("error.save.failed") + " : " + ioe.getMessage()); + } + catch (NullPointerException npe) {} // no config file given + finally { + try {outStream.close();} catch (Exception e) {} + } + } }