>

Vaibhav's Blog Space

Sorting and OpenJDK

Wednesday Nov 25, 2009

If you are looking for sorting algorithms and if you use some sorting algorithm in your code/application/big application, then have a look here. First of all sorting/searching is a classic thing. It take more than 70 percent of your application time.People/Developer/Mathematician do a lot of work on optimizing this work to get Best, best out of best.

Early days, JDK used to use QuickSort which is one of the best sorting algorithm and go for a complexity of O(nlogn). But mind it, QuickSort is a recursive algorithm and consume space. Whereas some of the algorithm which has the complexity like O(n^2) go for less complex in terms of memory. These days our platform varies from small mobile device to a terabyte storage machine............

[Read More]

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Bangalore Open JavaFX User Group

Thursday Oct 29, 2009

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]

[4] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

shape intersection/subtraction result - JavaFX

Wednesday Sep 23, 2009

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.


[2] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Small presentation on Cloud Computing

Wednesday Sep 16, 2009

Sorry this blog is nothing related with Java or JavaFX !

Some day back, I have given one small presentation on Cloud Computing in PESIT, Bangalore. Quite enthu students and ready to face the challenges of world. 

You can see/use presentation here:  Presentation


[2] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Debugging basics and some link - Java

Monday Aug 24, 2009

Some simple debugging tools related to Java. These are for those who are new to Java.

1. Application is crashing : Most miserable one. Get your log file, try to analysis log. How to write log file, use Java Logger API.  Java Logger had been introduced in JDK 1.4.2. The most awesome feature of  Logger API is that you can use it in production without much overhead. The overhead is controlled by something called level in API. Level goes from FINEST to SEVERE. You can refer to O'Relly Book "Java, In a NutShell". I guess. ...........

[Read More]

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Netbeans Java Presentation

Wednesday Aug 12, 2009

Small presentation(actually very small) on Netbeans and Java. Mostly covers the features, netbeans provide for Java SE. Like Profiling, Debugging..

http://blogs.sun.com/vaibhav/resource/BasicOfNetbeans_Java.pdf



[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

User experience - More rich !

Tuesday Aug 11, 2009

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 !

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Progress Indicator - JavaFX !

Sunday Aug 02, 2009

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]

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Use of ListView - UI Control

Thursday Jul 30, 2009

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]

[2] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Simple example of Scroll Bar - JavaFX 1.2

Tuesday Jul 28, 2009

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]

[5] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Hyperlink to URL

Sunday Jul 26, 2009

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]

[11] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Small code for PieChart...but !

Tuesday Jun 30, 2009

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 :



[4] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Browser + Drag + Feature + JavaFX + Profile + Many more :)

Thursday Jun 18, 2009

Final destination for us is death and final destination of a JavaFX application is Browser. So, we should know what all things we can do with an application, JavaFX application, in browser.

Here are some :

1. Understand when our code will run on browser and when on Desktop/Mobile and optimize the code. Here is a small one :

package appletshow;

import javafx.scene.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;

/**
 * @author Vaibhav Choudhary
 */

var textContent = "Hello JavaFX in applet World";
var subtext = "Drag me out for this example(Alt->Drag)";
var vis = false;
var s: Stage = Stage {
    title: "Applet Show"
    width : 600 height : 200
    style: StageStyle.TRANSPARENT
    scene : Scene {
            fill: Color.BLACK
            content: [
                Text { content: textContent
                       x: 25 y:35 fill: Color.WHITE
                       font: Font{size: 24}
                }
                Text { content:  subtext
                       x: 25 y:55 fill: Color.WHITE
                       font: Font{size: 14}
                }

                Rectangle { x: 560 y: 10 width: 20 height: 20
                            arcHeight:5
                            arcWidth: 5
                            stroke:Color.GRAY
                            strokeWidth: 2
                            fill: Color.TRANSPARENT
                            visible: bind ("{__PROFILE__}" != "browser")
                            onMouseClicked: function(e: MouseEvent): Void {
                                s.close();
                            }
                }
                Text {
                    fill: Color.WHITE
                    visible: bind ("{__PROFILE__}" != "browser")
                    font : Font {
                        name:"Arial Bold"
                        size: 14
                    }
                    x: 567, y: 25
                    content: "x"
                }
                ,
            ]
    }
}

Close button will be visible only in browser not in desktop/mobile. So, this is logical, close button should not be in Browser.

