| 20 | } |
| 21 | |
| 22 | public Create(Box root) { |
| 23 | this.properties.put(_new, (box, tag, clazz) -> { |
| 24 | |
| 25 | Optional<Box> o = box.children() |
| 26 | .stream() |
| 27 | .filter(x -> isTagged(x, tag)) |
| 28 | .findAny(); |
| 29 | |
| 30 | if (o.isPresent()) return o.get(); |
| 31 | |
| 32 | try { |
| 33 | Box c = (Box) (clazz == null ? Box.class : clazz).newInstance(); |
| 34 | |
| 35 | c.properties.put(Box.name, tag); |
| 36 | Rect parent = box.properties.get(Box.frame); |
| 37 | |
| 38 | c.properties.put(Box.frame, new Rect(parent.x + parent.w - 10, parent.y + parent.h - 10, parent.w, parent.h)); |
| 39 | c.properties.put(Create.tag, tag); |
| 40 | box.connect(c); |
| 41 | if (c instanceof IO.Loaded) ((IO.Loaded) c).loaded(); |
| 42 | |
| 43 | return c; |
| 44 | } catch (InstantiationException | IllegalAccessException e) { |
| 45 | e.printStackTrace(); |
| 46 | } |
| 47 | return null; |
| 48 | |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | protected boolean isTagged(Box b, String tag) { |
| 53 | if (!b.properties.has(Create.tag)) return false; |