JavaFX – Picasa Viewer


Bookmark and Share

Simple image viewer for Picasa Web Albums using Data API. It shows pictures taken at Hogenakkal Falls from my Picasa account.


To launch click on above image or

The application gets a feed listing all of the albums belonging to specified user using ListAlbums and ListAlbumPhotos. The feed is parsed using HttpRequest and PullParser APIs.

Try it out and let me know feedback..

var dzone_style = ‘2’;

Advertisements

JavaFX + Echo Nest


The Echo Nest provides series of web based solutions for better search, recommendation and interactivity on the music web. The Echo Nest API allows you to call methods that respond in REST style XML. Please refer to API documentation for more information.

They also provide a series of data feeds in various formats. Below application is updated version of DraggableMP3Player sample. Now it gets data from “Found Audio Feed” using JavaFX RssTask APIs.


To launch click on above image or

Type name of artist in TextField and press enter key. It will get the list of songs using Echo Nest feed. Click play to listen to songs! Simple! It will save the last searched artist name using JavaFX Storage APIs.

Note: Most of the media were in MP3 format (not streaming) and hence may take a while to download and play. Please try to incorporate more APIs and write new player..

JavaFX – RSS and ATOM Task


JavaFX 1.2 provides new APIs to handle RSS and ATOM feeds. RssTask and AtomTask parses the feeds and provide the content as JavaFX objects. It can also be configured to provide updates on regular intervals.

RssTask parses the feed and provides the content as Channel and Item objects. These objects in-turn provides other information such as image, link, title, category, date etc.

Similarly AtomTask parses feed and provides Feed and Entry objects. These objects in-turn provides information such as author, category, link, logo, contributors etc.

News ticker using Yahoo RSS feed is given below.

For Applet mode, click on above image

For standalone mode

RssTask Usage:


var rssTask = RssTask {
    
    location: "http://rss.news.yahoo.com/rss/world"
    interval: 300s

    onException: function(e) {
        e.printStackTrace();
    }

    onChannel: function(channel) {
        println("{channel.title}");
    }

    onItem: function(item) {
        println("{item.title}");
    }
}
rssTask.start();

AtomTask Usage:


var atomTask = AtomTask {
    
    location: "http://jfxstudio.wordpress.com/feed/atom"
    interval: 300s

    onException: function(e) {
        e.printStackTrace();
    }

    onFeed: function(feed) {
        println("{feed.title}");
    }

    onEntry: function(entry) {
        println("{entry.title}");        
    }
}
atomTask.start();

JavaFX Tweeter sample demonstrates use of both RssTask and HttpRequest.

Source:

var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_rss_and_atom_task”;
var dzone_style = ‘2’;

digg_skin = ‘compact’;
digg_window = ‘new’;

JavaFX – Upload and Download Large Files


We can upload or download large files using new HttpRequest attributes available in JavaFX 1.2.

HttpRequest has input and onInput attributes that provides InputStream which can be used to download data. This stream supports mark, reset, available, skip etc. But to support this HttpRequest buffers the data. Due to this buffering it was not possible to use this approach to download large files.

JavaFX 1.2 introduce two new attributes – source (InputStream) and sink (OutputStream). If we set sink attribute, we can directly download the content of stream without buffering. Also with source we can upload the content. Eg: By setting it to FileInputStream. When source or sink attribute is used, corresponding input, onInput, output, onOutput will not be functional.

For Applet mode, click on above image

For standalone mode

The application downloads a larger version of the photo. I took it from Somnathpur using Nikon Coolpix! 🙂


function downloadFile(url , outputFile) {

    def getRequest: HttpRequest = HttpRequest {

        location: url
        sink: new java.io.FileOutputStream(outputFile)

        onToRead: function(bytes: Long) {
            toRead = bytes;
            println("onToRead({bytes})");
        }

        onRead: function(bytes: Long) {
            read = bytes;
            println("onRead - {read * 100/toRead}%");
        }

        onDone: function() { println("onDone") }
    }

    getRequest.start();
}

In above sample, sink is assigned to a FileOutputStream. So all the content will be directly written to file without buffering. Note: For making the application compatible with mobile or other platforms we will have to use only subset of java.io package. Example: MID Profile Core API.

Source:

JavaFX + Yahoo Placemaker + Maps


I have my travel itinerary or a document with list of cities, such as Seven Wonders of the World. I would like to retrieve the list of cities and the location information associated with it. How to do this??

Yahoo! released new Yahoo! Placemaker APIs. These APIs search for name of places in plain text document and returns the latitude and longitude associated with the place. You can either provide a text or a URL as input to the API. The output can be obtained in XML or RSS format.

Combine above information with Yahoo! Maps will return the maps associated with all places mentioned in specified document! Itn’t that cool?! 🙂




May be I must write more applications and publish at Java-Store!

