Thursday Oct 29, 2009

Bangalore Open JavaFX User Group

Time for adoption :). We are starting up Bangalore Open JavaFX User Group and searching for the JavaFX techie who can lead it. So, all JavaFX developers in Bangalore please write a mail to me, if you are interested. My mail ID is : vaibhav.choudhary-AT-sun-DOT-com or can drop a comment here.

We will have more fun with FX soon
[Read More]

Wednesday Sep 23, 2009

shape intersection/subtraction result - JavaFX

A very simple example in JavaFX to show that shape intersection/subtraction  works so cool in JavaFX. Gradient comes out in a nice fashion and motion is also smooth. 

 Please see this link to view the sample: http://www.javafx.com/samples/SpeedoMeter/index.html The gradient in sample and here are different and that can be changed by changing 3-4 lines in code.

Its again a open code written. Personally I don't like too much of OOP's coding in JavaFX as it is not a language meant for it. But yes if sample size/application size is big, its always good to make things seperate.


Tuesday Aug 11, 2009

User experience - More rich !

Finally Nancy got it done. Thanks ! 

It's very very important for us to know the correct method of shipping the application. Out of Browser feature is awesome but you can't simply expect Customer, End User to drag the applet out of browser by pressing Alt-Space. No, its just a way Java Runtime provide to us. In JavaFX, this feature is customizable up to an awesome extent. You can simply write 4-5 lines of code and make the applet draggable as you feel it should :D.

Here is one small article on same:

http://www.javafx.com/docs/articles/ShouldDrag/index.jsp

Maybe, I mentioned something like this in my prev. post, so can be repeated, but not truly  ! Have Fun !

Now again, we will talk about Customer, User look and feel. I bet most of us got bored watching rotating Java Logo and applet is taking time to load. JavaFX new feature is to use splash screen for that. Though here in this article you will get one static splash screen but no one can stop you making a dynamic gif splash screen. We will have that also in show case soon, till that time enjoy with this :

http://www.javafx.com/docs/techtips/SplashScreen/

Do, leave your comments so that we get to know how pathetic we are and what is/are the improvement(s) required. thanks !

Sunday Aug 02, 2009

Progress Indicator - JavaFX !

Probably I missed something. But this is the way we can add indefinite progress indicator with any unpredictable events. Here I am just calling a Web service to show yahoo maps for NY city.

Here how progress indicator looks like : ..........

[Read More]

Thursday Jul 30, 2009

Use of ListView - UI Control

A simple example how ListView works in JavaFX 1.2. I guess it need more feature in next release. But it do basic stuff like providing scrollbar if list is long, selected item actions.Something like this :

Here is the simple code, in which I am adding text  ..........

[Read More]

Tuesday Jul 28, 2009

Simple example of Scroll Bar - JavaFX 1.2

ScrollBar - UI Control feature of JavaFX 1.2 .

It has been used in lot of samples but if you are finding it tough to grab out the code from sample to use. Here is a simple(simplest actually :) ) code to use scrollBar. I have create array of rectangle and associated scroll bar with it. Something like this  ..........

[Read More]

Saturday Jul 25, 2009

Hyperlink to URL

It's a long time being blogging. Actually not done anything new from long time :). Here is one simple concept which some guys asked me. We have provided hyperlink API in JavaFX 1.2 but some of us struggled to open a URL using hyperlink API.

Hmm, 2 ways to do it actually.

 No1 : Use the Desktop API of JDK6. It's simple to use. One example is here....

[Read More]

Tuesday Jun 30, 2009

Small code for PieChart...but !

As already discussed, JavaFX 1.2 provide API set for Charts and Graphs. Though I decided to put my hand dirty in writing one 3D piechart from my own. With mine, you will get additional feature of explode in and out feature :). Well, action can be written with the existing chart API and I guess explode feature will also come soon.


Making 3D Pie chart is nothing but layering of 2D Pie Chart and here goes a small code :

Slice.fx

package piechart3d;

import java.lang.Math;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;

/\*\*
 \* @author Vaibhav Choudhary
 \*/

public class Slice extends CustomNode {

    public var color: Color;
    public var sAngle: Number = 0.0;
    public var len: Number = 0.0;
    public var xt = 0.0;
    public var yt = 0.0;


