-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove Diff0 and Diff1, use FileDiffRootView instead, fix tests
- Loading branch information
Showing
18 changed files
with
264 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 56 additions & 4 deletions
60
demo-edit-es-module/src/main/java/org/sudu/experiments/JsLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,79 @@ | ||
package org.sudu.experiments; | ||
|
||
import org.sudu.experiments.esm.EditArgs; | ||
import org.sudu.experiments.esm.JsBaseControl; | ||
import org.sudu.experiments.fonts.FontConfigJs; | ||
import org.sudu.experiments.fonts.FontDesk; | ||
import org.sudu.experiments.fonts.Fonts; | ||
import org.sudu.experiments.js.*; | ||
import org.sudu.experiments.math.ArrayOp; | ||
import org.teavm.jso.JSObject; | ||
import org.teavm.jso.core.JSString; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
public abstract class JsLauncher { | ||
|
||
boolean fontsLoaded; | ||
private JsArray<WebWorkerContext> workers; | ||
|
||
public JsLauncher(boolean waitFonts) { | ||
JsLauncher(boolean waitFonts) { | ||
fontsLoaded = !waitFonts; | ||
} | ||
|
||
public void onWorkersStart(JsArray<WebWorkerContext> workers) { | ||
void onWorkersStart(JsArray<WebWorkerContext> workers) { | ||
this.workers = workers; | ||
if (fontsLoaded) launch(workers); | ||
} | ||
|
||
public void onFontsLoaded(JsArrayReader<JSObject> fontFaces) { | ||
void onFontsLoaded(JsArrayReader<JSObject> fontFaces) { | ||
FontFace.addToDocument(fontFaces); | ||
fontsLoaded = true; | ||
if (workers != null) launch(workers); | ||
} | ||
|
||
public abstract void launch(JsArray<WebWorkerContext> workers); | ||
abstract void launch(JsArray<WebWorkerContext> workers); | ||
|
||
public static <T extends JsBaseControl> Promise<T> start( | ||
EditArgs arguments, | ||
Function<SceneApi, Scene> sf, | ||
BiFunction<WebWindow, EditArgs, T> rf | ||
) { | ||
if (!JsCanvas.checkFontMetricsAPI()) | ||
return Promise.reject(FireFoxWarning.message); | ||
|
||
return Promise.create((postResult, postError) -> { | ||
boolean loadCodicon = arguments.hasCodiconUrl(); | ||
var l = new JsLauncher(loadCodicon) { | ||
@Override | ||
public void launch(JsArray<WebWorkerContext> workers) { | ||
var w = new WebWindow(arguments.getContainerId(), workers); | ||
if (w.init(sf)) { | ||
postResult.f(rf.apply(w, arguments)); | ||
} else { | ||
postError.f(JSString.valueOf(WebGLError.text)); | ||
} | ||
} | ||
}; | ||
|
||
if (loadCodicon) { | ||
var url = arguments.getCodiconUrl().stringValue(); | ||
FontFace.loadFonts(codiconFontConfig(url)) | ||
.then(l::onFontsLoaded, | ||
e -> postError.f(e.cast())); | ||
} | ||
WebWorkerContext.start( | ||
l::onWorkersStart, | ||
postError, | ||
arguments.workerUrl(), | ||
arguments.numWorkerThreads()); | ||
}); | ||
} | ||
|
||
static FontConfigJs[] codiconFontConfig(String filename) { | ||
return ArrayOp.array( | ||
new FontConfigJs(Fonts.codicon, filename, | ||
FontDesk.NORMAL, FontDesk.WEIGHT_REGULAR)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.