Merge remote-tracking branch 'origin/development' into development
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 2 Oct 2019 14:05:18 +0000 (16:05 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 2 Oct 2019 14:05:18 +0000 (16:05 +0200)
plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties
plugins/net.mograsim.plugin.core/plugin.xml
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/MemoryEditor.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/FontAndColorHelper.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/SingleSWTRequest.java

index 2c6f94c..8bec772 100644 (file)
@@ -17,6 +17,7 @@ decorator.label = Resource Decorator
 themeElementCategory.label = Mograsim
 themeElementCategory.label.0 = Simulation
 themeElementCategory.label.1 = Microinstructions
+themeElementCategory.label.2 = Memory
 colorDefinition.label = Simulation Background
 colorDefinition.description = The Background of the Simulation Visualisation
 colorDefinition.label.0 = Simulation Foreground Color
@@ -36,6 +37,7 @@ colorDefinition.label.13 = Highlighted Cell Background Color
 colorDefinition.label.14 = Highlighted Cell Foreground Color
 fontDefinition.label = Assembler Operation Style
 fontDefinition.label.0 = Table Font
+fontDefinition.label.1 = Table Font
 view.name.0 = Simulation View
 view.name.1 = Memory
 wizards.newWizards.category = Mograsim
index 9060a60..8e00c1f 100644 (file)
             label="%themeElementCategory.label.1"
             parentId="net.mograsim.plugin.mograsim">
       </themeElementCategory>
+      <themeElementCategory
+            class="net.mograsim.plugin.SimulationPreview"
+            id="net.mograsim.plugin.memory"
+            label="%themeElementCategory.label.2"
+            parentId="net.mograsim.plugin.mograsim">
+      </themeElementCategory>
       <colorDefinition
             categoryId="net.mograsim.logic.model"
             id="net.mograsim.logic.model.color.background"
       </fontDefinition>
       <colorDefinition
             categoryId="net.mograsim.plugin.mi"
-            id="net.mograsim.plugin.modified_cell_bg_color"
+            id="net.mograsim.plugin.mi.modified_cell_bg_color"
             isEditable="true"
             label="%colorDefinition.label.11"
             value="COLOR_GREEN">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.plugin.mi"
-            id="net.mograsim.plugin.modified_cell_fg_color"
+            id="net.mograsim.plugin.mi.modified_cell_fg_color"
             isEditable="true"
             label="%colorDefinition.label.12"
             value="COLOR_BLACK">
       </colorDefinition>
-      <fontDefinition
-            categoryId="net.mograsim.plugin.mi"
-            id="net.mograsim.plugin.table_font"
-            isEditable="true"
-            label="%fontDefinition.label.0">
-      </fontDefinition>
       <colorDefinition
             categoryId="net.mograsim.plugin.mi"
-            id="net.mograsim.plugin.highlighted_cell_bg_color"
+            id="net.mograsim.plugin.mi.highlighted_cell_bg_color"
             isEditable="true"
             label="%colorDefinition.label.13"
             value="COLOR_YELLOW">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.plugin.mi"
-            id="net.mograsim.plugin.highlighted_cell_fg_color"
+            id="net.mograsim.plugin.mi.highlighted_cell_fg_color"
             isEditable="true"
             label="%colorDefinition.label.14"
             value="COLOR_BLACK">
       </colorDefinition>
+      <fontDefinition
+            categoryId="net.mograsim.plugin.mi"
+            id="net.mograsim.plugin.mi.table_font"
+            isEditable="true"
+            label="%fontDefinition.label.0">
+      </fontDefinition>
+      <fontDefinition
+            categoryId="net.mograsim.plugin.memory"
+            id="net.mograsim.plugin.memory.table_font"
+            isEditable="true"
+            label="%fontDefinition.label.1">
+      </fontDefinition>
    </extension>
    <extension
          point="org.eclipse.ui.preferencePages">
index 507adae..028a1b5 100644 (file)
@@ -7,6 +7,7 @@ import java.math.BigInteger;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.SafeRunnable;
 import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.swt.SWT;
@@ -23,6 +24,8 @@ import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.themes.ITheme;
+import org.eclipse.ui.themes.IThemeManager;
 
 import net.mograsim.machine.MainMemory;
 import net.mograsim.machine.MainMemoryDefinition;
@@ -56,6 +59,9 @@ public class MemoryEditor extends EditorPart
 
        private final MemoryCellModifiedListener memListener;
 
+       private final static String font = "net.mograsim.plugin.memory.table_font";
+       private IPropertyChangeListener fontChangeListener;
+
        public MemoryEditor()
        {
                memListener = this::cellModified;
@@ -139,12 +145,29 @@ public class MemoryEditor extends EditorPart
                table.setLinesVisible(true);
                viewer.setUseHashlookup(true);
                viewer.setContentProvider(provider);
-               getSite().setSelectionProvider(viewer);// TODO what does this?
+               getSite().setSelectionProvider(viewer);// TODO what does this do?
                viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 7, 1));
+
+               IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager();
+               themeManager.addPropertyChangeListener(fontChangeListener = (e) ->
+               {
+                       if (IThemeManager.CHANGE_CURRENT_THEME.equals(e.getProperty()) || font.equals(e.getProperty()))
+                       {
+                               updateFont(themeManager.getCurrentTheme());
+                               viewer.refresh();
+                       }
+               });
+               updateFont(themeManager.getCurrentTheme());
+
                if (memory != null)
                        viewer.setInput(memory);
        }
 
+       private void updateFont(ITheme theme)
+       {
+               viewer.getTable().setFont(theme.getFontRegistry().get(font));
+       }
+
        private void createColumns()
        {
                TableViewerColumn addrCol = createTableViewerColumn("Address", 100);
@@ -274,6 +297,7 @@ public class MemoryEditor extends EditorPart
        @Override
        public void dispose()
        {
+               getSite().getWorkbenchWindow().getWorkbench().getThemeManager().removePropertyChangeListener(fontChangeListener);
                if (memory != null)
                        memory.deregisterCellModifiedListener(memListener);
                super.dispose();
index 82d7e8b..a97d2c6 100644 (file)
@@ -1,13 +1,17 @@
 package net.mograsim.plugin.launch;
 
+import static org.eclipse.core.resources.IResourceDelta.CHANGED;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResourceChangeEvent;
 import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -16,6 +20,8 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.statushandlers.StatusManager;
 
 import net.mograsim.machine.Machine;
@@ -38,6 +44,8 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate
        public static final String INITIAL_RAM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".initialram";
 
        private final IResourceChangeListener resChangedListener;
+       private IFile mpmFile;
+       private Machine machine;
 
        public MachineLaunchConfigType()
        {
@@ -126,20 +134,9 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate
 
                MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project);
                MachineDefinition machineDefinition = machineContext.getMachineDefinition().orElseThrow();
-               MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition();
                MainMemoryDefinition mainMemDef = machineDefinition.getMainMemoryDefinition();
 
-               IFile mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, ""));
-
-               MicroInstructionMemory mpm;
-               try (InputStream mpmStream = mpmFile.getContents())
-               {
-                       mpm = MicroInstructionMemoryParser.parseMemory(miMemDef, mpmStream);
-               }
-               catch (IOException e)
-               {
-                       throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e));
-               }
+               mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, ""));
 
                String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, "");
                MainMemory mem;
@@ -161,16 +158,30 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate
                MachineDebugTarget debugTarget = new MachineDebugTarget(launch, machineDefinition);
                debugTarget.suspend();
                debugTarget.setExecutionSpeed(1);
-               Machine machine = debugTarget.getMachine();
-               machine.getMicroInstructionMemory().bind(mpm);
+               machine = debugTarget.getMachine();
+               assignMicroInstructionMemory();
                if (mem != null)
                        machine.getMainMemory().bind(mem);
                machine.reset();
        }
 
