X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fwires%2FPin.java;h=b761c0e7912133cb951b97246bf3628062b0c4a9;hb=a4d1573c2f2cf8236bcb56dc70bc8b8c60b6c225;hp=aec2df0816f33cf81aa01d6838101e9ac65fcb5b;hpb=b37ba7609a925cc945bbac0f6ead619d07912238;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java index aec2df08..b761c0e7 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java @@ -7,18 +7,48 @@ import java.util.function.Consumer; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.mograsim.logic.ui.model.components.GUIComponent; -public class Pin +/** + * A connection interface between a GUIComponent and the rest of a ViewModel. Pins usually are created by {@link GUIComponent}s themselves. + *
+ * A pin has a name identifying it. Pin names are unique for a {@link GUIComponent}: Every pin of a {@link GUIComponent} has a different + * name, but different {@link GUIComponent}s can have pins with the same name. + * + * @author Daniel Kirschten + */ +public class Pin implements ConnectionPoint { + /** + * The {@link GUIComponent} this pin belongs to + */ public final GUIComponent component; + /** + * The name identifying this pin. Is unique for a {@link GUIComponent}. + */ public final String name; + /** + * The logical width of this pin. Denotes how many bits this pin consists of. + */ public final int logicWidth; + /** + * The X position of this pin, relative to its component's location. + */ protected double relX; + /** + * The Y position of this pin, relative to its component's location. + */ protected double relY; private final List> pinMovedListeners; private final List redrawListeners; + // creation and destruction + + /** + * Creates a new pin. Usually it is not needed to call this constructor manually, as {@link GUIComponent}s create their pins themselves. + * + * @author Daniel Kirschten + */ public Pin(GUIComponent component, String name, int logicWidth, double relX, double relY) { this.component = component; @@ -33,26 +63,53 @@ public class Pin component.addComponentMovedListener(c -> callPinMovedListeners()); } + // "graphical" operations + + /** + * Returns the X position of this pin relative to the position of its component. + * + * @author Daniel Kirschten + */ public double getRelX() { return relX; } + /** + * Returns the Y position of this pin relative to the position of its component. + * + * @author Daniel Kirschten + */ public double getRelY() { return relY; } + /** + * Returns the position of this pin relative to the position of its component. + * + * @author Daniel Kirschten + */ public Point getRelPos() { return new Point(relX, relY); } + /** + * Returns the absolute position of this pin. + * + * @author Daniel Kirschten + */ public Point getPos() { return new Point(relX + component.getPosX(), relY + component.getPosY()); } + /** + * Sets the position of this pin relative to the position of its component. + * + * @author Daniel Kirschten + */ protected void setRelPos(double relX, double relY) { this.relX = relX; @@ -61,6 +118,8 @@ public class Pin callRedrawListeners(); } + // listeners + // @formatter:off public void addPinMovedListener (Consumer listener){pinMovedListeners.add (listener);} public void addRedrawListener (Runnable listener){redrawListeners .add (listener);} @@ -77,4 +136,10 @@ public class Pin { return "Pin [" + name + ", point=" + getPos() + "]"; } + + @Override + public Pin getPin() + { + return this; + } } \ No newline at end of file