Completely changed the structure and switched to Eclipse Plugin.
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / SimpleRectangularSubmodelComponent.java
index 0c0bf30..04a6fcc 100644 (file)
@@ -12,7 +12,9 @@ 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.ModelVisitor;
 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 SimpleRectangularSubmodelComponent extends SubmodelComponent
@@ -69,7 +71,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
                        String pinName = newPinNames[i];
                        int oldPinIndex = pinNamesListThisSide.indexOf(pinName);
                        if (oldPinIndex == -1)
-                               super.addSubmodelInterface(pinName, logicWidth, relX, pinDistance / 2 + i * pinDistance);
+                               super.addSubmodelInterface(new MovablePin(this, pinName, logicWidth, relX, pinDistance / 2 + i * pinDistance));
                        else
                                getSupermodelMovablePin(pinName).setRelPos(relX, pinDistance / 2 + i * pinDistance);
                }
@@ -93,26 +95,23 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
        @Override
        protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion)
        {
-               double posX = getBounds().x;
-               double posY = getBounds().y;
-
                Font oldFont = gc.getFont();
                gc.setFont(new Font(oldFont.getName(), labelFontHeight, oldFont.getStyle()));
                Point textExtent = gc.textExtent(label);
-               gc.drawText(label, posX + (getBounds().width - textExtent.x) / 2, posY + (getBounds().height - textExtent.y) / 2, true);
+               gc.drawText(label, getPosX() + (getWidth() - textExtent.x) / 2, getPosY() + (getHeight() - textExtent.y) / 2, true);
                gc.setFont(new Font(oldFont.getName(), pinNameFontHeight, oldFont.getStyle()));
                for (int i = 0; i < inputPinNames.size(); i++)
                {
                        String pinName = inputPinNames.get(i);
                        textExtent = gc.textExtent(pinName);
-                       gc.drawText(pinName, posX + pinNameMargin, posY + i * pinDistance + (pinDistance - textExtent.y) / 2, true);
+                       gc.drawText(pinName, getPosX() + pinNameMargin, getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, true);
                }
                for (int i = 0; i < outputPinNames.size(); i++)
                {
                        String pinName = outputPinNames.get(i);
                        textExtent = gc.textExtent(pinName);
-                       gc.drawText(pinName, posX + width - textExtent.x - pinNameMargin, posY + i * pinDistance + (pinDistance - textExtent.y) / 2,
-                                       true);
+                       gc.drawText(pinName, getPosX() + width - textExtent.x - pinNameMargin,
+                                       getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, true);
                }
                gc.setFont(oldFont);
        }
@@ -138,7 +137,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
        }
 
        @Override
-       protected Pin addSubmodelInterface(String name, int logicWidth, double relX, double relY)
+       protected Pin addSubmodelInterface(MovablePin supermodelPin)
        {
                throw new UnsupportedOperationException(
                                "Can't add submodel interfaces to a SimpleRectangularSubmodelComponent directly, call setInputPins / setOutputPins instead");
@@ -157,4 +156,10 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
                throw new UnsupportedOperationException(
                                "Can't set the size of a SimpleRectangularSubmodelComponent directly, call setInputPins / setOutputPins instead");
        }
+
+       @Override
+       public void accept(ModelVisitor mv)
+       {
+               mv.visit(this);
+       }
 }
\ No newline at end of file