    function explodout():Boolean {
        var t = Timeline {

            repeatCount: 1
            keyFrames: [
                KeyFrame {
                    time: 0.25s
                    canSkip: true
                    values: [
                        xt =>
                        30 \* Math.cos(2  \*  Math.PI  \*  (sAngle  +  len  /  2)  /  360) tween Interpolator.EASEBOTH,
                        yt =>
                        -30 \* Math.sin(2  \*  Math.PI  \*  (sAngle  +  len  /  2)  /  360) tween Interpolator.EASEBOTH

                    ]
                }
            ]
        }
        t.play();
        return true
    }
    function explodein():Boolean {
        var t1 = Timeline {
            repeatCount: 1
            keyFrames: [
                KeyFrame {
                    time: 0.25s
                    canSkip: true
                    values: [
                        xt => 0,
                        yt => 0
                    ]
                }
            ]
        }
        t1.play();
        return true
    }

    public override function create(): Node {
        return Group {
            blocksMouse: true
            translateX: bind xt
            translateY: bind yt
            onMouseClicked: function( e: MouseEvent ):Void {
                if(xt == 0 and yt == 0) {
                    explodout();
                }
                            else
                explodein();
            }
            content: for(num in [0..25]) {[
                    Arc {
 
                        stroke: color
                        cache: true
                        fill: color
                        translateX: 0
                        translateY: (num + 1) \* 1
                        centerX: 250
                        centerY: 250
                        radiusX: 150
                        radiusY: 60
                        startAngle: bind sAngle
                        length: bind len
                        type: ArcType.ROUND
                    }
                    Arc {
                        cache: true
 
                        fill: LinearGradient {
                            startX: 0.3
                            startY: 0.3
                            endX: 1.0
                            endY: 1.0
                            stops: [
                                Stop {
                                    color: color
                                    offset: 0.0
                                },
                                Stop {
                                    color: Color.WHITE
                                    offset: 1.0
                                },

                            ]
                        }
 
                        centerX: 250
                        centerY: 250
                        radiusX: 150
                        radiusY: 60
                        startAngle: bind sAngle
                        length: bind len
                        type: ArcType.ROUND
                    },
                ]
            }

        };
    }
}


Main.fx:
package piechart3d;


import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.stage.Stage;

/\*\*
 \* @author Vaibhav Choudhary
 \*/

var slice1: Slice = Slice{color: Color.YELLOWGREEN, sAngle:0, len: 45};
var slice2: Slice = Slice{color: Color.BLUEVIOLET, sAngle:45, len: 80 };
var slice3: Slice = Slice{color: Color.PALETURQUOISE, sAngle:125, len: 80 };
var slice4: Slice = Slice{color: Color.DARKORANGE, sAngle:205, len: 100 };
var slice5: Slice = Slice{color: Color.FIREBRICK, sAngle:305, len: 55};


Stage {
    title: "Pie Chart - 3D"
    width: 550
    height: 580
    scene: Scene {
        fill: Color.WHITE
        content:[
           slice2, slice1,slice5,slice3,slice4
        ]
     }
    }


Anything here can be made generic to any extend. There is a for loop of 0..25 in Slice.fx which speaks about the thickness of chart :) and some mathematics in timeline speaks about explode feature.

Now if you compare this with PieChart that comes in API, you will see this has some jerky corners + Color combination is not as soluble. How that has been made is secret :).

JNLP Run :



Tuesday Jun 09, 2009

JavaFX Production Suite - Usages

The new samples are more complex than older once. And this is what we want. New features, not only need a sample to showcase but all the sample should be result oriented. Mean to say, it should do something with real world.

In the meantime, I can show you how interaction of JavaFX SDK increased with Production Suite. 

Lot of samples like Forecasting, BrickBreaker, SnakesNLadders are using Production Suite. They get the FXZ file from the designer and then do the animation job(logic coding) in JavaFX.

One I can explain of mine, Forecasting, though this sample is not complete but it uses FXZ file to a great extent. I got all the weather information in FXZ file by Charles, who is the graphics designer of this sample. Now, our idea is to animate weather conditions. According to the condition, we need to thought of animation.

For thunder, it looks something like this : 


Animation can be viewed in applet but I am just putting an image. Here there are three animation, 1. Shining of Sun 2. Left thunder spark 3. Right thunder spark.

Now, I have 5 layers of image in FXZ file, Sun, Sun Glow, Cloud, Left spark, right spark. On the basic of these, we decided what to animate when !

Final point is we need animation like opacity reduction or translation or both or rotating. Content once delivered to us in FXZ file, we can easily interoperable with FX code. The best way is to define layer names in FXZ file and use it in the code.

Thursday Jun 04, 2009

New Controls - Chart API in JavaFX 1.2

One of the most effective API's got introduced into the Marina(JavaFX 1.2) release are Control and Chart API's. As there are lot of questions on chart API, here is the small code for making some charts, it almost follow the same protocol with all chart API's.

