import java.util.function.Consumer;
import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
public class SimpleLogicUIStandalone
{
- public static void executeVisualisation(Consumer<ViewModel> setupViewModel)
+ public static void executeVisualisation(Consumer<ViewModelModifiable> setupViewModel)
{
LogicModelParameters params = new LogicModelParameters();
params.gateProcessTime = 50;
executeVisualisation(setupViewModel, params);
}
- public static void executeVisualisation(Consumer<ViewModel> setupViewModel, LogicModelParameters params)
+ public static void executeVisualisation(Consumer<ViewModelModifiable> setupViewModel, LogicModelParameters params)
{
// setup view model
- ViewModel viewModel = new ViewModel();
+ ViewModelModifiable viewModel = new ViewModelModifiable();
setupViewModel.accept(viewModel);
// convert to logic model
package net.mograsim.logic.ui.examples;
import net.mograsim.logic.ui.SimpleLogicUIStandalone;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.components.Am2901NANDBased;
import net.mograsim.logic.ui.model.components.GUIBitDisplay;
import net.mograsim.logic.ui.model.components.GUIManualSwitch;
}
@SuppressWarnings("unused") // for GUIWires being created
- public static void createAm2901Example(ViewModel model)
+ public static void createAm2901Example(ViewModelModifiable model)
{
Am2901NANDBased am2901 = new Am2901NANDBased(model);
am2901.moveTo(100, 0);
package net.mograsim.logic.ui.examples;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.mograsim.logic.ui.SimpleLogicUIStandalone;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.components.GUIManualSwitch;
import net.mograsim.logic.ui.model.components.GUINotGate;
import net.mograsim.logic.ui.model.components.GUIOrGate;
import net.mograsim.logic.ui.model.wires.GUIWire;
import net.mograsim.logic.ui.model.wires.WireCrossPoint;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
public class RSLatchExample
{
}
@SuppressWarnings("unused") // for GUIWires being created
- public static void createRSLatchExample(ViewModel model)
+ public static void createRSLatchExample(ViewModelModifiable model)
{
GUIManualSwitch rIn = new GUIManualSwitch(model);
rIn.moveTo(100, 100);
private final Runnable redrawListenerForSubcomponents;
- public ViewModel()
+ protected ViewModel()
{
components = new ArrayList<>();
componentsUnmodifiable = Collections.unmodifiableList(components);
* Adds the given component to the list of components and calls all componentAddedListeners. Don't call this method from application
* code as it is automatically called in GUIComponent::new.
*/
- public void componentCreated(GUIComponent component)
+ protected void componentCreated(GUIComponent component)
{
if (components.contains(component))
throw new IllegalStateException("Don't add the same component twice!");
* Removes the given component from the list of components and calls all componentRemovedListeners. Don't call this method from
* application code as it is automatically called in GUIComponent::destroy.
*/
- public void componentDestroyed(GUIComponent component)
+ protected void componentDestroyed(GUIComponent component)
{
if (!components.contains(component))
throw new IllegalStateException("Don't remove the same component twice!");
* Adds the given component to the list of components and calls all componentAddedListeners. Don't call this method from application
* code as it is automatically called in GUIComponent::new.
*/
- public void wireCreated(GUIWire wire)
+ protected void wireCreated(GUIWire wire)
{
if (wires.contains(wire))
throw new IllegalStateException("Don't add the same wire twice!");
* Removes the given component from the list of components and calls all componentRemovedListeners. Don't call this method from
* application code as it is automatically called in GUIComponent::destroy.
*/
- public void wireDestroyed(GUIWire wire)
+ protected void wireDestroyed(GUIWire wire)
{
if (!wires.contains(wire))
throw new IllegalStateException("Don't remove the same wire twice!");
return wiresUnmodifiable;
}
-// public void requestRedraw()
-// {
-// callRedrawListeners();
-// }
-
// @formatter:off
public void addComponentAddedListener (Consumer<? super GUIComponent> listener) {componentAddedListeners .add (listener);}
public void addComponentRemovedListener (Consumer<? super GUIComponent> listener) {componentRemovedListeners.add (listener);}
--- /dev/null
+package net.mograsim.logic.ui.model;
+
+import net.mograsim.logic.ui.model.components.GUIComponent;
+import net.mograsim.logic.ui.model.wires.GUIWire;
+
+public class ViewModelModifiable extends ViewModel
+{
+ @Override
+ public void componentCreated(GUIComponent component)
+ {
+ super.componentCreated(component);
+ }
+
+ @Override
+ public void componentDestroyed(GUIComponent component)
+ {
+ super.componentDestroyed(component);
+ }
+
+ @Override
+ public void wireCreated(GUIWire wire)
+ {
+ super.wireCreated(wire);
+ }
+
+ @Override
+ public void wireDestroyed(GUIWire wire)
+ {
+ super.wireDestroyed(wire);
+ }
+}
\ No newline at end of file
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.wires.Pin;
// TODO make a superclass
public final List<String> inputNames;
public final List<String> outputNames;
- public Am2901NANDBased(ViewModel model)
+ public Am2901NANDBased(ViewModelModifiable model)
{
super(model);
package net.mograsim.logic.ui.model.components;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
public class GUIAndGate extends SimpleRectangularGUIGate
{
- public GUIAndGate(ViewModel model, int logicWidth)
+ public GUIAndGate(ViewModelModifiable model, int logicWidth)
{
super(model, logicWidth, "&", false);
setInputCount(2);// TODO make variable
import net.mograsim.logic.core.LogicObserver;
import net.mograsim.logic.core.components.BitDisplay;
import net.mograsim.logic.core.types.BitVectorFormatter;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
import net.mograsim.logic.ui.model.wires.Pin;
public class GUIBitDisplay extends GUIComponent
private final LogicObserver logicObs;
private BitDisplay bitDisplay;
- public GUIBitDisplay(ViewModel model)
+ public GUIBitDisplay(ViewModelModifiable model)
{
super(model);
logicObs = (i) -> requestRedraw();
import java.util.List;
import java.util.function.Consumer;
-import net.mograsim.logic.ui.model.ViewModel;
-import net.mograsim.logic.ui.model.wires.Pin;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
+import net.mograsim.logic.ui.model.wires.Pin;
public abstract class GUIComponent
{
- protected final ViewModel model;
+ protected final ViewModelModifiable model;
private final Rectangle bounds;
private final List<Pin> pins;
protected final List<Pin> pinsUnmodifiable;
private final Runnable redrawListenerForSubcomponents;
- public GUIComponent(ViewModel model)
+ public GUIComponent(ViewModelModifiable model)
{
this.model = model;
this.bounds = new Rectangle(0, 0, 0, 0);
-package net.mograsim.logic.ui.model.components;\r
-\r
-import net.mograsim.logic.ui.model.ViewModel;\r
-import net.mograsim.logic.ui.model.wires.Pin;\r
-import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
-import net.haspamelodica.swt.helper.swtobjectwrappers.Font;\r
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;\r
-import net.mograsim.logic.core.LogicObservable;\r
-import net.mograsim.logic.core.LogicObserver;\r
-import net.mograsim.logic.core.components.ManualSwitch;\r
-import net.mograsim.logic.core.types.BitVectorFormatter;\r
-import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
-\r
-public class GUIManualSwitch extends GUIComponent\r
-{\r
- private static final double width = 20;\r
- private static final double height = 15;\r
- private static final double fontHeight = 5;\r
-\r
- private final Pin outputPin;\r
-\r
- private final LogicObserver logicObs;\r
- private ManualSwitch logicSwitch;\r
- private ReadEnd end;\r
-\r
- public GUIManualSwitch(ViewModel model)\r
- {\r
- super(model);\r
- logicObs = (i) -> requestRedraw();\r
-\r
- setSize(width, height);\r
- addPin(this.outputPin = new Pin(this, 1, width, height / 2));\r
- }\r
-\r
- @Override\r
- public void render(GeneralGC gc, Rectangle visibleRegion)\r
- {\r
- double posX = getBounds().x;\r
- double posY = getBounds().y;\r
-\r
- // TODO maybe draw switch state too?\r
- gc.drawRectangle(posX, posY, width, height);\r
- String label = BitVectorFormatter.formatValueAsString(end);\r
- Font oldFont = gc.getFont();\r
- Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());\r
- gc.setFont(labelFont);\r
- Point textExtent = gc.textExtent(label);\r
- gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true);\r
- gc.setFont(oldFont);\r
- }\r
-\r
- public void setLogicModelBinding(ManualSwitch logicSwitch, ReadEnd end)\r
- {\r
- deregisterLogicObs(this.end);\r
- deregisterLogicObs(this.logicSwitch);\r
- this.logicSwitch = logicSwitch;\r
- this.end = end;\r
- registerLogicObs(end);\r
- registerLogicObs(logicSwitch);\r
- }\r
-\r
- private void registerLogicObs(LogicObservable observable)\r
- {\r
- if (observable != null)\r
- observable.registerObserver(logicObs);\r
- }\r
-\r
- private void deregisterLogicObs(LogicObservable observable)\r
- {\r
- if (observable != null)\r
- observable.deregisterObserver(logicObs);\r
- }\r
-\r
- @Override\r
- public boolean clicked(double x, double y)\r
- {\r
- if (logicSwitch != null)\r
- logicSwitch.toggle();\r
- return true;\r
- }\r
-\r
- public Pin getOutputPin()\r
- {\r
- return outputPin;\r
- }\r
+package net.mograsim.logic.ui.model.components;
+
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.core.LogicObservable;
+import net.mograsim.logic.core.LogicObserver;
+import net.mograsim.logic.core.components.ManualSwitch;
+import net.mograsim.logic.core.types.BitVectorFormatter;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
+import net.mograsim.logic.ui.model.wires.Pin;
+
+public class GUIManualSwitch extends GUIComponent
+{
+ private static final double width = 20;
+ private static final double height = 15;
+ private static final double fontHeight = 5;
+
+ private final Pin outputPin;
+
+ private final LogicObserver logicObs;
+ private ManualSwitch logicSwitch;
+ private ReadEnd end;
+
+ public GUIManualSwitch(ViewModelModifiable model)
+ {
+ super(model);
+ logicObs = (i) -> requestRedraw();
+
+ setSize(width, height);
+ addPin(this.outputPin = new Pin(this, 1, width, height / 2));
+ }
+
+ @Override
+ public void render(GeneralGC gc, Rectangle visibleRegion)
+ {
+ double posX = getBounds().x;
+ double posY = getBounds().y;
+
+ // TODO maybe draw switch state too?
+ gc.drawRectangle(posX, posY, width, height);
+ String label = BitVectorFormatter.formatValueAsString(end);
+ Font oldFont = gc.getFont();
+ Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
+ gc.setFont(labelFont);
+ Point textExtent = gc.textExtent(label);
+ gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true);
+ gc.setFont(oldFont);
+ }
+
+ public void setLogicModelBinding(ManualSwitch logicSwitch, ReadEnd end)
+ {
+ deregisterLogicObs(this.end);
+ deregisterLogicObs(this.logicSwitch);
+ this.logicSwitch = logicSwitch;
+ this.end = end;
+ registerLogicObs(end);
+ registerLogicObs(logicSwitch);
+ }
+
+ private void registerLogicObs(LogicObservable observable)
+ {
+ if (observable != null)
+ observable.registerObserver(logicObs);
+ }
+
+ private void deregisterLogicObs(LogicObservable observable)
+ {
+ if (observable != null)
+ observable.deregisterObserver(logicObs);
+ }
+
+ @Override
+ public boolean clicked(double x, double y)
+ {
+ if (logicSwitch != null)
+ logicSwitch.toggle();
+ return true;
+ }
+
+ public Pin getOutputPin()
+ {
+ return outputPin;
+ }
}
\ No newline at end of file
package net.mograsim.logic.ui.model.components;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
public class GUINotGate extends SimpleRectangularGUIGate
{
- public GUINotGate(ViewModel model, int logicWidth)
+ public GUINotGate(ViewModelModifiable model, int logicWidth)
{
super(model, logicWidth, "1", true);
setInputCount(1);
package net.mograsim.logic.ui.model.components;
-import net.mograsim.logic.ui.model.ViewModel;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
public class GUIOrGate extends SimpleRectangularGUIGate
{
- public GUIOrGate(ViewModel model, int logicWidth)
+ public GUIOrGate(ViewModelModifiable model, int logicWidth)
{
super(model, logicWidth, "\u22651", false);// ">=1"
setInputCount(2);
import java.util.Collections;
import java.util.List;
-import net.mograsim.logic.ui.model.ViewModel;
-import net.mograsim.logic.ui.model.wires.MovablePin;
-import net.mograsim.logic.ui.model.wires.Pin;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
+import net.mograsim.logic.ui.model.wires.MovablePin;
+import net.mograsim.logic.ui.model.wires.Pin;
public class SimpleRectangularGUIGate extends GUIComponent
{
private final List<Pin> inputPins;
private final List<Pin> inputPinsUnmodifiable;
- protected SimpleRectangularGUIGate(ViewModel model, int logicWidth, String label, boolean isInverted)
+ protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted)
{
super(model);
this.label = label;
import net.mograsim.logic.core.types.BitVectorFormatter;\r
import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
import net.mograsim.logic.ui.ColorHelper;\r
-import net.mograsim.logic.ui.model.ViewModel;\r
+import net.mograsim.logic.ui.model.ViewModelModifiable;\r
\r
public class GUIWire\r
{\r
- private final ViewModel model;\r
+ private final ViewModelModifiable model;\r
public final int logicWidth;\r
private Pin pin1;\r
private Pin pin2;\r
private final LogicObserver logicObs;\r
private ReadEnd end;\r
\r
- public GUIWire(ViewModel model, Pin pin1, Pin pin2, Point... path)\r
+ public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path)\r
{\r
logicObs = (i) -> callRedrawListeners();\r
this.model = model;\r
import net.mograsim.logic.core.types.BitVectorFormatter;\r
import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
import net.mograsim.logic.ui.ColorHelper;\r
-import net.mograsim.logic.ui.model.ViewModel;\r
+import net.mograsim.logic.ui.model.ViewModelModifiable;\r
import net.mograsim.logic.ui.model.components.GUIComponent;\r
\r
public class WireCrossPoint extends GUIComponent\r
private final LogicObserver logicObs;\r
private ReadEnd end;\r
\r
- public WireCrossPoint(ViewModel model, int logicWidth)\r
+ public WireCrossPoint(ViewModelModifiable model, int logicWidth)\r
{\r
super(model);\r
logicObs = (i) -> requestRedraw();\r