MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Create

Method Create

src/main/java/fieldbox/boxes/plugins/Create.java:22–50  ·  view source on GitHub ↗
(Box root)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 8

isTaggedMethod · 0.95
childrenMethod · 0.80
isPresentMethod · 0.80
getMethod · 0.65
loadedMethod · 0.65
putMethod · 0.45
streamMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected