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.core.wires.Wire;
9 import net.mograsim.logic.model.model.wires.GUIWire;
11 public class WirePointHandle extends Handle
13 private final static int END_OFFSET = 4;
14 private boolean selected = false;
15 public final GUIWire parent;
17 private int pointIndex;
19 public WirePointHandle(GUIWire parent, int pointIndex)
23 this.pointIndex = pointIndex;
24 setSize(END_OFFSET, END_OFFSET);
25 Point pathPoint = parent.getPathPoint(pointIndex);
26 moveTo(pathPoint.x, pathPoint.y);
31 Point p = parent.getPathPoint(pointIndex);
36 public void render(GeneralGC gc)
39 gc.setForeground(Display.getDefault().getSystemColor(selected ? SWT.COLOR_YELLOW : SWT.COLOR_BLUE));
40 gc.drawLine(getPosX(), getPosY(), getPosX() + END_OFFSET, getPosY() + END_OFFSET);
44 public void reqMove(double x, double y)
46 parent.setPathPoint(new Point(x, y), pointIndex);
50 public void onSelect()
53 callRedrawListeners();
57 public void onDeselect()
60 callRedrawListeners();
64 public void reqDelete()
66 parent.removePathPoint(pointIndex);
70 public HandleType getType()
72 return HandleType.WIRE_POINT;
76 * Sets the index of the {@link Point} within the parent {@link Wire}s path that is controlled by this handle
77 * @param index Index of the Point in the Wires path.
78 * @throws IndexOutOfBoundsException
80 public void setIndex(int index)
82 this.pointIndex = index;