2. Remeber, we have draggable feature and things can change from applet inside the browser and when it has been dragged out :).

Now, I want again that when I dragged my applet out of the browser, I get a close button which is logical again, because a dragged application is like a desktop application. So, here we go :)


package appletshow2;

import javafx.scene.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;

var textContent = "Hello JavaFX in applet World";
var subtext = "Drag me out for this example(Alt->Drag)";
var vis = false;
var s: Stage = Stage {
    title: "Applet Show"
    width : 600 height : 200
    style: StageStyle.TRANSPARENT
    scene : Scene {
            fill: Color.BLACK
            content: [
                Text { content: textContent
                       x: 25 y:35 fill: Color.WHITE
                       font: Font{size: 24}
                }
                Text { content:  subtext
                       x: 25 y:55 fill: Color.WHITE
                       font: Font{size: 14}
                }

                Rectangle { x: 560 y: 10 width: 20 height: 20
                            arcHeight:5
                            arcWidth: 5
                            stroke:Color.GRAY
                            strokeWidth: 2
                            fill: Color.TRANSPARENT

                    visible: bind vis
                            onMouseClicked: function(e: MouseEvent): Void {
                                s.close();
                            }
                }
                Text {
                    fill: Color.WHITE
                    visible: bind vis
                    font : Font {
                        name:"Arial Bold"
                        size: 14
                    }
                    x: 567, y: 25
                    content: "x"
                }
                ,
            ]
    }
    extensions: [
        AppletStageExtension {
            onDragStarted: function() {
                vis = true;
            }
            onAppletRestored: function() {
                vis  = false;
            }
            useDefaultClose: false
        }
    ]
}

Points to remember : a. useDefaultClose : false, it will vanish the default close button else it will be a mess, seeing too many close buttons. b. AppletStageExtension has lot of other features, please check the API. c. Close button should vanish once it goes back into the browser. 

3. Ah, now most important about dragging feature. I don't want to drag applet with Alt-> Drag feature, I want it should be draggable in simple style like we do with other application, NO COMPLICATION. Use this :)



package shoulddrag;

import javafx.lang.FX;
import javafx.scene.input.MouseEvent;
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.AppletStageExtension;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;

/**
 * @author Vaibhav Choudhary
 */

var isApplet = "true".equals
(FX.getArgument("isApplet") as String);
var inBrowser = isApplet;
var dragRect: Rectangle;
var draggable = AppletStageExtension.appletDragSupported;
dragRect = Rectangle {
    x: 0
    y: 0
    width: 240
    height: 40
    opacity: 0.5
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                color: Color.BLACK
                offset: 0.0
            },
            Stop {
                color: Color.WHITE
                offset: 0.3
            },
            Stop {
                color: Color.BLACK
                offset: 1.0
            },

        ]
    }
    onMouseDragged: function(e:MouseEvent):Void {
        print(inBrowser);
        stage.x += e.dragX;
        stage.y += e.dragY;
    }
};
var dragTextVisible = bind draggable and dragRect.hover;
var can_drag_me_text: Text = Text {
    content: "You can drag me !"
    fill: Color.BLACK
    font: Font {
        size: 12
        embolden: true
        name: "Arial Bold"
    }

    opacity: 1.0
    visible: bind dragTextVisible
    y: 20
    x: 15
};
var stage = Stage {
    title: "Should Drag"
    width: 250
    height: 280
    style: StageStyle.TRANSPARENT
    scene: Scene {
        content: [
            dragRect,
            Rectangle {
                x: 0,
                y: 40
                width: 240,
                height: 290
                fill: Color.BLACK
            },
            can_drag_me_text
        ]
    }
    extensions: [
        AppletStageExtension {
            shouldDragStart: function(e): Boolean {
                return e.primaryButtonDown and dragRect.hover;
            }
            onDragStarted: function(): Void {
                inBrowser = false;
            }
            onAppletRestored: function(): Void {
                inBrowser = true;
            }
            useDefaultClose: true
        }
    ]
}

Some complication are in code, but be relaxed and see, too easy, RIGHT ? Alright ! What more we can add here...

Please let me know if there is any issue with any of the code. Thanks !

[5] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

JavaFX Production Suite - Usages

Tuesday Jun 09, 2009

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.

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

New Controls - Chart API in JavaFX 1.2

Friday Jun 05, 2009

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.

[6] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg