Editor now creates a new component per default; re-added New option
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 5 Sep 2019 13:26:13 +0000 (15:26 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 5 Sep 2019 13:26:13 +0000 (15:26 +0200)
net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java
net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java

index 903f882..b6de1ac 100644 (file)
@@ -1,6 +1,5 @@
 package net.mograsim.logic.model.editor;
 
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -27,6 +26,9 @@ import net.mograsim.logic.model.model.wires.GUIWire;
 import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent;
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
+import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.DefaultSymbolRenderer;
 
 public final class Editor
 {
@@ -158,7 +160,8 @@ public final class Editor
                                moveSelection(x, y);
                                successful = true;
                        }
-                       catch (@SuppressWarnings("unused") UnsupportedOperationException | JsonSyntaxException | NumberFormatException e)
+                       catch (@SuppressWarnings("unused") UnsupportedOperationException | JsonSyntaxException | NumberFormatException
+                                       | NullPointerException e)
                        {
                                String result = DialogManager.openMultiLineTextDialog("Add component", "Create", "Cancel", "Parameters:");
                                if (result == null)
@@ -236,10 +239,20 @@ public final class Editor
                }
        }
 
-       public static void main(String[] args) throws IOException
+       public static void main(String[] args)
        {
                Am2900Loader.setup();
-               SaveLoadManager.openLoadDialog();
+               openNewEditor();
+//             SaveLoadManager.openLoadDialog();
+       }
+
+       public static void openNewEditor()
+       {
+               DeserializedSubmodelComponent toBeEdited = new DeserializedSubmodelComponent(new ViewModelModifiable(), null, null, null);
+               toBeEdited.setOutlineRenderer(new DefaultOutlineRenderer(toBeEdited));
+               toBeEdited.setSymbolRenderer(new DefaultSymbolRenderer(toBeEdited));
+               toBeEdited.setHighLevelStateHandler(new DefaultHighLevelStateHandler());
+               new Editor(toBeEdited);
        }
 
        public Snapping getSnapping()
index 7fd7323..0c4d038 100644 (file)
@@ -95,8 +95,7 @@ public class EditorGUI
                ToolItem file = new ToolItem(toolBar, SWT.DROP_DOWN);
 
                // TODO
-//             DropDownEntry newEntry = new DropDownEntry("New", e -> {
-//             });
+               DropDownEntry newEntry = new DropDownEntry("New", e -> Editor.openNewEditor());
                DropDownEntry loadEntry = new DropDownEntry("Load", e ->
                {
                        try
@@ -111,7 +110,7 @@ public class EditorGUI
                DropDownEntry saveEntry = new DropDownEntry("Save", e -> editor.save());
                DropDownEntry saveAsEntry = new DropDownEntry("Save as...", e -> editor.saveAs());
 
-               DropDownEntry[] entries = new DropDownEntry[] { loadEntry, saveEntry, saveAsEntry };
+               DropDownEntry[] entries = new DropDownEntry[] { newEntry, loadEntry, saveEntry, saveAsEntry };
 
                setupDrowpDownMenu(file, entries);
 
@@ -230,5 +229,4 @@ public class EditorGUI
                        if (!display.readAndDispatch())
                                display.sleep();
        }
-
-}
+}
\ No newline at end of file