0f4a1524ff8835d2dd657f162d88005388b92df0
[Mograsim.git] /
1 package net.mograsim.logic.model.editor.handles;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Display;
5
6 import net.haspamelodica.swt.helper.gcs.GeneralGC;
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
8 import net.mograsim.logic.model.model.wires.Pin;
9
10 public class StaticPinHandle extends PinHandle
11 {
12         private final static int CIRCLE_DIAM = 2;
13         private final static int CIRCLE_RADIUS = 1;
14         private final Pin parent;
15
16         public StaticPinHandle(Pin parent)
17         {
18                 super(1);
19                 this.parent = parent;
20                 setSize(CIRCLE_DIAM, CIRCLE_DIAM);
21                 parent.addPinMovedListener((p) -> updatePos());
22                 updatePos();
23         }
24
25         @Override
26         protected void render(GeneralGC gc)
27         {
28                 gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
29                 gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM);
30         }
31
32         private void updatePos()
33         {
34                 Point pos = parent.getPos();
35                 moveTo(pos.x - CIRCLE_RADIUS, pos.y - CIRCLE_RADIUS);
36         }
37
38         @Override
39         public double getCenterX()
40         {
41                 return getPosX() + CIRCLE_RADIUS;
42         }
43
44         @Override
45         public double getCenterY()
46         {
47                 return getPosY() + CIRCLE_RADIUS;
48         }
49
50         @Override
51         public HandleType getType()
52         {
53                 return HandleType.STATIC_PIN;
54         }
55
56         @Override
57         public Pin getPin()
58         {
59                 return parent;
60         }
61 }