We can do hell lot of things with it. I have just used the default and shown how action() can be written on slices. 

Source code : Here

Here goes the bubble chart, basic funda is same, insert the number array into BubbleChart.Data. Get all the Data into series and get that series into the Chart API. For more, please see the source Code.

More will be posted soon, or a jumbo one with all of it in one go ! You can download the latest SDK from here.

Wednesday Jun 03, 2009

JavaFX 1.2 : RIA + You

So, finally sweat materialized into product. JavaOne announced the new release of JavaFX 1.2. You are welcome to visit the new cool site of javafx.com.

Also visit the sample section, fully loaded with new samples.

JavaFX 1.2 release is loaded with enormous features. Detailed list  here.

Little bit what I know, let me speak about the changes and the corresponding samples.

1. Set of new UI Controls : Buttons, Sliders, Texts ... bla bla... many more. Please figure out in this nice sample :

ProjectManager. Other new samples are also using it like FXAddressBook, StockQuote

2. Chart API : LineChart, AreaChart, BarChart(2D,3D), PieChart(2D,3D), Bubble Chart and many more. Please see the detail in Chart API doc.

Samples : Shopping Mashup, Weather Forecasting

3. Persistence Storage: Resource and Storage class has been added.

Samples: StickyNotes

4. Start-up performance has been increased around 40 percent. No Sample for it :) or we can saw all sample for it :).

5. Lot of changes in Graphics API's

6. O yes, adding of Asynchronous Operations, last time I was struggling running process in Parallel in JavaFX as it is a single threaded application.

Some more things you would like to see :

2 FullScreen Games has been added into samples repo, Reversi Game and SnakesLadders.

IMPORTANT POINT : Many times I talk about RIA, and now if you see the sample repo, there are only few samples which are not using any Web Services. Most of it, are taking Data dynamically from Web Services.

More things to come ....

Friday May 22, 2009

Yahoo Map Navigation...JavaFX

Extremely sorry for not responding to the question in few of the last blog posts. Here is the Yahoo Map navigation. I started liking Yahoo Web Service, it is so cool.

Please use your App-ID, if you are putting this code somewhere else, because this code uses default Yahoo Key.  Now, any web service work need these API use :

PullParser - A parser for structured Data. JDK6 can also do parsing in same way.

HttpRequest - Can use for Async HTTP or RestFul web services.

This code is so easy and monotonous that you will start copying it after 2-3 go :). Here it goes for Yahoo Map + Navigation code I have added addition here for both key and mouse.

JNLP for the same : 


Main.fx :
package yahoomapnavigation;

import java.lang.Math;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import yahoomapnavigation.MapLocate;


/\*\*
 \* @author Vaibhav
 \*/

var ml: MapLocate = MapLocate{zip:"10001"}; // 10001 - Newyork, i guess
var x1: Number = 0;
var y1: Number = 0;
var im: Image = bind Image {
    url: ml.location
}
/\* Image of the map from Yahoo WS \*/
var imview = ImageView {
    cache: true
    translateX: bind x1
    translateY: bind y1
    image: bind im
    cursor: Cursor.MOVE
    /\* Navigation from Mouse event\*/
    onMouseDragged: function( e: MouseEvent ):Void {
        if(e.dragX < 0 and x1 < 0) {
            x1 = x1 + 5;
        }
        if(e.dragX > 0 and Math.abs(x1  -  240) < im.width) {
            x1 = x1 - 5;
        }
        if(e.dragY < 0 and y1 < 0 ) {
            y1 = y1 + 5;
        }
        if(e.dragY > 0 and Math.abs(y1  -  320) < im.height) {
            y1 = y1 - 5;
        }
    }
    /\* Navigation from key event \*/
    onKeyPressed: function( e: KeyEvent ):Void {
        if(e.code == KeyCode.VK_LEFT)
                    {
            if(x1 < 0) {
                x1+=10;
            }
        }
        if(
                    e.code == KeyCode.VK_RIGHT)
                    {
            if(Math.abs(x1  -  240) < im.width) {
                x1-=10;
            }
        }
        if(
                    e.code == KeyCode.VK_DOWN)
                    {
            if(Math.abs(y1  -  320) < im.height) {
                y1-=10;
            }
        }
        if(e.code == KeyCode.VK_UP)
                    {
            if(y1 < 0) {
                y1+=10;
            }
        }
    }
};
Stage {
    title: "Yahoo Map Navigation"
    width: 240
    height: 320
    scene: Scene {
        content: [
            imview
        ]
    }
}
MapLocate.fx :
package yahoomapnavigation;

