Libraryless. Click here for Pure Java version (30734L/196K).
1 | srecord noeq JGazelleVScriptRunner(SimpleLiveValue<S> lvScript) { |
2 | GazelleVScript parsedScript; |
3 | GazelleVScript.Run run; |
4 | O result; |
5 | SingleComponentPanel scpScriptResult = singleComponentPanel(); |
6 | new WeakVar<ImageSurface> isScriptResult; |
7 | new WeakVar<JTextArea> taResult; |
8 | JLabel lblScore = jlabel(); |
9 | |
10 | JComponent scriptAndResultPanel() { |
11 | ret northAndCenter( |
12 | scriptInputField(), |
13 | scpScriptResult = singleComponentPanel() |
14 | ); |
15 | } |
16 | |
17 | JComponent scriptInputField() { |
18 | ret withMargin(centerAndEastWithMargin( |
19 | withLabel("Gazelle \"Linear\" Script:", jLiveTextField(lvScript)), |
20 | jPopDownButton_noText( |
21 | "Show Scripting Help", rThread { showText("Gazelle 'Linear Script' Help", GazelleVScript.helpText) }) |
22 | )); |
23 | } |
24 | |
25 | void showScriptOutput { |
26 | if (result cast BWImage) { |
27 | showImageResult(result); |
28 | } else if (result cast BufferedImage) { |
29 | showImageResult(result); |
30 | } else if (result cast Animation) { |
31 | showImageResult(result.toImage()); |
32 | } else { |
33 | showTextResult(str(result)); |
34 | } |
35 | } |
36 | |
37 | void showTextResult(S text) { |
38 | text = shorten(1000, text); |
39 | |
40 | if (isShowing(taResult!)) { |
41 | setTextKeepCaret(taResult!, text); |
42 | } else { |
43 | var ta = jTextArea_noUndo(text); |
44 | scpScriptResult.set(jscroll(ta)); |
45 | taResult.set(ta); |
46 | } |
47 | } |
48 | |
49 | void showImageResult(BufferedImage etc img) { |
50 | if (img == null) ret; |
51 | if (isShowing(isScriptResult!)) { |
52 | isScriptResult->setImage(img); |
53 | } else { |
54 | var is = stdImageSurface(); |
55 | is.setImage(img); |
56 | scpScriptResult.set(jscroll_centered(is)); |
57 | isScriptResult.set(is); |
58 | } |
59 | |
60 | if (isShowing(lblScore)) { |
61 | S score = ""; |
62 | if (sameSize(run.inputImage, img)) { |
63 | double distance = bwDistance(toBWImage(run.inputImage), toBWImage(img)); |
64 | score = "Score: " + formatDoubleX(100*(1-distance), 1); |
65 | } |
66 | setText(lblScore, score); |
67 | } |
68 | } |
69 | |
70 | ImageSurface stdImageSurface() { |
71 | ret pixelatedImageSurface().setAutoZoomToDisplay(true).repaintInThread(false); |
72 | } |
73 | |
74 | void parse { |
75 | parsedScript = new GazelleVScript(lvScript!); |
76 | } |
77 | |
78 | void runOn(IBWIntegralImage ii) { |
79 | run = parsedScript.new Run(); |
80 | run.setInputImage(ii); |
81 | run.setIntegralImage(ii); |
82 | run.run(); |
83 | result = run.result(); |
84 | } |
85 | |
86 | void parseAndRunOn(IBWIntegralImage ii) { |
87 | try { |
88 | parse(); |
89 | runOn(ii); |
90 | } catch e { |
91 | result = exceptionToStringShort(e); |
92 | printStackTrace(e); |
93 | } |
94 | showScriptOutput(); |
95 | } |
96 | } |
Began life as a copy of #1033717
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033725 |
Snippet name: | JGazelleVScriptRunner |
Eternal ID of this version: | #1033725/31 |
Text MD5: | c614a6d60be67ea62aa273a8de2bd419 |
Transpilation MD5: | 76e3947a92792048bfce72abfda534e0 |
Author: | stefan |
Category: | javax / gazelle v |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-18 15:37:12 |
Source code size: | 2611 bytes / 96 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 220 / 439 |
Version history: | 30 change(s) |
Referenced in: | [show references] |