Search in sources :

Example 6 with PropertiesPreferences

use of com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences in project netbeans-mmd-plugin by raydac.

the class MMDCfgPanel method buttonExportSettingsActionPerformed.

// GEN-LAST:event_buttonResetSettingsActionPerformed
private void buttonExportSettingsActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_buttonExportSettingsActionPerformed
    File file = DialogProviderManager.getInstance().getDialogProvider().msgSaveFileDialog(null, "exportSettings", "Export settings", lastExportedSettingsFile, true, new PropertiesFileFilter(), "Save");
    if (file != null) {
        lastExportedSettingsFile = file;
        if (!file.getName().toLowerCase(Locale.ENGLISH).endsWith(".properties")) {
            final Boolean addExt = DialogProviderManager.getInstance().getDialogProvider().msgConfirmYesNoCancel(null, "Add extension", "Add '.properties' extension?");
            if (addExt == null) {
                return;
            }
            if (addExt) {
                file = new File(file.getAbsolutePath() + ".properties");
            }
        }
        if (file.exists() && !DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Override file", String.format("File %s exists, to override it?", file.getName()))) {
            return;
        }
        final PropertiesPreferences prefs = new PropertiesPreferences("NB MindMap plugin");
        final MindMapPanelConfig cfg = store(prefs, new MindMapPanelConfig(), false);
        cfg.saveTo(prefs);
        try {
            FileUtils.write(file, prefs.toString(), "UTF-8");
        } catch (final Exception ex) {
            LOGGER.error("Can't export settings", ex);
            DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't export settings [" + ex.getMessage() + ']');
        }
    }
}
Also used : PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) File(java.io.File) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)

Example 7 with PropertiesPreferences

use of com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences in project netbeans-mmd-plugin by raydac.

the class Main method exportSettings.

private static boolean exportSettings(@Nonnull final File settingsFile) {
    boolean result = true;
    final MindMapPanelConfig config = new MindMapPanelConfig();
    config.loadFrom(PreferencesManager.getInstance().getPreferences());
    // NOI18N
    final PropertiesPreferences prefs = new PropertiesPreferences("Exported configuration for SciaReto editor https://github.com/raydac/netbeans-mmd-plugin");
    config.saveTo(prefs);
    try {
        FileUtils.write(settingsFile, prefs.toString(), "UTF-8");
    } catch (final Exception ex) {
        // NOI18N
        LOGGER.error("Can't export settings for error", ex);
        result = false;
    }
    return result;
}
Also used : PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

PropertiesPreferences (com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences)7 MindMapPanelConfig (com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)6 File (java.io.File)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 AbstractExporter (com.igormaznitsa.mindmap.plugins.api.AbstractExporter)1 AbstractImporter (com.igormaznitsa.mindmap.plugins.api.AbstractImporter)1 Point (java.awt.Point)1 Properties (java.util.Properties)1 Preferences (java.util.prefs.Preferences)1