import java.lang.Exception;
import javafx.data.pull.PullParser;
import javafx.io.http.HttpRequest;

/\*\*
 \* @author Vaibhav
 \*/

/\* Class to show Map from Yahoo Web service, input zip code \*/
public class MapLocate {
    public var location: String;
    public var zip: String;
    public var isguid: Boolean = false;
    var url = bind "http://local.yahooapis.com/MapsService/V1/mapImage?appid=P6pToNnV34GfP9zgTALgVW3CUTL5qHTnKjz5bLXPikqNjcMZTkF6h1xsnhm.P1WIs3U-&zip={zip}";
    var p: PullParser;
    var h: HttpRequest;
    init {
        if (url.length() > 0) {
            h = HttpRequest {
                location: url
                onException: function(exception: Exception) {
                    print("Please check the internet connectivity/Data Input");
                }

                onInput: function(input) {

                    p = PullParser {
                        input: input
                        onEvent: function(event) {

                            if ((event.type == PullParser.END_ELEMENT)) {
                                if (event.qname.name == "Result") {
                                    isguid = true;
                                    location = event.text;
                                }
                            }
                        }
                    };
                    p.parse();
                    p.input.close();
                }
                onDone: function() {
                  
                }
            };
            h.enqueue();
        }
    }
}
</pre>

Please let me know if there is any issue, with JNLP or code :). Have fun !

Monday May 11, 2009

Image of the Day - NASA + JavaFX

In last blog entry, we talked to have some blogs on Web Service to show how things go. Here is one of the simplest.

JavaFX is moving towards it's next release and work is ON. One of my friends came to my desk and he saw some animation of weather going here and there. He asked me " Is it some scientific data, data from NASA or something like that, if not what is this animation all about". Meantime, I checked the RSS feeds/WebService by NASA and I use one here to get something called "Image of the Day".

Its a big size image and so decide to showcase fullscreen example as well. Here goes the small code :

//Main.fx

package nasaimage;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

/\*\*
 \* @author Vaibhav
 \*/

var s: Stage;
public var vText: Boolean = true;
var ly: LocationY = LocationY{};
var im = ImageView {
    fitHeight: bind s.height
    fitWidth: bind s.width
    image: bind Image {
        url: ly.urlImage
    }
}

var rect = Rectangle {
   blocksMouse: true
   x: bind s.width - 25
   y: 20
   arcHeight: 4
   arcWidth: 4
   width: 20,
   height: 20
   stroke: Color.GRAY
   strokeWidth: 2
   onMouseClicked: function( e: MouseEvent ):Void {
       FX.exit();
   }
}
/\* close button 'x' in title bar \*/
var close = Text {
   fill: Color.WHITE
   font: Font {
       name: "Arial Bold"
       size: 18
   }
   x: bind s.width - 20
   y: 35
   content: "x"
}

var loadingText = Text {
   visible: bind vText
   fill: Color.BLACK
   font: Font {
       name: "Arial Bold"
       size: 20
   }
   x: 20
   y: 20
   content: "Loading Image from NASA WebService..."
}

function run() {
s = Stage {
    title: "Nasa Image"
    width: 300
    height: 300
    fullScreen: true   
    scene: Scene {
        content: [
            loadingText,im, rect, close
        ]
    }
}
}

//LocationY.fx

package nasaimage;

import java.lang.Exception;
import javafx.data.pull.PullParser;
import javafx.data.xml.QName;
import javafx.io.http.HttpRequest;

/\*\*
 \* @author Vaibhav
 \*/

public class LocationY {
    public var urlImage:String;
    var url = bind "http://www.nasa.gov/rss/lg_image_of_the_day.rss";
    var p: PullParser;
    var h: HttpRequest;
    init {
        if (url.length() > 0) {
            h = HttpRequest {
                location: url
                onException: function(exception: Exception) {
                    print("Please check the internet connectivity or Data Input");
                }
                onInput: function(input) {
                    p = PullParser {
                        input: input
                        onEvent: function(event) {
                            if ((event.type == PullParser.END_ELEMENT)) /\* and (event.qname.name == "current_conditions")) \*/{
                                if (event.qname.name == "enclosure") {
                                    urlImage = event.getAttributeValue(QName{name:"url"});
                                 }
                            }
                        }
                    };
                    p.parse();
                    p.input.close();
                }
                onDone: function() {
                Main.vText = false;
                }
            };
            h.start();
        }
    }
}

Don't ask me why I am using LocationY.fx as filename. Sometime back, I made my first webservice with name LocationY and from that time, I am copying the same file.

