A small text height box in JS that refers to a box on the canvas, with a factory system for them.
| 29 | /** |
| 30 | * A small text height box in JS that refers to a box on the canvas, with a factory system for them. |
| 31 | */ |
| 32 | public class Taps extends Box implements IO.Loaded { |
| 33 | |
| 34 | static public final Dict.Prop<BiFunctionOfBoxAnd<String, Box /*Function<Object, Object>*/>> tap = new Dict.Prop<>( |
| 35 | "tap").type() |
| 36 | .toCanon(); //doc! |
| 37 | static public final Dict.Prop<Binding> tapBinding = new Dict.Prop<>("tapBinding").type() |
| 38 | .toCanon(); //doc! |
| 39 | |
| 40 | // used by interventions |
| 41 | |
| 42 | static public final Dict.Prop<Function<Double, Double>> evalInterpolation = new Dict.Prop<Function<Double, Double>>("evalInterpolation").toCanon().type(); |
| 43 | |
| 44 | |
| 45 | |
| 46 | boolean selectionHasChanged = false; |
| 47 | Box selectionWas = null; |
| 48 | boolean editorLoaded = false; |
| 49 | HashMap<String, Runnable> queue = new LinkedHashMap<>(); |
| 50 | HashMap<String, Runnable> onActiveSet = new LinkedHashMap<>(); |
| 51 | |
| 52 | public Taps(Box root) { |
| 53 | |
| 54 | } |
| 55 | |
| 56 | public void loaded() { |
| 57 | properties.put(tap, (x, name) -> { |
| 58 | |
| 59 | String kind = name.substring(0, name.lastIndexOf(":")); |
| 60 | |
| 61 | Box c; |
| 62 | |
| 63 | if (kind.equalsIgnoreCase("PAD")) |
| 64 | c = Pads.padFactory(x, kind, name); |
| 65 | else |
| 66 | c = x.first(Templates.ensureChildTemplated) |
| 67 | .get() |
| 68 | .apply(x, "tap-" + kind, name); |
| 69 | |
| 70 | if (c == null) // no template or child found, just make a box |
| 71 | { |
| 72 | c = x.first(DefaultMenus.newBox).get().apply(x); |
| 73 | c.properties.put(Box.name, name); |
| 74 | } |
| 75 | |
| 76 | // do something with 'c' -> function |
| 77 | |
| 78 | Binding bindingwWas = c.properties.get(tapBinding); |
| 79 | if (bindingwWas == null) { |
| 80 | Binding binding = new Binding(c, x, name); |
| 81 | Optional<RemoteEditor> first = this.first(RemoteEditor.editor, both()); |
| 82 | if (first.isPresent()) { |
| 83 | binding.server = first.get() |
| 84 | .getServer(); |
| 85 | binding.lastSocket = Server.currentWebSocket.get(); |
| 86 | } |
| 87 | c.properties.put(tapBinding, binding); |
| 88 | x.first(Chorder.begin).get().apply(c); |