1 package era.mi.gui.model.components;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import era.mi.gui.model.ViewModel;
8 import era.mi.gui.model.wires.Pin;
9 import net.haspamelodica.swt.helper.gcs.GeneralGC;
10 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
12 public abstract class GUIComponent
14 protected final ViewModel model;
15 private final Rectangle bounds;
16 private final List<Pin> pins;
17 protected final List<Pin> pinsUnmodifiable;
19 public GUIComponent(ViewModel model)
22 this.bounds = new Rectangle(0, 0, 0, 0);
23 this.pins = new ArrayList<>();
24 this.pinsUnmodifiable = Collections.unmodifiableList(pins);
27 public void moveTo(double x, double y)
34 * Returns the bounds of this component. Used for calculating which component is clicked.
36 public Rectangle getBounds()
38 return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
43 * Called when this component is clicked. Relative coordinates of the click are given. Returns true if this component has to be redrawn.
45 public boolean clicked(double x, double y)
51 * Returns a list of pins of this component.
53 public List<Pin> getPins()
55 return pinsUnmodifiable;
59 * Render this component to the given gc.
61 public abstract void render(GeneralGC gc, Rectangle visibleRegion);
63 protected void setSize(double width, double height)
66 bounds.height = height;
69 protected void addPin(Pin pin)
70 {// TODO notify pins they are "created"
74 protected void removePin(Pin pin)
75 {// TODO notify pins they are "destroyed"