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;
}
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);
}
}
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);
}
}
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() {
}
};
}
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);
}
Aggregations