label="%fontDefinition.label">
</fontDefinition>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="net.mograsim.plugin.MainPreferencePage"
+ id="net.mograsim.plugin.core.mainprefpage"
+ name="Mograsim preferences">
+ </page>
+ </extension>
</plugin>
--- /dev/null
+package net.mograsim.plugin;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.ui.themes.ITheme;
+
+import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.DefaultPreferences;
+import net.mograsim.preferences.Preferences;
+
+public class EclipsePreferences extends Preferences
+{
+ private final ITheme theme;
+ private final IPreferenceStore prefs;
+ private final Preferences defaultPrefs;
+
+ public EclipsePreferences(ITheme theme, IPreferenceStore prefs)
+ {
+ this.theme = theme;
+ this.prefs = prefs;
+ this.defaultPrefs = new DefaultPreferences();
+ }
+
+ @Override
+ public boolean getBoolean(String name)
+ {
+ prefs.setDefault(name, defaultPrefs.getBoolean(name));
+ return prefs.getBoolean(name);
+ }
+
+ @Override
+ public int getInt(String name)
+ {
+ prefs.setDefault(name, defaultPrefs.getInt(name));
+ return prefs.getInt(name);
+ }
+
+ @Override
+ public double getDouble(String name)
+ {
+ prefs.setDefault(name, defaultPrefs.getDouble(name));
+ return prefs.getDouble(name);
+ }
+
+ @Override
+ public ColorDefinition getColorDefinition(String name)
+ {
+ RGB rgb = getColorRegistry().getRGB(name);
+ if (rgb == null)
+ {
+ StatusManager.getManager().handle(new Status(IStatus.ERROR, "net.mograsim.plugin.core", "No color for name " + name));
+ return null;
+ }
+ return new ColorDefinition(rgb.red, rgb.green, rgb.blue);
+ }
+
+ @Override
+ public Color getColor(String name)
+ {
+ return getColorRegistry().get(name);
+ }
+
+ private ColorRegistry getColorRegistry()
+ {
+ return theme.getColorRegistry();
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.mograsim.plugin;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class MainPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
+{
+ public MainPreferencePage()
+ {
+ super(GRID);
+ }
+
+ @Override
+ public void init(IWorkbench workbench)
+ {
+ setPreferenceStore(MograsimActivator.instance().getPreferenceStore());
+ }
+
+ @Override
+ protected void createFieldEditors()
+ {
+ addField(new BooleanFieldEditor("net.mograsim.logic.model.debug.openhlsshell", "Open the debug HLS shell", getFieldEditorParent()));
+ // TODO add other preferences
+ }
+}
\ No newline at end of file
public final class MograsimActivator extends AbstractUIPlugin
{
+ private static MograsimActivator instance;
public MograsimActivator()
{
+ if (instance != null)
+ throw new IllegalStateException("MograsimActivator already created!");
+ instance = this;
MachineRegistry.reload();
}
-}
+
+ public static MograsimActivator instance()
+ {
+ if (instance == null)
+ throw new IllegalStateException("MograsimActivator not yet created!");
+ return instance;
+ }
+}
\ No newline at end of file
{
oldPreferences = Preferences.current();
- currentThemePreferences = new ThemePreferences(currentTheme);
+ currentThemePreferences = new EclipsePreferences(currentTheme, MograsimActivator.instance().getPreferenceStore());
// TODO this will change the global preferences; so if another LogicUICanvas redraws, it will use the "new" colors too.
Preferences.setPreferences(currentThemePreferences);
+++ /dev/null
-package net.mograsim.plugin;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.ColorRegistry;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.ui.statushandlers.StatusManager;
-import org.eclipse.ui.themes.ITheme;
-
-import net.mograsim.preferences.ColorDefinition;
-import net.mograsim.preferences.DefaultPreferences;
-import net.mograsim.preferences.Preferences;
-
-// TODO proper getInt/getDouble implementation, maybe via own preferences page?
-public class ThemePreferences extends Preferences
-{
- private final ITheme theme;
-
- public ThemePreferences(ITheme theme)
- {
- this.theme = theme;
- }
-
- @Override
- public boolean getBoolean(String name)
- {
- return new DefaultPreferences().getBoolean(name);
- }
-
- @Override
- public int getInt(String name)
- {
- return new DefaultPreferences().getInt(name);
- }
-
- @Override
- public double getDouble(String name)
- {
- return new DefaultPreferences().getDouble(name);
- }
-
- @Override
- public ColorDefinition getColorDefinition(String name)
- {
- RGB rgb = getColorRegistry().getRGB(name);
- if (rgb == null)
- {
- StatusManager.getManager().handle(new Status(IStatus.ERROR, "net.mograsim.plugin.core", "No color for name " + name));
- return null;
- }
- return new ColorDefinition(rgb.red, rgb.green, rgb.blue);
- }
-
- @Override
- public Color getColor(String name)
- {
- return getColorRegistry().get(name);
- }
-
- private ColorRegistry getColorRegistry()
- {
- return theme.getColorRegistry();
- }
-}
\ No newline at end of file
import net.mograsim.logic.model.LogicExecuter;
import net.mograsim.logic.model.LogicUICanvas;
import net.mograsim.machine.Machine;
+import net.mograsim.plugin.EclipsePreferences;
import net.mograsim.plugin.MachineContext;
-import net.mograsim.plugin.ThemePreferences;
+import net.mograsim.plugin.MograsimActivator;
import net.mograsim.preferences.Preferences;
public class LogicUIPart extends ViewPart
public void createPartControl(Composite parent)
{
// set preferences
- Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme()));
+ Preferences.setPreferences(new EclipsePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(),
+ MograsimActivator.instance().getPreferenceStore()));
Machine m = MachineContext.getInstance().getMachine();