| 27 | public class Pads extends Box implements Mouse.OnMouseDown, IO.Loaded { |
| 28 | |
| 29 | static String code_padFactory = BoxDefaultCode.findSource(Pads.class, "padFactory"); |
| 30 | |
| 31 | static public final Dict.Prop<FunctionOfBoxValued<BoxChildHelper>> padOutward = new Dict.Prop<FunctionOfBoxValued<BoxChildHelper>>("padOutward").doc("a collection of boxes that are the outward connections to this box") |
| 32 | .toCanon() |
| 33 | .type(); |
| 34 | static public final Dict.Prop<FunctionOfBoxValued<BoxChildHelper>> padInward = new Dict.Prop<FunctionOfBoxValued<BoxChildHelper>>("padInward").doc("a collection of boxes that are the inward connections to this box") |
| 35 | .toCanon() |
| 36 | .type(); |
| 37 | |
| 38 | |
| 39 | static public final Dict.Prop<Boolean> isPad = new Dict.Prop<>("_isPad").type() |
| 40 | .toCanon(); |
| 41 | private final Box root; |
| 42 | |
| 43 | public Pads(Box root) |
| 44 | { |
| 45 | this.root = root; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void loaded() { |
| 50 | this.properties.put(Planes.plane, "__always__"); |
| 51 | this.properties.putToMap(Mouse.onMouseDown, "__pads__", this); |
| 52 | |
| 53 | root.properties.put(padOutward, (box) -> new BoxChildHelper(box.children() |
| 54 | .stream() |
| 55 | .filter(x -> x.properties.has(TopologyBox.head)) |
| 56 | .filter(x -> x.properties.get(TopologyBox.head) |
| 57 | .get(root) == box) |
| 58 | .map(x -> x.properties.get(TopologyBox.tail) |
| 59 | .get(root)) |
| 60 | .collect(Collectors.toCollection(() -> new LinkedHashSet<>())))); |
| 61 | root.properties.put(padInward, (box) -> new BoxChildHelper(box.children() |
| 62 | .stream() |
| 63 | .filter(x -> x.properties.has(TopologyBox.tail)) |
| 64 | .filter(x -> x.properties.get(TopologyBox.tail) |
| 65 | .get(root) == box) |
| 66 | .map(x -> x.properties.get(TopologyBox.head) |
| 67 | .get(root)) |
| 68 | .collect(Collectors.toCollection(() -> new LinkedHashSet<>())))); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | public static Box padFactory(Box parent, String kind, String name) { |
| 73 | |
| 74 | Box c = parent.first(DefaultMenus.ensureChildOfClass) |
| 75 | .get() |
| 76 | .apply(parent, name, SimpleCanvas.class); |
| 77 | |
| 78 | if (c.properties.isTrue(DefaultMenus.wasNew, false)) { |
| 79 | c.properties.put(Execution.code, code_padFactory); |
| 80 | |
| 81 | parent.find(Boxes.root, parent.upwards()).findFirst().map( r -> r.disconnect(c)); |
| 82 | } |
| 83 | |
| 84 | c.properties.put(DragToCopy._ownedByParent, true); |
| 85 | |
| 86 | return c; |
nothing calls this directly
no test coverage detected