Search in sources :

Example 41 with BackingStoreException

use of java.util.prefs.BackingStoreException in project netbeans-mmd-plugin by raydac.

the class MindMapPanelConfig method loadFrom.

@Nullable
public Preferences loadFrom(@Nullable final Preferences prefs) {
    if (prefs != null) {
        final String prefix = MindMapPanelConfig.class.getSimpleName();
        final MindMapPanelConfig etalon = new MindMapPanelConfig();
        for (final Field f : MindMapPanelConfig.class.getDeclaredFields()) {
            if ((f.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT | Modifier.FINAL)) != 0) {
                continue;
            }
            final Class<?> fieldClass = f.getType();
            final String fieldName = prefix + '.' + f.getName();
            try {
                if (fieldClass == boolean.class) {
                    f.setBoolean(this, prefs.getBoolean(fieldName, f.getBoolean(etalon)));
                } else if (fieldClass == int.class) {
                    f.setInt(this, prefs.getInt(fieldName, f.getInt(etalon)));
                } else if (fieldClass == float.class) {
                    f.setFloat(this, prefs.getFloat(fieldName, f.getFloat(etalon)));
                } else if (fieldClass == double.class) {
                    f.setDouble(this, prefs.getDouble(fieldName, f.getDouble(etalon)));
                } else if (fieldClass == Font.class) {
                    final Font etalonFont = (Font) etalon.getFont();
                    final String fontName = (String) prefs.get(fieldName + ".name", etalonFont.getName());
                    final int fontSize = prefs.getInt(fieldName + ".size", etalonFont.getSize());
                    final int fontStyle = prefs.getInt(fieldName + ".style", etalonFont.getStyle());
                    f.set(this, new Font(fontName, fontStyle, fontSize));
                } else if (fieldClass == Color.class) {
                    final int argb = prefs.getInt(fieldName, ((Color) f.get(etalon)).getRGB());
                    f.set(this, new Color(argb, true));
                } else if (fieldClass == String.class) {
                    f.set(this, prefs.get(fieldName, (String) f.get(etalon)));
                } else if (fieldClass == RenderQuality.class) {
                    final String name = prefs.get(fieldName, ((RenderQuality) f.get(etalon)).name());
                    f.set(this, RenderQuality.valueOf(name));
                } else {
                    throw new Error("Unexpected field type " + fieldClass.getName());
                }
            } catch (IllegalAccessException ex) {
                throw new Error("IllegalAccessException [" + fieldClass.getName() + ']', ex);
            } catch (IllegalArgumentException ex) {
                throw new Error("IllegalArgumentException [" + fieldClass.getName() + ']', ex);
            }
        }
        this.mapShortCut.clear();
        this.mapShortCut.putAll(etalon.mapShortCut);
        try {
            for (final String k : prefs.keys()) {
                if (k.startsWith("mapShortCut.")) {
                    // final int dotIndex = k.indexOf('.');
                    // final String id = k.substring(dotIndex + 1);
                    final String packedValue = prefs.get(k, "");
                    if (packedValue.isEmpty()) {
                        throw new Error("Unexpected situation, short cut value is empty [" + k + ']');
                    }
                    final KeyShortcut unpacked = new KeyShortcut(packedValue);
                    this.mapShortCut.put(unpacked.getID(), unpacked);
                }
            }
        } catch (BackingStoreException ex) {
            throw new Error("Can't get list of keys from storage", ex);
        }
    }
    return prefs;
}
Also used : Color(java.awt.Color) KeyShortcut(com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut) BackingStoreException(java.util.prefs.BackingStoreException) Font(java.awt.Font) Field(java.lang.reflect.Field) RenderQuality(com.igormaznitsa.mindmap.swing.panel.utils.RenderQuality) Nullable(javax.annotation.Nullable)

Example 42 with BackingStoreException

use of java.util.prefs.BackingStoreException in project dwoss by gg-net.

the class UserPreferencesJdk method loadLocation.

/**
 * Loads and sets the location and size on the component if existing in the store.
 *
 * @param key the key
 * @param c   the window
 */
