JaroslavTulach at 01:16, 30 October 2014 - 2014-10-30 01:16:21

←Older revision Revision as of 01:16, 30 October 2014
Line 6: Line 6:
public static void onPageLoad() throws Exception {
public static void onPageLoad() throws Exception {
URL u = Main.class.getResource("yourimg.png");
URL u = Main.class.getResource("yourimg.png");
 +
// one can use u.openStream() to do 'lightweight' read from Java code
-
// by opening the connection one requests creation of Blob
+
// by opening the connection one requests creation of browser Blob
URLConnection conn = u.openConnection();
URLConnection conn = u.openConnection();
-
// the conn.getURL() may actually differ from u
+
// the conn.getURL() is actually different URL than u
 +
// the browser page can really see the URL and use it
changeImg(conn.getURL().toExternalForm());
changeImg(conn.getURL().toExternalForm());
}
}
-
// the browser can really see the URL now:
 
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
private static native void changeImg(String url);
private static native void changeImg(String url);

JaroslavTulach at 01:12, 30 October 2014 - 2014-10-30 01:12:53

←Older revision Revision as of 01:12, 30 October 2014
Line 19: Line 19:
</source>
</source>
-
The '''conn''' object in [[Bck2Brwsr]] also implements {{JDK|java/io|Closeable}}, so when the {{JDK|java/net|URL}} is no longer needed, it can be freed from browser by (safely) casting and calling '''close()''' on it.
+
The '''conn''' object in [[Bck2Brwsr]] also implements {{JDK|java/io|Closeable}}, so when the {{JDK|java/net|URL}} is no longer needed, it can be freed from browser by (safely) casting and calling '''close()''' on it. The full change together with tests is available in [http://source.apidesign.org/hg/bck2brwsr/rev/f5200d90b730 Hg history].
The above code works in [[Bck2Brwsr]] as well as in [[FXBrwsr]].
The above code works in [[Bck2Brwsr]] as well as in [[FXBrwsr]].

JaroslavTulach at 01:11, 30 October 2014 - 2014-10-30 01:11:14

←Older revision Revision as of 01:11, 30 October 2014
Line 19: Line 19:
</source>
</source>
-
The '''conn''' object in [[Bck2Brwsr]] also implements {{JDK|java/io|Closeable}}, so when the {{JDK|java/net|URL}} is no longer needed, it can be freed from browser by calling '''close()'''.
+
The '''conn''' object in [[Bck2Brwsr]] also implements {{JDK|java/io|Closeable}}, so when the {{JDK|java/net|URL}} is no longer needed, it can be freed from browser by (safely) casting and calling '''close()''' on it.
The above code works in [[Bck2Brwsr]] as well as in [[FXBrwsr]].
The above code works in [[Bck2Brwsr]] as well as in [[FXBrwsr]].
-
The created connection
 

JaroslavTulach at 01:10, 30 October 2014 - 2014-10-30 01:10:26

←Older revision Revision as of 01:10, 30 October 2014
Line 1: Line 1:
-
For a long time users of [[Bck2Brwsr]] complained that loading images, or other resources from the browser is complicated. With great delight [[I]] can announce that forthcoming [[Bck2Brwsr 0.12|version 0.12]] contains solution. It is build around [[JavaScript]] '''Blob''' support. In case you have an application class with an image resource next to it, you can:
+
For a long time users of [[Bck2Brwsr]] complained that loading images, or other resources from the browser's [[HTML]] page is complicated. With a great delight [[I]] can announce that forthcoming [[Bck2Brwsr 0.12|version 0.12]] contains a solution. It is build around [[JavaScript]] '''Blob''' support.
 +
 
 +
In case you have an application class with an image resource next to it, you can:
<source lang="java">
<source lang="java">
public static void onPageLoad() throws Exception {
public static void onPageLoad() throws Exception {
-
URL u = Main.class.getResource("launcher.png");
+
URL u = Main.class.getResource("yourimg.png");
// by opening the connection one requests creation of Blob
// by opening the connection one requests creation of Blob
Line 12: Line 14:
}
}
 +
// the browser can really see the URL now:
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
private static native void changeImg(String url);
private static native void changeImg(String url);

JaroslavTulach: New page: For a long time users of Bck2Brwsr complained that loading images, or other resources from the browser is complicated. With great delight I can announce that forthcoming [[Bck2Brws... - 2014-10-30 01:09:12

New page: For a long time users of Bck2Brwsr complained that loading images, or other resources from the browser is complicated. With great delight I can announce that forthcoming [[Bck2Brws...

New page

For a long time users of [[Bck2Brwsr]] complained that loading images, or other resources from the browser is complicated. With great delight [[I]] can announce that forthcoming [[Bck2Brwsr 0.12|version 0.12]] contains solution. It is build around [[JavaScript]] '''Blob''' support. In case you have an application class with an image resource next to it, you can:

<source lang="java">
public static void onPageLoad() throws Exception {
URL u = Main.class.getResource("launcher.png");

// by opening the connection one requests creation of Blob
URLConnection conn = u.openConnection();
// the conn.getURL() may actually differ from u

changeImg(conn.getURL().toExternalForm());
}

@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
private static native void changeImg(String url);
</source>

The '''conn''' object in [[Bck2Brwsr]] also implements {{JDK|java/io|Closeable}}, so when the {{JDK|java/net|URL}} is no longer needed, it can be freed from browser by calling '''close()'''.

The above code works in [[Bck2Brwsr]] as well as in [[FXBrwsr]].
The created connection