Last day Photo was more awesome than this. I guess it was something related with stars :). As talked in the prev. blog about the use of OnDone() method, here it is. Before loading of image, you will see a text   'Loading Image from NASA WebService...'. This text vanishes when image get loaded because we have called its visible: false in OnDone() method of HTTP.

I hope you love this short code and start of webservices. Thanks to NASA website to provide this RSS feed :).

Sunday May 10, 2009

Take care of Basic User Interface - JavaFX

For a developer perspective, I always appreciate the work of Graphics Designer. Immense level of smoothness, simple though beautiful, delicacy in every movement and most important fulfill the functionality in most easier way. Though we all can't think like a UE or a Graphics Designer but we can maintain the correct functionality in code. Some code which I have seen in last one month are awesome but some simple points are missing not because they are tough to write but because we forgot to write.

1. Use the correct cursor when required :  Like if its a button or a Hyperlink, cursor should be Cursor.HAND like this code :

package cursorsample;

import javafx.scene.Cursor;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

Stage{
    title: "Button Cursor"
    width: 250
    height: 280
    scene: Scene{
        content: [
            Rectangle {
                cursor: Cursor.HAND
                x: 10,
                y: 10
                arcHeight: 10
                arcWidth: 10
                width: 100,
                height: 30
                fill: Color.BLACK
            },
            Text {
                fill: Color.WHITE
                font: Font {
                    name: "Arial Bold"
                    size: 14
                }
                x: 15,
                y: 30
                content: "Hand Cursor"
            }
        ]
    }
}

If you are navigating inside the map or graph or if you are dragging things out. Cursor is supposed to be Cursor.MOVE. Please check the complete list supported in FX: http://java.sun.com/javafx/1.1/docs/api/javafx.scene/javafx.scene.Cursor.html

2. Simple opacity Game : Changing the opacity with simple values can make the UI rich. Simple code like this :

var opacity = 0.6;

onMouseEntered: function( e: MouseEvent ):Void {
                    opacity = 1.0;
                }
                onMouseExited: function( e: MouseEvent ):Void {
                    opacity = 0.6;
                }

 and bind the opacity of rectangle with opacity variable.

3. Gradient give life : "My Button" is simple but you will find it much better than only Black or only GRAY. Same way, you can make it more rich with filling correct gradient. Most of the time we find it a problem in setting Gradient color. My simple formula says, take 2 color of same family and try to mix. Never mix color like RED and GREEN. Mix LIGHTGREEN and DARKGREEN, RED and DARKRED, BLUE and AQUA. Using these, we can see effects like this :


 4. Gradient at title bar -> I love to write custom title bar in place of OS defaults which always gives a feeling that I am living in old age. Color in title bar can be made cool with gradient like :

This is simple DARKGREEN, BLACK and DARKGREEN linear gradient. Though, I am misusing the close button concept here. Close button should not be green in color, preferable color is RED.

5. If we want it to be simple: If application itself is too complex and we want to minimize the cost of gradient, colors. Best is to go with simplicity. A black background with white text is one of the awesome combination. 

6. Web services or HTTP request : If we are using PullParser and HTTP, onDone method is one of the important places for everything. Consider on a button click you called a web service and web service takes sometime and showed the output. In the middle, you need to show a screen to user saying "We called this web service and it will take sometime", else user will impatiently close the window.

So, waitingText.visible = true when mouse click ! In onDone() {   waitingText.visible = false; }

Soon, we will have more example on this :).

That's it. 

Have fun with JavaFX !

Thursday Apr 30, 2009

Complex Animation = "n" Basic Animation

Some developers ask me "what is the future of JavaFX". Actually I can't say, because I am not a future maker. But yes it depends how honest your effort is, how consistent your effort is. We are doing best from our side. Talks apart, we have published some more article on JavaFX official site. Basic and awesome :).

1. In any RIA language which provide a great easiness for developer, one of the most important things you know is how to manage animation and so, timeline. Nancy, has written detailed article on how to play with timeline : "Animation Basics for JavaFX Beginners"

2. She has written one more article on Reloading Data. Actually reloading is a tricky part not in terms of mind but in terms of ways to do. Sometime, you want ball to be at initial position, sometime you want it to be at random position, sometime final position is initial position.

These 2 articles are related and both as one give a good picture of animation.

3. Very important to know this. How to run JavaFX Application offline. Thomas, guru of JWS, has written one article speaking about what all things to take care when you want JavaFX Appliation to run offline. As most of us know, JavaFX has lot to do with deployJava.js, Java Logo Image.

 Have Fun !

About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

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