@Override
public void loadLocation(Class<?> key, Component c) {
    if (key == null || c == null)
        return;
    try {
        if (!Preferences.userNodeForPackage(key).nodeExists(key.getSimpleName()))
            return;
        Preferences p = Preferences.userNodeForPackage(key).node(key.getSimpleName());
        if (reset) {
            p.clear();
            L.info("Reset on load {} reseted", p);
        } else {
            c.setLocation(p.getInt(WINDOW_X, 100), p.getInt(WINDOW_Y, 100));
            c.setSize(p.getInt(WINDOW_WIDTH, 200), p.getInt(WINDOW_HEIGHT, 200));
            L.debug("Loaded: {}", p);
        }
    } catch (BackingStoreException ex) {
        L.error("Cound not load Preferences", ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 43 with BackingStoreException

use of java.util.prefs.BackingStoreException in project dwoss by gg-net.

the class UserPreferencesJdk method loadLocation.

/**
 * Loads and sets the location and size on the component if existing in the store.
 *
 * @param key the key
 * @param c   the window
 */
public void loadLocation(Class<?> key, Window c) {
    if (key == null || c == null)
        return;
    try {
        if (!Preferences.userNodeForPackage(key).nodeExists(key.getSimpleName()))
            return;
        Preferences p = Preferences.userNodeForPackage(key).node(key.getSimpleName());
        if (reset) {
            p.clear();
            L.info("Reset on load {} reseted", p);
        } else {
            c.setX(p.getDouble(WINDOW_X, 100));
            c.setY(p.getDouble(WINDOW_Y, 100));
            c.setWidth(p.getDouble(WINDOW_WIDTH, 200));
            c.setHeight(p.getDouble(WINDOW_HEIGHT, 200));
            L.debug("Loaded: {}", p);
        }
    } catch (BackingStoreException ex) {
        L.error("Cound not load Preferences", ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 44 with BackingStoreException

use of java.util.prefs.BackingStoreException in project qi4j-sdk by Qi4j.

the class PreferencesEntityStoreMixin method applyChanges.

@Override
public StateCommitter applyChanges(final EntityStoreUnitOfWork unitofwork, final Iterable<EntityState> state) {
    return new StateCommitter() {

        @Override
        public void commit() {
            try {
                synchronized (root) {
                    for (EntityState entityState : state) {
                        DefaultEntityState state = (DefaultEntityState) entityState;
                        if (state.status().equals(EntityStatus.NEW)) {
                            Preferences entityPrefs = root.node(state.identity().identity());
                            writeEntityState(state, entityPrefs, unitofwork.identity(), unitofwork.currentTime());
                        } else if (state.status().equals(EntityStatus.UPDATED)) {
                            Preferences entityPrefs = root.node(state.identity().identity());
                            writeEntityState(state, entityPrefs, unitofwork.identity(), unitofwork.currentTime());
                        } else if (state.status().equals(EntityStatus.REMOVED)) {
                            root.node(state.identity().identity()).removeNode();
                        }
                    }
                    root.flush();
                }
            } catch (BackingStoreException e) {
                throw new EntityStoreException(e);
            }
        }

        @Override
        public void cancel() {
        }
    };
}
Also used : DefaultEntityState(org.qi4j.spi.entitystore.helpers.DefaultEntityState) BackingStoreException(java.util.prefs.BackingStoreException) StateCommitter(org.qi4j.spi.entitystore.StateCommitter) EntityState(org.qi4j.spi.entity.EntityState) DefaultEntityState(org.qi4j.spi.entitystore.helpers.DefaultEntityState) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException) Preferences(java.util.prefs.Preferences)

Example 45 with BackingStoreException

use of java.util.prefs.BackingStoreException in project qi4j-sdk by Qi4j.

the class PreferencesEntityStoreMixin method activateService.

@Override
public void activateService() throws Exception {
    root = getApplicationRoot();
    logger = LoggerFactory.getLogger(PreferencesEntityStoreService.class.getName());
    logger.info("Preferences store:" + root.absolutePath());
    uuid = UUID.randomUUID().toString() + "-";
    // Reload underlying store every 60 seconds
    reloadExecutor = new ScheduledThreadPoolExecutor(1);
    reloadExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    reloadExecutor.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            try {
                synchronized (root) {
                    root.sync();
                }
            } catch (BackingStoreException e) {
                logger.warn("Could not reload preferences", e);
            }
        }
    }, 0, 60, TimeUnit.SECONDS);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BackingStoreException(java.util.prefs.BackingStoreException)

Aggregations

BackingStoreException (java.util.prefs.BackingStoreException)112 Preferences (java.util.prefs.Preferences)95 NbPreferences (org.openide.util.NbPreferences)14 File (java.io.File)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)4 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)4 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)4 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)4 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)4 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)4 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)4 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileLinkPreferences (org.jabref.logic.layout.format.FileLinkPreferences)4 NameFormatterPreferences (org.jabref.logic.layout.format.NameFormatterPreferences)4 ProxyPreferences (org.jabref.logic.net.ProxyPreferences)4 OpenOfficePreferences (org.jabref.logic.openoffice.OpenOfficePreferences)4 ProtectedTermsPreferences (org.jabref.logic.protectedterms.ProtectedTermsPreferences)4