Start a sketch in tweak mode
(Sketch sketch,
RunnerListener listener,
JavaEditor editor)
| 124 | |
| 125 | /** Start a sketch in tweak mode */ |
| 126 | public Runner handleTweak(Sketch sketch, |
| 127 | RunnerListener listener, |
| 128 | JavaEditor editor) throws SketchException { |
| 129 | // first try to build the unmodified code |
| 130 | JavaBuild build = new JavaBuild(sketch); |
| 131 | // String appletClassName = build.build(false); |
| 132 | String appletClassName = build.build(true); |
| 133 | if (appletClassName == null) { |
| 134 | // unmodified build failed, so fail |
| 135 | return null; |
| 136 | } |
| 137 | |
| 138 | // if compilation passed, modify the code and build again |
| 139 | // save the original sketch code of the user |
| 140 | editor.initBaseCode(); |
| 141 | // check for "// tweak" comment in the sketch |
| 142 | boolean requiresTweak = SketchParser.containsTweakComment(editor.baseCode); |
| 143 | // parse the saved sketch to get all (or only with "//tweak" comment) numbers |
| 144 | final SketchParser parser = new SketchParser(editor.baseCode, requiresTweak); |
| 145 | |
| 146 | // add our code to the sketch |
| 147 | final boolean launchInteractive = editor.automateSketch(sketch, parser); |
| 148 | |
| 149 | build = new JavaBuild(sketch); |
| 150 | appletClassName = build.build(false); |
| 151 | |
| 152 | if (appletClassName != null) { |
| 153 | final Runner runtime = new Runner(build, listener); |
| 154 | new Thread(() -> { |
| 155 | runtime.launch(null); |
| 156 | // next lines are executed when the sketch quits |
| 157 | if (launchInteractive) { |
| 158 | // fix swing deadlock issue: https://github.com/processing/processing/issues/3928 |
| 159 | EventQueue.invokeLater(() -> { |
| 160 | editor.initEditorCode(parser.allHandles); |
| 161 | editor.stopTweakMode(parser.allHandles); |
| 162 | }); |
| 163 | } |
| 164 | }).start(); |
| 165 | |
| 166 | if (launchInteractive) { |
| 167 | // fix swing deadlock issue: https://github.com/processing/processing/issues/3928 |
| 168 | EventQueue.invokeLater(() -> { |
| 169 | // replace editor code with baseCode |
| 170 | editor.initEditorCode(parser.allHandles); |
| 171 | editor.updateInterface(parser.allHandles, parser.colorBoxes); |
| 172 | editor.startTweakMode(); |
| 173 | }); |
| 174 | } |
| 175 | return runtime; |
| 176 | } |
| 177 | return null; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | public boolean handleExportApplication(Sketch sketch) throws SketchException, IOException { |
nothing calls this directly
no test coverage detected