Thursday Jul 02, 2009

JavaFX + Zembly


Zembly application development environment makes it easy to develop, customize and deploy your application. It provides APIs from various providers.

Here we will try to use Zembly services (outside of Zembly) from JavaFX. Zembly provides client libraries for both Java and JavaFX.

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

For Applet mode, click on above image

For standalone mode

Above sample is modified version of InterestingPhotos which now uses Zembly APis to search flickr's photo search based on tags. It uses flickr api - photos.search as shown below.

String result = Zembly.getInstance().callService(
    String.class,                 // Return Type
    "web.flickr.photos.search",   // Service Name
    new String[][] {              // Arguments
        {"machine_tag_mode""any"},
        {"tags""javafx" },
        {"per_page""65"},
        {"page""1"},
        {"format""json"}
    }
);

Class com.zembly.gateway.client.Zembly is available in Zembly Client Library implementation. Download zcl4j.zip here

Now we can easily write a wrapper for zcl in JavaFX using Asynchronous APIs. This will also demonstrate how to use these APIs to invoke Java apis in background thread from JavaFX.

Provide an implementation for javafx.async.RunnableFuture which will invoke the Zembly client APIs - ZemblyRunnableFuture. Next design an interface which bridge the Java and JavaFX - CallbackHandler.

Now we can implement the ZemblyRequest API which extends the JavaFX JavaTaskBase. This will provide an implementation similar to HttpRequest API.

ZemblyRequest can be used in application as shown below

var request = ZemblyRequest {

    // Zembly Service Name
    serviceName: "web.flickr.photos.search"

    // Arguments to be passed to service
    arguments: [
        Pair name: "machine_tag_mode", value: "any" },
        Pair name: "tags", value: "{encodedTags}" },
        Pair name: "per_page", value: "65" },
        Pair name: "page", value: "1" },
        Pair name: "format", value: "json" }     
    ]

    onStart: function() {
        println("ZemblyRequest - start");
    }

    onInput: function(is) {
        // Use PullParser to parse the stream
        is.close();
    }

    onDone: function() {
        println("ZemblyRequest - done");
    }

};
request.start();

Zembly key and secret must be generated and specified in zcl.properties file which must be kept in default package inside jar file. For more information on this, please refer to article - How to Call Data Service from Outside Zembly

I followed articles - Creating a Widget in 5 Minutes and Working with JavaFX so as to deploy above sample as Application

Try it out and let me know feedback

Source:

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_zembly";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>

Monday Apr 13, 2009

JavaFX - Image Viewer


One of the questions I received in comments of one post

actually regarding the carousel and display shelf samples written on the net.this samples r feasible for 100 x100 pics. i am getting photos from flickr. if i want to implement this view how can it be done.. or is it at all feasible..

A genuine valid question! Yes Carousel and DisplayShelf are written with smaller dimensions. Carousel was targeting mobile profile as well, so its size was small. Also most of samples I have too didn't have large dimensions.

So here is a sample which uses larger dimension - [800X650].

For Applet mode, click on above image

For standalone mode

It loads images from flickr. If you click on the thumbnails below, it will move to scroll to next thumbnail and zooms the image. Its very basic demo, just to demonstrate use of large images. It uses hard-coded values for coordinates and scale, so not really the best demo.


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

Wednesday Mar 04, 2009

Making JavaFX InterestingPhotos... Interesting!



InterestingPhotos is one of JavaFX sample published at samples website. It displays "interesting" photos from flickr [List of interesting photos for the most recent day].

It uses flickr api - flickr.interestingness.getList

Does it sound interesting to you? May be not.. It would have been nice if it could display photos from my flickr id!

Ofcourse yes! It can! For that you need to do some minor modifications to the source code. First download the InterestingPhotos source from http://javafx.com/samples/InterestingPhotos/.

Obtain a flickr api-key from flickr website. You need to login to the site with your flickr id and apply for a new key. You will receive a key similar to 1234567890abcdef0123456789abcdef.

Now you need to find user-id (nsid) of your flickr user-name. It can be found from flickr website. Visit flickr.people.findByUsername. Enter your user name in the text field. Click "Call Method..." button. It will display an XML output below. Note down the nsid in the output, similar to nsid="1234567@A01".

You can get the list of public photos in your flickr account using flickr.people.getPublicPhotos api. You need to specify the above nsid as user_id argument.

Example: http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=1234567890abcdef0123456789abcdef&user_id=1234567@A01

Open the above URL, it must list the photo information in XML format.
Below code is in Main.fx of InterestingPhotos.

// Submit HttpRequest    
var request: HttpRequest = HttpRequest {
    
    location: "http://api.flickr.com/services/rest/?method="
        "flickr.interestingness.getList&api_key={apiKey}&per_page={layout.imageCount}"
    method: HttpRequest.GET

Modify the location: URL to point to above obtained URL. Rebuild the application. Now it must show photos from your flickr account!

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




For Applet mode, click on above image

For standalone mode


<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/making_javafx_interestingphotos_interesting";</script>
<script type="text/javascript">var dzone_style = '2';</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/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