Search in sources :

Example 1 with PropertiesPreferences

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

the class MMDCfgPanel method buttonResetSettingsActionPerformed.

// GEN-LAST:event_checkBoxScalingMETAActionPerformed
private void buttonResetSettingsActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_buttonResetSettingsActionPerformed
    this.config.makeFullCopyOf(new MindMapPanelConfig(), false, false);
    loadFromPreferences(new PropertiesPreferences("NB MindMap plugin"), this.config);
    this.controller.changed();
}
Also used : PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig)

Example 2 with PropertiesPreferences

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

the class MMDCfgPanel method buttonImportSettingsActionPerformed.

// GEN-LAST:event_buttonExportSettingsActionPerformed
private void buttonImportSettingsActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_buttonImportSettingsActionPerformed
    final File file = DialogProviderManager.getInstance().getDialogProvider().msgOpenFileDialog(null, "importSettings", "Import settings", lastImportedSettingsFile, true, new PropertiesFileFilter(), "Open");
    if (file != null) {
        lastImportedSettingsFile = file;
        try {
            final Preferences prefs = (new PropertiesPreferences("NB MindMap plugin", FileUtils.readFileToString(file, "UTF-8")));
            loadFromPreferences(prefs, this.config);
            this.controller.changed();
        } catch (final Exception ex) {
            LOGGER.error("Can't import settings", ex);
            DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't import settings [" + ex.getMessage() + ']');
        }
    }
}
Also used : PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 3 with PropertiesPreferences

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

the class PreferencesPanel method buttonExportToFileActionPerformed.

