package ie.dcu.apps.ist; import static ie.dcu.segment.annotate.AnnotationType.*; import static ie.dcu.apps.ist.AppPrefs.Keys.*; import static ie.dcu.apps.ist.AppPrefs.SupportedTypes.*; import ie.dcu.segment.annotate.*; import ie.dcu.apps.ist.AppPrefs.*; import java.util.prefs.*; import org.eclipse.jface.resource.*; import org.eclipse.swt.graphics.*; /** * Manages updating various components when preferences change. * * @author Kevin McGuinness */ class AppPrefsManager implements PreferenceChangeListener { private final AppWindow window; private final ColorRegistry colorRegistry; private final AppPrefs prefs; public AppPrefsManager(AppWindow window) { this.window = window; this.colorRegistry = JFaceResources.getColorRegistry(); this.prefs = loadPreferences(); } private AppPrefs loadPreferences() { AppPrefs prefs = new AppPrefs(); prefs.addPreferenceChangeListener(this); return prefs; } public AppPrefs getPrefs() { return prefs; } public void update() { updateFeedbackEnabled(); updateBackgroundColor(); updateForegroundColor(); updateExperimentEmbedded(); } public void updateExperimentEmbedded() { boolean on = prefs.get(BOOLEAN, Keys.EXPERIMENT_EMBEDDED, false); window.setExperimentModeEmbedded(on); } public void updateFeedbackEnabled() { boolean on = prefs.get(BOOLEAN, Keys.ENABLE_FEEDBACK, true); window.setEnableFeedback(on); } public void updateForegroundColor() { RGB color = prefs.get(RGB, Keys.FOREGROUND_COLOR, DEFAULT_FOREGROUND); colorRegistry.put(AnnotationType.Foreground.key, color); window.getView().repaint(); } public void updateBackgroundColor() { RGB color = prefs.get(RGB, Keys.BACKGROUND_COLOR, DEFAULT_BACKGROUND); colorRegistry.put(AnnotationType.Background.key, color); window.getView().repaint(); } public void preferenceChange(PreferenceChangeEvent evt) { String pref = evt.getKey(); if (pref.equals(ENABLE_FEEDBACK)) { updateFeedbackEnabled(); } else if (pref.equals(FOREGROUND_COLOR)) { updateForegroundColor(); } else if (pref.equals(BACKGROUND_COLOR)) { updateBackgroundColor(); } else if (pref.equals(EXPERIMENT_EMBEDDED)) { updateExperimentEmbedded(); } } }