Monday Feb 08, 2010

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.


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..


Wednesday Feb 03, 2010

One of the previous post had a sample to download large files using JavaFX. It relies on HttpRequest attribute sink to specify the output file location. Similarly we can use source attribute for uploading a file.

I have written a simple UploadServlet to receive the file content and save at <user.home>/JavaFXDownloads/ location.

Relevant part of JavaFX client code is given below..

def uploadServletURL = 
    
"http://localhost:8080/server/UploadServlet";

def urlConverter = URLConverter{ };
def encodedServletURL = urlConverter.encodeURL(
    "{uploadServletURL}?file={inputFile.getName()}")

def httpRequest: HttpRequest = HttpRequest {

    location: encodedServletURL    
    source: new java.io.FileInputStream(inputFile)
    method: HttpRequest.POST

    headers: [
        HttpHeader {
            name: HttpHeader.CONTENT_TYPE
            value: "multipart/form-data"
        }
    ]
}

Name of file is passed as argument to upload servlet. This URL is encoded using URLConverter. The file to be uploaded is assigned to source attribute. Http content-type is set to "multipart/form-data". You can host the UploadServlet - server - code in any webserver such as Tomcat, Glassfish etc. Value of uploadServletURL in JavaFX client must be updated to point to this servlet URL.

I found another sample code Multipart HTTP file upload with JavaFX which demonstrates alternate approach.

Try it out and let me know feedback..


Wednesday Jan 27, 2010

you know its coming...
but you find it difficult to believe...
like someone said, "all good things come to an end"...


To launch click on above image or



A Tribute to Sun Microsystems

"... Sun cared about its customers... Sun did not cheat, lie, or break the rule of law or decency... We enjoyed breaking the rules of conventional wisdom and archaic business practice... we did so with a solid reputation for integrity... Kick butt and have fun!"

    -- Scott McNealy



The URL of this blog may change.. But the passion to work, write, discuss and share about latest technologies don't! I'm grateful for all your encouragement and support.. "A BIG THANK-YOU"
Looking forward to have the same in future as well..

Also available at http://rakeshmenonp.wordpress.com/

Thursday Jan 14, 2010

There were many queries related to saving and printing of JavaFX nodes. Users can capture the node as image following the approach outlined in one of previous blog and use ImageIO APIs to save the image to file. For printing, we can use 2D printing - java.awt.print.PrinterJob and java.awt.print.Printable. Implement print method in Printable interface and draw the image onto Graphics object. Another approach is to directly print the image using javax.print.PrintService.

Below sample demonstrates use of ImageIO and PrintService to print the Chart


To launch click on above image or

The chart node is captured in BufferedImage. Refer to toBufferedImage method in Utils.fx. The image is then streamed to a ByteArrayOutputStream using ImageIO API. A PrintService instance which supports DocFlavor.INPUT_STREAM.PNG is obtained using lookupPrintServices method in PrintServicesLookup and print. Refer to print method in PrintUtils.java for more information.

Try it out and let me know feedback.. ..and once again wish you a
Happy New Year!


Wednesday Dec 23, 2009

JavaFX + Apache Derby Database + JDBC - I have seen several queries related to this, hence thought of providing a sample application. In order to avoid any back-end database setup, I'm using Embedded Derby which will create database in <UserHome>/JavaFXDatabase/. The Derby jars are hosted as separate JNLP extension - ApacheDerby.jnlp - which is referenced in application jnlp files.

Click "Populate" button to add some dummy data to the Table.


To launch click on above image or

Note: Application may take a little longer to download due to large size of Derby jar files. Application will show two certificate dialogs - One for application and another for Derby Extension. These permissions are required so as to create database in user's home directory.

Database access code is same as any other java application - DBUtils.java. The table is implemented using Rectangle, Label and Panel Layout. Its not really scalable as its not using any virtual concepts, all nodes are real. The approach can be used for simple applications. Please refer to CustomerTable.fx for more information.

Try it out and let me know feedback..

..and that brings the end of this year's blogs. It was nice sharing all the information with you.. "See" you next year!

Merry Christmas and Happy New Year to All.. Have Fun!


This blog copyright 2010 by Rakesh Menon