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

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 !

Comments:

good...

Posted by yoursubtitle on June 18, 2009 at 11:55 AM IST #

The problem is that while i use useDefaultClose : false, the default button is still appearing.
Also i was wondering if there is a way to determine if the applet is in or out of the browser (I am using AppletStageExtension.appletDragSupported but it doesn't seem to work when i am starting the application via the desktop shortcut).

Posted by Erevodifwntas on August 28, 2009 at 07:34 AM IST #

For me useDefaultClose: false, will not show any close button. If this is the case, I will raise a bug. Can you tell me which SDK version you are using ?

onDragStart, onAppletRestore .. you can use these 2 to get when applet is out of browser !

Posted by Vaibhav Choudhary on August 28, 2009 at 07:51 AM IST #

Well, i am using javaFX sdk1.2 (the one that comes with NetBeans 6.7.1 with build number 233).
The thing with onDragStart, onAppletRestore is that they work only if you have already determined if you are in a browser or not. What happens if someone has installed the applet to his machine and is starting it via the desktop shortcut.

P.S. Your blog is the best source of information on JavaFX!!! Keep up the excellent work!!!!

Posted by Erevodifwntas on August 28, 2009 at 08:16 AM IST #

Hmm, we need to have something for this. I will raise feature or bug for this. Thanks for raising this point.

thanks !

Posted by Vaibhav Choudhary on August 31, 2009 at 07:48 AM IST #

This is great news. Best of luck for the future and keep up the good work.

Posted by China Wholesale on January 09, 2010 at 04:45 AM IST #

I will raise feature or bug for this. Thanks for raising this point.

Posted by av oyunları on January 19, 2010 at 08:39 PM IST #

I have enjoyed reading, I will make sure and bookmark this page and be back to follow you.

Posted by charleston forge furniture on January 25, 2010 at 05:32 PM IST #

[URL=http://www.christianlouboutinshoes.me]Christian Louboutin Shoes[/URL]
[URL=http://www.christianlouboutinshoesstore.com]Christian Louboutin Shoes[/URL]
[URL=http://www.christianlouboutinshoesmart.com]Christian Louboutin Shoes[/URL]

Posted by may on February 01, 2010 at 04:24 AM IST #

The state's <a href=http://www.mynikeairmax.com/>Nike Air Max</a> decision in October to shrink the school <a href=http://www.mynikeairmax.com/>Air Max </a> year by 10 percent, giving it the fewest number <a href=http://www.mynikeairmax.com/>Air Max 90</a>of instructional days in the nation at 163<a href=http://www.mynikeairmax.com/>Air Max 95</a>, is adding to the already dismal reputation Hawaii's<a href=http://www.mynikeairmax.com/>nike Air Max 95</a> public schools have among<a href=http://www.mynikeairmax.com/>nike Air Max 90</a> servicemen and womenCol. Mike Davino, the director of<a href=http://www.mynikeairmax.com/>Air max ltd </a> manpower, personnel and administration<a href=http://www.mynikeairmax.com/>Air Max shoes </a> for the U.S. Pacific Command, said the truncated school year is yet another concern for officials who have long heard about servicemen and women avoiding Hawaii assignments because of the state's public education system.

Posted by air max on February 01, 2010 at 04:48 AM IST #

Christian Louboutin http://www.christianlouboutinmarts.com
Christian Louboutin Shoes http://www.christianlouboutinmarts.com
christian louboutin sale http://www.christianlouboutinmarts.com
Christian Louboutin Boots http://www.christianlouboutinmarts.com
Christian Louboutin Pumps http://www.christianlouboutinmarts.com
Christian Louboutin Sandals http://www.christianlouboutinmarts.com
tiffany wholesale http://www.toptiffanylinks.com
tiffany stores http://www.toptiffanylinks.com
replica tiffany http://www.toptiffanylinks.com
cheap jewelry http://www.toptiffanylinks.com
replica tiffany retail http://www.toptiffanylinks.com
pandora jewelry http://www.toptiffanylinks.com
replica pandora jewelry http://www.toptiffanylinks.com
ed hardy http://www.ed-onlineshop.com
ed hardy clothing http://www.ed-onlineshop.com
ed hardy t shirt http://www.ed-onlineshop.com
ed hardy jeans http://www.ed-onlineshop.com
wholesale ed hardy http://www.ed-onlineshop.com
ed hardy shirt http://www.ed-onlineshop.com
ed hardy boots http://www.ed-onlineshop.com
ed hardy swimwear http://www.edhardydream.com
ed hardy clothing http://www.edhardydream.com
ed hardy clothes http://www.edhardydream.com
ed hardy t shirts http://www.edhardydream.com
ed hardy jeans http://www.edhardydream.com
ed hardy sunglasses http://www.edhardydream.com
ed hardy sunglass http://www.edhardydream.com

Posted by china wholesale on March 07, 2010 at 01:56 AM IST #

I would like to introduce a very good company, electronic products dealer.
I have bought some products from company,the price was very cheap,and the products are very good quality!They accept paypal, credit card transactions,bank transfers,and more.Just have a look at this web page : http://www.nike-airyeezy.com
I am sure you will could save a lot of money!
Best regards!
web: http://www.victoriawear.com
http://www.homybuy.com

Posted by wwwnice on March 09, 2010 at 06:16 AM IST #

I am a new learner to JAVAFX . Please give me any good books or site names for learning JavaFx by my won

Posted by Ram on April 14, 2010 at 04:33 AM IST #

I am new to Java/JavaFx but I do appreciate what you provided here. It's a great way to start learning this JavaFx

Posted by used stationary bikes on July 27, 2010 at 09:20 AM IST #

I am new to Java/JavaFx but I do appreciate what you provided here. It's a great way to start learning this JavaFx

Posted by MicroConsole on October 11, 2010 at 04:38 PM IST #

Excellently written article, if only all bloggers offered the same content as you, the internet would be a much better place. Please keep it up!

Posted by hookah on January 19, 2011 at 03:46 AM IST #

I am a new learner to JAVAFX . Please give me any good books or site names for learning JavaFx by my won

Posted by tütünex on February 12, 2011 at 06:06 AM IST #

Post a Comment:
Comments are closed for this entry.
About

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

Search

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