X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2FEditor.java;h=e3279150e4710f780cebd3302fa066f1698c07f3;hb=ec0a13e824a9058dc41ba0952fdf8ad99fb19772;hp=e4c92928d012eb785e4bdf1c4312acbd0042beb8;hpb=f87464acdb28197031f7235e60ed7de1ac206723;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java index e4c92928..e3279150 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java @@ -53,10 +53,10 @@ public final class Editor dialogManager = new DialogManager(gui.shell); toBeEdited.submodel.addComponentRemovedListener(c -> identifierPerComponent.remove(c)); - + gui.open(); } - + public ViewModelModifiable getSubmodel() { return toBeEdited.getSubmodelModifiable(); @@ -67,8 +67,8 @@ public final class Editor return selection; } - //TODO: Remove this error prone method: Relative offset may change between multiple moves, - //because Handles have different ways of responding to reqMove(...), causing strange behaviour + // TODO: Remove this error prone method: Relative offset may change between multiple moves, + // because Handles have different ways of responding to reqMove(...), causing strange behaviour @Deprecated public void moveSelection(double x, double y) { @@ -84,7 +84,7 @@ public final class Editor c.reqMove(newX, newY); } } - + public void moveHandles(double x, double y, Map handleOffsetMap) { Point snapped = new Point(x, y); @@ -113,7 +113,7 @@ public final class Editor for (Handle h : selection) { Optional cInfo = h.reqCopy(refPoint); - if(cInfo.isPresent()) + if (cInfo.isPresent()) copyBuffer.add(cInfo.get()); } } @@ -130,18 +130,22 @@ public final class Editor } moveSelection(x, y); } - + public void save() { saveManager.save(); } + public void saveAs() + { + saveManager.openSaveAsDialog(); + } + public void addComponent(double x, double y) { boolean successful = false; JsonElement params = JsonNull.INSTANCE; - outer: - while(!successful) + outer: while (!successful) { String selected = gui.getAddListSelected(); try @@ -152,24 +156,23 @@ public final class Editor moveSelection(x, y); successful = true; } - catch(UnsupportedOperationException | JsonSyntaxException | NumberFormatException e) + catch (@SuppressWarnings("unused") UnsupportedOperationException | JsonSyntaxException | NumberFormatException e) { String result = DialogManager.openMultiLineTextDialog("Add component", "Create", "Cancel", "Parameters:"); - if(result == null) + if (result == null) break outer; params = new JsonParser().parse(result); } } } - + private GUIComponent addComponent(String identifier, JsonElement params) { - GUIComponent comp = IndirectGUIComponentCreator.createComponent(toBeEdited.getSubmodelModifiable(), identifier, - params); + GUIComponent comp = IndirectGUIComponentCreator.createComponent(toBeEdited.getSubmodelModifiable(), identifier, params); identifierPerComponent.put(comp, identifier); return comp; } - + public static String getIdentifier(GUIComponent c) { return identifierPerComponent.get(c); @@ -189,8 +192,10 @@ public final class Editor case OFF: break; case ABSOLUTE: - newP.x -= newP.x % snapX; - newP.y -= newP.y % snapY; + newP.x = (int) (newP.x / snapX + .5) * snapX; + newP.y = (int) (newP.y / snapY + .5) * snapY; + break; + default: break; } } @@ -200,7 +205,7 @@ public final class Editor public final double relX, relY; public final String identifier; public final JsonElement params; - + public ComponentInfo(double relX, double relY, String identifier, JsonElement params) { this.relX = relX; @@ -210,6 +215,7 @@ public final class Editor } } + @SuppressWarnings("unused") public void addWire(PinHandle a, PinHandle b) { new GUIWire(toBeEdited.getSubmodelModifiable(), a.getPin(), b.getPin(), new Point[0]); @@ -218,14 +224,14 @@ public final class Editor public static enum Snapping { OFF, ABSOLUTE; - + @Override public String toString() { return super.toString().toLowerCase(); } } - + public static void main(String[] args) throws IOException { SaveLoadManager.openLoadDialog();