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 final HandleManager manager;
15 private boolean selected = false;
16 public final GUIWire parent;
18 private int pointIndex;
20 public WirePointHandle(HandleManager manager, GUIWire parent, int pointIndex)
23 this.manager = manager;
25 this.pointIndex = pointIndex;
26 setSize(END_OFFSET, END_OFFSET);
27 Point pathPoint = parent.getPathPoint(pointIndex);
28 moveTo(pathPoint.x, pathPoint.y);
33 Point p = parent.getPathPoint(pointIndex);
38 public void render(GeneralGC gc)
41 gc.setForeground(Display.getDefault().getSystemColor(selected ? SWT.COLOR_YELLOW : SWT.COLOR_BLUE));
42 gc.drawLine(getPosX(), getPosY(), getPosX() + END_OFFSET, getPosY() + END_OFFSET);
46 public void reqMove(double x, double y)
48 parent.setPathPoint(new Point(x, y), pointIndex);
52 public void onSelect()
55 callRedrawListeners();
59 public void onDeselect()
62 callRedrawListeners();
66 public void reqDelete()
68 manager.destroyWirePointHandle(parent, this);
72 public HandleType getType()
74 return HandleType.WIRE_POINT;
78 * Sets the index of the {@link Point} within the parent {@link Wire}s path that is controlled by this handle
79 * @param index Index of the Point in the Wires path.
80 * @throws IndexOutOfBoundsException
82 public void setIndex(int index)
84 this.pointIndex = index;