41
41
import javafx .scene .layout .*;
42
42
import org .w3c .dom .events .EventTarget ;
43
43
import netscape .javascript .JSObject ;
44
+ import java .io .IOException ;
45
+ import java .net .UnknownHostException ;
44
46
import javafx .application .Platform ;
45
47
import javafx .scene .control .Control ;
46
48
import javafx .scene .input .Clipboard ;
@@ -64,6 +66,8 @@ public class WebTerminal extends VBox // FIXME should extend Control
64
66
{
65
67
public Backend backend ;
66
68
public void log (String str ) { WTDebug .println (str ); }
69
+
70
+ static DomHttpServer httpServer ;
67
71
68
72
WebView webView ;
69
73
protected WebView getWebView () { return webView ; }
@@ -172,6 +176,13 @@ public void setBackend(Backend backend) {
172
176
}
173
177
174
178
public WebTerminal (final Backend backend ) {
179
+ if (httpServer == null ) {
180
+ try {
181
+ startServer (0 );
182
+ } catch (Exception ex ) {
183
+ ex .printStackTrace ();
184
+ }
185
+ }
175
186
setBackend (backend );
176
187
webView = new WebView ();
177
188
webEngine = webView .getEngine ();
@@ -213,10 +224,7 @@ public void changed(ObservableValue<? extends State> ov, State t, State newValue
213
224
*/
214
225
protected String pageUrl () {
215
226
String rname = "jfx-term.html" ;
216
- java .net .URL rurl = Backend .class .getClassLoader ().getResource (rname );
217
- if (rurl == null )
218
- throw new RuntimeException ("no initial web page " +rname );
219
- return rurl .toString ();
227
+ return "http://localhost:" +httpServer .getPort ()+"/domterm/" +rname ;
220
228
}
221
229
222
230
/** Load the start page. Do not call directly.
@@ -266,4 +274,11 @@ public void run() {
266
274
267
275
268
276
}
277
+
278
+ public static void startServer (int port )
279
+ throws IOException , UnknownHostException {
280
+ DomHttpServer s = new DomHttpServer (port , new String [0 ]);
281
+ s .start ();
282
+ httpServer = s ;
283
+ }
269
284
}
0 commit comments