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

Class OutputBox

src/main/java/fieldcef/plugins/OutputBox.kt:33–253  ·  view source on GitHub ↗

* An OutputBox is a box that just lets you print html to it. This is a plugin that lets you make them. */

Source from the content-addressed store, hash-verified

31import java.io.IOException
32import java.util.*
33import java.util.function.BiFunction
34import java.util.function.Consumer
35import java.util.stream.Stream
36
37/**
38 * An OutputBox is a box that just lets you print html to it. This is a plugin that lets you make them.
39 */
40class OutputBox(private val root: Box) : Box(), Loaded {
41 var out: Out? = null
42 var playlist = Arrays.asList("preamble.js", "jquery-2.1.0.min.js", "jquery.autosize.input.js", "modal.js")
43 var styleSheet = "field-codemirror.css"
44 var styles: String? = null
45 private fun toHTML(param: Any): String {
46 return if (out == null) "" + param else out!!.convert(param)
47 }
48
49 var tick = 0
50 override fun loaded() {
51 out = find(Out.__out, both()).findAny().orElseGet { null }
52 }
53
54 protected fun make(w: Int, h: Int, b: Box): Browser {
55 Log.log("OutputBox.debug") { "initializing browser" }
56 val browser = find(Templates.templateChild, both()).findFirst()
57 .map { x: BiFunctionOfBoxAnd<String, Box> -> x.apply(b, "html output") }
58 .orElseGet { Browser() } as Browser
59 val f = b.properties.get(frame)
60 val inset = 10f
61 browser.properties.put(
62 frame,
63 Rect((f.x + f.w - inset).toDouble(), (f.y + f.h - inset).toDouble(), w.toDouble(), h.toDouble())
64 )
65 browser.properties.put(Boxes.dontSave, true)
66 b.connect(browser)
67 browser.loaded()
68 properties.put(Boxes.dontSave, true)
69 browser.properties.put(name, "outputbox")
70 styles = findAndLoad(styleSheet, false)
71 val t = longArrayOf(0)
72 boot(browser)
73 browser.pauseForBoot()
74 val ed: TextEditorExecution = TextEditorExecution(browser)
75 ed.connect(browser)
76 return browser
77 }
78
79 var postamble = "</body></html>"
80 fun boot(browser: Browser) {
81 val s = this.find(ServerSupport.server, both())
82 .findFirst()
83 .orElseThrow { IllegalArgumentException(" Server not found ") }
84 val bootstrap =
85 "<html class='outputbox' style='background:rgba(0,0,0,0.2);padding:8px;'><head><style>$styles</style></head><body class='outputbox' style='background:rgba(0,0,0,0.02);'>$postamble"
86 val res = UUID.randomUUID()
87 .toString()
88 s.setFixedResource("/$res", bootstrap)
89 browser.properties.put(Browser.url, "http://localhost:" + s.port + "/" + res)
90 tick = 0

Callers

nothing calls this directly

Calls 11

FunctionOfBoxValuedInterface · 0.85
TemplateMapClass · 0.85
makeFunction · 0.85
asListMethod · 0.80
toCanonMethod · 0.80
docMethod · 0.80
PropMethod · 0.80
asMap_getMethod · 0.65
putMethod · 0.45
makeCallableMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected