The existing HTML elements are given here under H:
https://developer.mozilla.org/de/docs/Web/API
The available JAVA API classes are shown here:
https://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/Element.html
Unfortunately the org.w3c.dom package misses some more specific elements like HTMLCanvasElement.
I am looking for some more advanced Java API that at least supports the HTMLCanvasElements (full WEP API support would be great).
What I found so far:
A. For the Project javafx-d3 I use the JavaFx WebView to control some JavaScript in Java. The communication between Java and JavaScript is based on netscape.javascript.JSObject and works fine in principle:
I am able to cast a JSObject that I got from the JavaScript world to an org.w3c.dom.Element ... and use its Java methods to manipulate the DOM.
If I want to "go deeper", e.g. control a HTMLCanvasElement, I have to write my own wrappers based on JSObject. That is possible but feels like reinventing the wheel.
B. Google GWT seems to provide some wrapper Classes, e.g.
com.google.gwt.dom.client.CanvasElement for HTMLCanvasElement
However I did not manage to convert netscape.javascript.JSObject to the GWT wrapper classes (starting from com.google.gwt.core.client.JavaScriptObject) .
If this is possible at all, could someone provide an example?
Anybody knows how to get that dummy example below running?
package main;
import elemental.client.Browser;
import elemental.html.AudioContext;
import elemental.html.AudioParam;
import elemental.html.Oscillator;
import elemental.html.Window;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class GwtElementDemo extends Application {
private Scene scene;
private Region browser;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
//set state title
stage.setTitle("JavaFx demo");
browser = new Region();
Window window = Browser.getWindow();
AudioContext audioContext = window.newAudioContext();
Oscillator osc = audioContext.createOscillator();
osc.setType(Oscillator.SQUARE);
osc.connect((AudioParam) audioContext.getDestination(), 0);
osc.getFrequency().setValue(440.0f);
osc.noteOn(0);
//create the scene
scene = new Scene(browser, 750, 500, Color.web("#666970"));
stage.setScene(scene);
stage.show();
}
}
maven dependency for GWT elemental:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-elemental</artifactId>
<version>2.8.0</version>
</dependency>
Or do you know an alternative/advanced JAVA API for DOM manipulation (that is build on the JSObject hierarchy)?