+       private void assignMicroInstructionMemory() throws CoreException
+       {
+               try (InputStream mpmStream = mpmFile.getContents())
+               {
+                       MicroInstructionMemory mpm = MicroInstructionMemoryParser
+                                       .parseMemory(machine.getDefinition().getMicroInstructionMemoryDefinition(), mpmStream);
+                       machine.getMicroInstructionMemory().bind(mpm);
+               }
+               catch (IOException e)
+               {
+                       throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e));
+               }
+       }
+
        private void resourceChanged(IResourceChangeEvent event)
        {
-               // TODO react to MPM changes
+               // TODO remove Sysout
                int type = event.getType();
                String typeStr;
                switch (type)
@@ -180,6 +191,33 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate
                        break;
                case IResourceChangeEvent.POST_CHANGE:
                        typeStr = "POST_CHANGE";
+                       IResourceDelta mpmDelta;
+                       if ((mpmDelta = event.getDelta().findMember(mpmFile.getFullPath())) != null && (mpmDelta.getKind() & CHANGED) == CHANGED
+                                       && mpmFile.exists())
+                       {
+                               AtomicBoolean doHotReplace = new AtomicBoolean();
+                               PlatformUI.getWorkbench().getDisplay().syncExec(() ->
+                               {
+                                       if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Hot Replace MPM?",
+                                                       String.format("The MPM %s has been modified on the file system. Replace simulated MPM with modified contents?",
+                                                                       mpmFile.getName())))
+                                               doHotReplace.set(true);
+                               });
+                               if (doHotReplace.get())
+                               {
+                                       try
+                                       {
+                                               assignMicroInstructionMemory();
+                                       }
+                                       catch (CoreException e)
+                                       {
+                                               PlatformUI.getWorkbench().getDisplay()
+                                                               .asyncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                                                                               "Failed Hot Replace!",
+                                                                               "An error occurred trying to read the modified MPM from the file system: " + e.getMessage()));
+                                       }
+                               }
+                       }
                        break;
                case IResourceChangeEvent.PRE_BUILD:
                        typeStr = "PRE_BUILD";
index befbac8..1aabce6 100644 (file)
@@ -23,11 +23,11 @@ public class FontAndColorHelper
        private Font boldItalic, bold, italic, normal;
        private Color modifBackground, modifForeground, highlightBackground, highlightForeground;
 
-       private final static String font = "net.mograsim.plugin.table_font",
-                       colorModifBackground = "net.mograsim.plugin.modified_cell_bg_color",
-                       colorModifForeground = "net.mograsim.plugin.modified_cell_fg_color",
-                       colorHighlightForeground = "net.mograsim.plugin.highlighted_cell_fg_color",
-                       colorHighlightBackground = "net.mograsim.plugin.highlighted_cell_bg_color";
+       private final static String font = "net.mograsim.plugin.mi.table_font",
+                       colorModifBackground = "net.mograsim.plugin.mi.modified_cell_bg_color",
+                       colorModifForeground = "net.mograsim.plugin.mi.modified_cell_fg_color",
+                       colorHighlightForeground = "net.mograsim.plugin.mi.highlighted_cell_fg_color",
+                       colorHighlightBackground = "net.mograsim.plugin.mi.highlighted_cell_bg_color";
        private final IPropertyChangeListener updateListener;
 
        public FontAndColorHelper(TableViewer viewer, IThemeManager themeManager)
index c4a1eee..9ffa772 100644 (file)
@@ -2,7 +2,7 @@ package net.mograsim.plugin.util;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
 
 /**
  * A utility class that requests the asynchronous execution of a Runnable in the SWT Thread. Making a new request before the old one is
@@ -21,7 +21,7 @@ public class SingleSWTRequest
                        if (!waiting.get())
                        {
                                waiting.set(true);
-                               Display.getDefault().asyncExec(() ->
+                               PlatformUI.getWorkbench().getDisplay().asyncExec(() ->
                                {
                                        synchronized (waiting)
                                        {