Tuesday May 25, 2010

Thank You!

I was inspired by Jim Weaver and Stephen Chin to start blogging. Jonathan Giles provided the launch pad via his "Java desktop links of the week". Philippe Lhoste (PhiLho in Forums, you cannot miss him!) inspired to write more. In less than one year this blog was made popular by all of you and was added to "Oracle's Java Bloggers" list. Feels great to see the name along with some of the greatest people in industry

None of these would have been possible without your encouragement and support. I would like to say to all of you. It was really nice interacting with you. Google-Analytics shows huge number of unique visitors, I hope this was of help to at-least few of them

Unfortunately today is my last day at Sun-Oracle. I had to take this difficult decision to end a decade long association with Sun. I'll continue to blog at WordPress

http://rakeshmenonp.wordpress.com/

Hope to have your continued encouragement and support


Monday Feb 08, 2010

Java Download Service Listener


One of the previous post [Applet Startup Time] provided a way to measure start-up time of JavaFX Applets. Many responded with requested information (Thanks a lot!). One of the main concern raised was high start-up time for "Without JavaFX Runtime". This is high because it includes time taken to download and install JavaFX Runtime.

Unfortunately there was no way to notify the user about exact progress of this. Hence user will not be able to differentiate between download and install of "JavaFX Runtime" and "JavaFX Application".

Recent JavaFX Update 1.2.3 reduced the download size and start-up time. You can notice this change by trying out the start-up time measurement applet again.. But still it doesn't provide a way to exactly notify the start-up progress. We can only specify a custom splash-screen as specified here.

And then we have Java Update 1.6.0_18 - [Download Now] - Not sure how many of you noticed this feature - Download Service Listener It allows you to provide a Custom Progress UI using AWT/Swing/Java2D APIs. It has callback methods which will provide information related to download and validation of resources. Please refer to Download Service Listener Example for more information. Refer to ProgressListener.java and ProgressView.java for implementation used in this sample.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="http://javafxdemos.googlecode.com/hg/resource/ProgressListener/ProgressListenerFX.js"></script>


To launch click on above image or

Now we can implement custom progress listener with actual values. We can use the same approach for JavaFX applications as well. There is minor issue in using this feature with JavaFX Applet deployed using dtfx.js. This script is not updated to utilize this feature. So for now we need to explicitly hide the default splash screen by invoking JavaScript method hideOverlay as shown in ProgressListenerFX.html

Reference:

Hmm.. thatz a long post with lots of information.. But I think its very useful.. As usual, please try it out and let me know feedback..


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://javafxdemos.googlecode.com/hg/resource/ProgressListener/zoneit.js"></script>

Thursday Nov 19, 2009

Java Warehouse Goes Global!


Developers from following countries can submit their free apps to Java Warehouse now and reach the US Java Store users :)

  • UK
  • Australia
  • India
  • China (PRC)
  • Sweden
  • Brazil
  • Russia
   

Please read about the features, JavaWarehouse-FAQ and JavaStore-FAQ for more information. Let Java Warehouse worry about distribution so you can focus on creating great apps! :)

Monday Oct 26, 2009

To Pack or not to Pack?


I'm back from vacation.. Hmm.. well it was not this long though.. (my last post was more than a month back).. I traveled to few places, exploring new things.. You may view the some of the photos here!

Well was busy with many other things as well..
Oracle OpenWorld, Mobile Application Conference..

Anyway back to the topic.. Is it always good to compress the jar while deploying the Java/JavaFX application? What will be its impact on startup time? Or may be I was doing too much pack and unpack of luggage during vacation and hence the thought is still lingering in my mind?!

I think the answer depends on the application and target users. Pack helps to compress the jar file size (reduce download time). But it may increase the start-up time due to additional step - unpack. So if the application is too small, it may be better not to use compressed jar. Also if the target audience has very good bandwidth, then user may not see the benefit of reduced download time.

Applet - Pack Applet - No-Pack
<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/Startup/Startup.js"></script>
<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/StartupNoPack/Startup.js"></script>

Note: Above example is not the best to demonstrate any significant difference in warm start-up time

Also set update check to background in jnlp files as shown below.. Please refer to tech tip on start-up time for more information.

<update check="background"/>

JavaFX packager was generating jnlp files with missing / for close tag for applet-desc - param tag. Due to this any subsequent tags were getting ignored. So we need to ensure that all tags are properly closed. This issue with javafxpackager is resolved (not be available in 1.2)

<applet-desc ... >
     <param name="MainJavaFXScript" value="..." />
</applet-desc>

Best way to validate the jnlp is to launch the application and view the jnlp in Java Cache Viewer. Ensure that all entries are reflected properly. Update check must be set to "background" and not "timeout".

Well.. I never thought that one character (or lack of it) can contribute so much towards start-up time! Keep exploring!!

Tuesday Jul 28, 2009

JavaFX - JavaScript Communication


There is a tutorial on JavaFX Script - JavaScript Bridge, JavaFX Sample, Plug-In Live Connect and Carl's blog to list a few.. But still see questions about this (JavaSE Plug-In) feature. Hence just thought about writing a blog to demonstrate this..

I think the question primarily arise because, people have tried it but it doesn't seem to work. The feature is stable only with JavaSE 6 Update 10 and above. So if you are using older JRE (as in default settings of Mac) the feature will not work as expected.

In below example, I have two user interface. One with HTML and another in JavaFX. When I click on HTML buttons it will invoke Java API and show message box using javax.swing.JOptionPane. When I click on JavaFX buttons, it will call JavaScript method such as alert, confirm, prompt to show message box.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/JavaFXJavaScript/JavaFXJavaScript.js"></script>

Click on above image to launch the applet

JavaScript methods are invoked from Java or JavaFX using netscape.javascript.JSObject. An instance of JSObject can be obtained using static method JSObject.getWindow(< applet >) by passing the current applet instance as argument.

Applet instance can be obtained from JavaFX as shown below:

var applet = FX.getArgument("javafx.applet"as Applet;

Next we need to get instance of JSObject. These classes are available in plugin.jar. So we need to include explicitly plugin.jar in classpath. Instead we can also use reflection to invoke these methods. I have used reflection and created a wrapper - JavaScriptUtil. This can be instantiated by passing above applet instance.

A series of method to show message box is added both JavaScript and JavaFX as shown below.

JavaScript:

function show_alert() {
    alert("JS: I am an alert box!");
}

JavaFX:

public function showAlert() : Void {
    JOptionPane.showMessageDialog(null, "FX: I am an alert box!");
}

I have prefixed the message with "FX" and "JS" so as to identify the origin of message box.

Invoke JavaFX method from JavaScript:

var applet = document.getElementById('JavaFXJavaScript');
// Invoke JavaFX method from JavaScript
applet.script.showAlert();

The applet element is obtained using its id

<script>
    javafx(
       {
           codebase: "dist",
           archive: "JavaFXJavaScript.jar",
           draggable: true,
           width: 250,
           height: 120,
           code: "javafxjavascript.Main",
           name: "JavaFXJavaScript",
           id: 'JavaFXJavaScript'
       }
    );
</script>

Invoke JavaScript method from JavaFX:

var jsObject = netscape.javascript.JSObject.getWindow(applet);
jsObject.call("show_alert"[]);

Since we have wrapped all JSObject methods in JavaScriptUtil we may invoke JavaScript method as shown below.

var applet: Applet = FX.getArgument("javafx.applet"as Applet;
var jsObject = new JavaScriptUtil(applet);
jsObject.call("show_alert"[]);

Please refer to JavaFXJavaScript.html and Main.fx for more details.

Java Plug-In LiveConnect API Documentation:

Try it out and let me know feedback


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXJavaScript/zoneit.js"></script>

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today