For Applet mode, click on above image

For standalone mode

In above application we provide a URL which the Placemaker API will parse and returns the list of places. This information is given to Map Image API to retrieve the image. Any valid http URL can be provided as input. There is currently a 50 kbs limit for documents processed by Placemaker. Documents above this length are rejected and returns status 413. Please enter a new URL in textfield and press enter to load new places.

Source:

var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_yahoo_placemaker_yahoo_maps”;
var dzone_style = ‘2’;

digg_skin = ‘compact’;
digg_window = ‘new’;

JavaFX – WebServices


JavaFX provides API to perform asynchronous HTTP request and also utilize RESTful webservices. It also provides parsers for XML and JSON data formats.

Related Posts:

HttpRequest class provides way to specify a location (HTTP URL) and transfer data via InputStream and OutputStream.


def httpRequest = HttpRequest {
    
    location: "http://news.google.com/?output=rss"
    method: HttpRequest.GET
    
    onInput: function(in: java.io.InputStream) {
        try {
            // Read the content from this InputStream
            // Pass the InputStream to parser 
        finally {
            in.close();
        }
    }
}
httpRequest.start();

The InputStream obtained from HttpRequest can be parsed using PullParser API. It can parse both XML and JSON data type.


def parser = PullParser {
    
    documentType: PullParser.XML
    input: <InputStream obtained from HttpRequest>
    
    onEvent: function(event: Event) {
        // Handle events triggered for each node
        // and retrieve the data
    }
}
parser.parse();

Now we can utilize these APIs to enhance the existing Image Viewer sample so as to retrieve the photos dynamically from Flickr. Source code for PhotoPullParser.fx and Photo.fx are copied directly from InterestingPhotos sample.

For Applet mode, click on above image

For standalone mode

There are many samples at JavaFX Samples website which uses HttpRequest and PullParser APIs. You can refer to those source code for more information.

<!–

–>

Deployment:

JavaFX – News Widget


This is an attempt to answer several queries in one go. Lets see if it helps..

  1. Can I embed JavaFX in JSP, ASP, PHP, JSF,…
    (Endless several other web technologies)?
  2. Can JavaFX dynamically interact with html page via JavaScript?
  3. Is it feasible to implement JavaFX JavaScript communication?
  4. Can JavaFX retrieve data from external services/resources?

Answer is YES! to all of above. Lets try to prove that..

We have a JavaFX Sample – RSS-Viewer which we will try to customize and integrate it into this blog. RSS-Viewer can retrieve data from various RSS feeds. It will parse the feed using JavaFX parser and render the HTML data in browser.

By default the application loads the feed from Yahoo! news. We will customize it so as to load the feed from Google News. The application accepts an argument rss_url which can be used to specify the RSS feed.

Now how will we incorporate this widget into this blog? We need to create a <div> in HTML which will act as placeholder for embedding the HTML data from JavaFX. We will update the content of this <div> using JavaScript.


<div id="ChannelData" style="text-align: center;"></div>

Now we will write a JavaScript method which will update the data from JavaFX.


function updateChannelData(channelData) {
    document.getElementById("ChannelData").innerHTML = channelData;
}

JavaFX will invoke updateChannelData( <data> ) with data from RSS feed and update the content.
Now we need to include the JavaFX Widget. For this we need to include the JavaScript dtfx.js and call javafx function passing the application attributes as shown below.


<script src="http://dl.javafx.com/1.2/dtfx.js&#34;></script>

<table width="40%" border="1" cellpadding="10" cellspacing="0">
  <tbody>
    <tr>
      <td align="center">

        <script>

          javafx(
            {
              archive: "http://javafx.com/samples/RSSViewer/webstart/RSSViewer.jar,&#34;,
              width: 610,
              height: 62,
              code: "rssviewer.Main",
              name: "RSSViewer"
            
              isApplet: "true"
              js_mode: "true"
              rss_url: "http://news.google.com/news?pz=1&ned=us&hl=en&topic=w&output=rss&#34;
            
          );
          
          function updateChannelData(channelData) {
            document.getElementById("ChannelData").innerHTML = channelData;
          }
          
        </script>
        
        <div id="ChannelData" style="text-align: center;"></div>
        
      </td>
    </tr>
  </tbody>
</table>

After embedding above code in your html you must be able to load and view Google News.

Now we have incorporated an existing widget into html page. It also uses JavaFX JavaScript interaction and loads the data from external service – Google News.

Refer to
LiveConnect Support in the Java™ Plug-In Technology
for more information on Java JavaScript communication.

But did I prove the first point – Can I embed JavaFX in JSP, ASP, PHP, JSF,…??. May be not? Please try to follow above steps and try to incorporate this widget into your page and let me know how things go. You must be able to provide any well formatted RSS feed as rss_url.

For standalone mode