import net.mograsim.logic.ui.model.wires.WireCrossPoint;
import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
+import net.mograsim.preferences.Preferences;
public class SimulationPreview implements IThemePreview
{
-
private LogicUICanvas ui;
private LogicExecuter exec;
+ private Preferences oldPreferences;
+ private Preferences currentThemePreferences;
@Override
@SuppressWarnings("unused")
public void createControl(Composite parent, ITheme currentTheme)
{
+ oldPreferences = Preferences.current();
+
+ currentThemePreferences = new ThemePreferences(currentTheme);
+ // TODO this will change the global preferences; so if another LogicUICanvas redraws, it will use the "new" colors too.
+ Preferences.setPreferences(currentThemePreferences);
+
ViewModelModifiable model = new ViewModelModifiable();
LogicModelParameters params = new LogicModelParameters();
params.gateProcessTime = 50;
ui.zoom(3.5, 10, 10);
exec.startLiveExecution();
+
+ currentTheme.addPropertyChangeListener(e -> ui.redraw());
}
@Override
public void dispose()
{
exec.stopLiveExecution();
+ if (Preferences.current() == currentThemePreferences)
+ Preferences.setPreferences(oldPreferences);
}
}
--- /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.Preferences;
+
+public class ThemePreferences extends Preferences
+{
+ private final ITheme theme;
+
+ public ThemePreferences(ITheme theme)
+ {
+ this.theme = theme;
+ }
+
+ @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 javax.inject.Inject;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
-import org.eclipse.ui.statushandlers.StatusManager;
import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
import net.mograsim.logic.core.timeline.Timeline;
import net.mograsim.logic.ui.model.wires.GUIWire;
import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
-import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.plugin.ThemePreferences;
import net.mograsim.preferences.Preferences;
public class LogicUIPart extends ViewPart
public void createPartControl(Composite parent)
{
// set preferences
- Preferences.setPreferences(new Preferences()
- {
- @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 PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
- }
- });
+ Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme()));
// setup view model
ViewModelModifiable viewModel = new ViewModelModifiable();