Hacking on GraphHopper - a Java road routing engine. Peter has posted 62 posts at DZone. You can read more from them at their website. View Full User Profile

Reply via JavaFX on: Shadow Motion Effect in 5 Lines Of jQuery

04.23.2010
| 5659 views |
  • submit to reddit

I took the opportunity to see how easy or difficult it is to implement a “shadow motion effect” in JavaFX. The effect is described in a post from Lam Nguyen and he implements it in jQuery in 5 lines.

What do we need to do this in JavaFX? Is this possible at all?

Yes it is possible and it was easy, fast (~10 min) and IMHO it looks nice and it is not only an animation – you can drag it:

1. Create a new JavaFX project in NetBeans and choose ‘Drag and Drop’.

2. Then adapt the DragBehaviour to the following. The necessary changes are minimal and marked with HERE:

// HERE: change 1 line
public var targetGroup: Group;

public var targetWidth: Number;
public var targetHeight: Number;
public var maxX = 200.0;
public var maxY = 200.0;
var startX = 0.0;
var startY = 0.0;

init {
// HERE: +1 line
var target = targetGroup.content[0];

target.onMousePressed = function (e: MouseEvent): Void {
startX = e.sceneX - target.translateX;
startY = e.sceneY - target.translateY;
}

target.onMouseDragged = function (e: MouseEvent): Void {
var tx = e.sceneX - startX;

// HERE +7 lines
var cloned = Duplicator.duplicate(target);
insert cloned into targetGroup.content;
FadeTransition {
node: cloned fromValue: 1 toValue: 0 duration: 0.5s repeatCount: 1
action: function () {
delete cloned from targetGroup.content;
} }.play();

if (tx < 0)
tx = 0;

if (tx > maxX - targetWidth)
tx = maxX - targetWidth;

target.translateX = tx;
var ty = e.sceneY - startY;
if (ty < 0)
ty = 0;

if (ty > maxY - targetHeight)
ty = maxY - targetHeight;

target.translateY = ty;
} // onMouseDragged
} // init

 

3. Drag it yourself  or try it out now:

 

From http://karussell.wordpress.com/2010/04/22/reply-via-javafx-on-shadow-motion-effect-in-5-lines-of-jquery/

Published at DZone with permission of its author, Peter Karussell.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Sura Sos replied on Fri, 2010/04/23 - 9:16am

Has anyone done performance comparision agains the 2 ?

 

just kidding. Good article.

 

Thanks,

Jacek Furmankiewicz replied on Fri, 2010/04/23 - 10:22am in response to: Sura Sos

This is the first ever JavaFX example that actually impressed me and makes it look better than competitors.

Good job.

Mike P(Okidoky) replied on Fri, 2010/04/23 - 12:34pm

Ohhh, by the way.... while you were spending doing actual work, there is this yet another earth shattering ground breaking technology that you have to learn... Seriously though, is the industry/community insane or something? There is no freaking way people can keep up with all these different techniques and technologies. At the rate stuff is coming out, even just scratching the surface of them all is a 24/7 job in itself. Things are *so* convoluted now, that when you visit a users group of just about anything these days, masses of people are completely oblivious to actual useful great accomplishments, because they never even heard of it (pretty much), like, ohh, say, Java, for instance. Anyone here know lisp or smalltalk for instance? People thinking I'm nuts, consider this: http://www.youtube.com/watch?v=KHGcvj3JiGA ps. Thanks for providing a starting point, allowing me to scratch this surface as well - I do find these posts useful. I wonder if I push it into my brain, some other stuff falls out on the other end ;-)

Peter Karussell replied on Fri, 2010/04/23 - 1:43pm

@Surajz Sos

you are invited to do so!

@Jacek F

thanks a lot!

@Mike P

relax and relinquish!!


 

Mike P(Okidoky) replied on Fri, 2010/04/23 - 2:33pm in response to: Peter Karussell

"relinquish"... the arrogance of the youngsters these days. You realize that your position makes you quite inferior, right?

Peter Karussell replied on Sat, 2010/04/24 - 1:09pm

no arrogance intented, sorry. then I think we completely misunderstood us. maybe this is because english it is not mother mother tongue.

BTW: I am not a youngster (hope you don't mean this arrogant ;-)). 

Mike P(Okidoky) replied on Sun, 2010/04/25 - 12:20am in response to: Peter Karussell

Hi Peter, with you saying "relinquish" I had the impression that you were a young person that thinks that the older people (I'm not even that old) should hand over their jobs and make room for new young people, that think they deserve it because they simply think they're entitled to it. I misunderstood you. My original point was that the "world" is creating too many technologies for people to keep up with. A lot of very good values completely are overlooked by new comers, such as smalltalk, lisp, the early parsers, etc. People are trying to make careers based on Flex, dot net, etc, but they are not seeing all the great accomplishments that have been made in the history of computing.

Peter Karussell replied on Sun, 2010/04/25 - 5:32am

> I had the impression that you were a young person that thinks that the older people (I'm not even that old) should hand over their jobs and make room for new young people

ups, no! I meant: there are a lot of technologies out there. every programmer will have to concentrate only on a few ones otherwise he can only scratch on the surfaces! E.g. I love to program algorithms in Java, but I am interested in UI stuff too. BUT there is so much other interesting stuff that I cannot do in my free time: robotics, mobile computing, 3d, ...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.