// GEN-LAST:event_buttonFontForEditorActionPerformed
private void buttonExportToFileActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_buttonExportToFileActionPerformed
    File file = DialogProviderManager.getInstance().getDialogProvider().msgSaveFileDialog(this, "exportProperties", "Export settings", null, true, new PropertiesFileFilter(), "Save");
    if (file != null) {
        if (!file.getName().toLowerCase(Locale.ENGLISH).endsWith(".properties")) {
            // NOI18N
            final Boolean addExt = DialogProviderManager.getInstance().getDialogProvider().msgConfirmYesNoCancel(this, "Add extension", "Add '.properties' extension?");
            if (addExt == null)
                return;
            if (addExt) {
                // NOI18N
                file = new File(file.getAbsolutePath() + ".properties");
            }
        }
        if (file.exists() && !DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(this, "Override file", String.format("File %s exists, to override it?", file.getName()))) {
            return;
        }
        final PropertiesPreferences prefs = new PropertiesPreferences("SciaReto editor settings");
        final MindMapPanelConfig cfg = fillBySettings(new MindMapPanelConfig(), prefs);
        cfg.saveTo(prefs);
        try {
            FileUtils.write(file, prefs.toString(), "UTF-8");
        } catch (final Exception ex) {
            // NOI18N
            LOGGER.error("Can't export settings", ex);
            // NOI18N
            DialogProviderManager.getInstance().getDialogProvider().msgError(this, "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 4 with PropertiesPreferences

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

the class Main method convertData.

private static boolean convertData(@Nonnull @MustNotContainNull final String[] args) {
    MindMapPluginRegistry.getInstance().registerPlugin(new LocalMMDExporter());
    MindMapPluginRegistry.getInstance().registerPlugin(new LocalMMDImporter());
    final String[] params = new String[5];
    final Properties options = new Properties();
    final int IN_FILE = 0;
    final int OUT_FILE = 1;
    final int IN_TYPE = 2;
    final int OUT_TYPE = 3;
    final int SETTINGS = 4;
    final int OPTION = 5;
    // NOI18N
    params[IN_TYPE] = "mmd";
    // NOI18N
    params[OUT_TYPE] = "mmd";
    // NOI18N
    params[SETTINGS] = "";
    int detected = -1;
    boolean allOk = true;
    for (int i = 1; i < args.length; i++) {
        if (detected >= 0) {
            if (detected == OPTION) {
                final String text = args[i];
                // NOI18N
                final String[] splitted = text.split("\\=");
                if (splitted.length < 2) {
                    // NOI18N
                    options.put(splitted[0], "true");
                } else {
                    options.put(splitted[0], splitted[1]);
                }
            } else {
                params[detected] = args[i];
            }
            detected = -1;
        } else {
            if ("--in".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = IN_FILE;
            } else if ("--out".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = OUT_FILE;
            } else if ("--from".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = IN_TYPE;
            } else if ("--to".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = OUT_TYPE;
            } else if ("--settings".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = SETTINGS;
            } else if ("--option".equalsIgnoreCase(args[i])) {
                // NOI18N
                detected = OPTION;
            } else {
                // NOI18N
                LOGGER.error("Unexpected argument : " + args[i]);
                allOk = false;
                break;
            }
        }
    }
    if (allOk) {
        for (final String s : params) {
            if (s == null) {
                // NOI18N
                LOGGER.error("Not provided required parameter");
                allOk = true;
                break;
            }
        }
        if (allOk) {
            final File inFile = new File(params[IN_FILE]);
            final File outFile = new File(params[OUT_FILE]);
            final AbstractImporter importer = MindMapPluginRegistry.getInstance().findImporterForMnemonic(params[IN_TYPE]);
            final AbstractExporter exporter = MindMapPluginRegistry.getInstance().findExporterForMnemonic(params[OUT_TYPE]);
            if (importer == null) {
                // NOI18N
                LOGGER.error("Unknown importer : " + params[IN_TYPE]);
                allOk = false;
            } else if (exporter == null) {
                // NOI18N
                LOGGER.error("Unknown exporter : " + params[OUT_TYPE]);
                allOk = false;
            }
            if (allOk) {
                final File settingsFile = params[SETTINGS].isEmpty() ? null : new File(params[SETTINGS]);
                final MindMapPanelConfig config = new MindMapPanelConfig();
                if (settingsFile != null) {
                    try {
                        config.loadFrom(new PropertiesPreferences(FileUtils.readFileToString(settingsFile, "UTF-8")));
                    } catch (IOException ex) {
                        // NOI18N
                        LOGGER.error("Can't load settings file : " + settingsFile, ex);
                        allOk = false;
                    }
                }
                if (allOk && importer != null && exporter != null) {
                    try {
                        makeConversion(inFile, importer, outFile, exporter, config, options);
                    } catch (final Exception ex) {
                        if (ex instanceof IllegalArgumentException) {
                            LOGGER.error(ex.getMessage());
                        } else {
                            // NOI18N
                            LOGGER.error("Unexpected error during conversion", ex);
                        }
                        allOk = false;
                    }
                }
            }
        }
    }
    return allOk;
}
Also used : AbstractExporter(com.igormaznitsa.mindmap.plugins.api.AbstractExporter) IOException(java.io.IOException) Properties(java.util.Properties) Point(java.awt.Point) MindMapPanelConfig(com.igormaznitsa.mindmap.swing.panel.MindMapPanelConfig) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) AbstractImporter(com.igormaznitsa.mindmap.plugins.api.AbstractImporter) PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) File(java.io.File)

Example 5 with PropertiesPreferences

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

the class Main method importSettings.

private static boolean importSettings(@Nonnull final File settingsFile) {
    boolean result = true;
    try {
        final PropertiesPreferences prefs = new PropertiesPreferences(FileUtils.readFileToString(settingsFile, "UTF-8"));
        final MindMapPanelConfig config = new MindMapPanelConfig();
        config.loadFrom(prefs);
        config.saveTo(PreferencesManager.getInstance().getPreferences());
        PreferencesManager.getInstance().flush();
        // NOI18N
        LOGGER.info("Settings imported from file : " + settingsFile);
    } catch (final Exception ex) {
        // NOI18N
        LOGGER.error("Error during import from file : " + settingsFile, 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