1 package net.mograsim.logic.model.editor.handles;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Display;
6 import net.haspamelodica.swt.helper.gcs.GeneralGC;
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
8 import net.mograsim.logic.model.model.wires.MovablePin;
9 import net.mograsim.logic.model.model.wires.Pin;
10 import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent;
12 public class InterfacePinHandle extends PinHandle
14 private final static int CIRCLE_DIAM = 4, CIRCLE_RADIUS = CIRCLE_DIAM / 2, SELECTED_CIRCLE_OFFSET = 1,
15 SELECTED_CIRCLE_DIAM = SELECTED_CIRCLE_OFFSET * 2 + CIRCLE_DIAM;
16 private final MovablePin parent;
17 private final DeserializedSubmodelComponent owner;
18 private boolean selected = false;
20 public InterfacePinHandle(MovablePin parent, DeserializedSubmodelComponent pinOwner)
24 this.owner = pinOwner;
25 setSize(CIRCLE_DIAM, CIRCLE_DIAM);
29 private void initPos()
31 Point pos = parent.getPos();
32 moveTo(pos.x - CIRCLE_RADIUS, pos.y - CIRCLE_RADIUS);
36 protected void render(GeneralGC gc)
38 double x = getPosX(), y = getPosY();
40 gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
41 gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
42 gc.drawText(parent.name, x + CIRCLE_DIAM, y + CIRCLE_DIAM, true);
45 gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
46 gc.drawOval(x - SELECTED_CIRCLE_OFFSET, y - SELECTED_CIRCLE_OFFSET, SELECTED_CIRCLE_DIAM,
47 SELECTED_CIRCLE_DIAM);
49 gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
50 gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM);
54 public void reqMove(double x, double y)
60 public void onSelect()
63 callRedrawListeners();
67 public void onDeselect()
70 callRedrawListeners();
74 public void reqDelete()
76 owner.removeSubmodelInterface(parent.name);
80 protected void moveTo(double x, double y)
83 parent.setRelPos(getCenterX(), getCenterY());
87 public double getCenterX()
89 return getPosX() + CIRCLE_RADIUS;
93 public double getCenterY()
95 return getPosY() + CIRCLE_RADIUS;
99 public HandleType getType()
101 return HandleType.INTERFACE_PIN;