« Previous month (Mar 2009) | Main | Next month (May 2009) »

20090429 Wednesday April 29, 2009

JavaFX editing tips!

The NetBeans support for editing JavaFX isn't as mature as for other languages. After working with it for a little bit I've figured out a few things you might find helpful:

(2009-04-29 17:42:49.0) Permalink Comments [3]

20090427 Monday April 27, 2009

Nice touch, Skype!

I work from home, so I rely heavily on Instant Messaging and IRC to communicate with my co-workers, and for video conferencing I use Skype.

I sometimes make typing mistakes. And if the typo is particularly embarrassing, to the extent that I want to fix it to show that I know better, I usually write something like this:

   12:00   I agre.
   12:00   s/agre/agree/
Anybody with vi experience or even sed experience will recognize the second line as a search/replace command, so I'm really saying "I said agre but I meant agree". It's reflex at this point - I'll do it for the most minor accident.

I usually only use Skype for video conferencing, not instant messaging. But I just discovered, by accident, that Skype does something wonderful. Instead of showing my substitution command, it applies it to the previous line, instantly, on both sides of the conversation! Look at this:



Ugh, typo, reflexively type s/foo/bar



Voila:



Instead of adding my correction command to the log for the viewer to interpret, it just edited the previous command in place. If I can type this quickly enough, perhaps the reader won't notice!

Chatzilla, Adium, Others - Please please please do this too!

P.S. On the topic of terminal conventions.... I like using ^H's as a "just kidding" device:

   12:00   Ok, I'll slap^H^H^H^H tell him about it. 
Anyone who's logged into terminals with wrong tty settings will recognize the ^H's as failed backspaces... And I don't want IM clients processing these :)

(2009-04-27 13:34:28.0) Permalink Comments [3]

20090424 Friday April 24, 2009

Catchup

A lot of stuff is happening these days, so here are some quickies... is this what people use Twitter for?

(2009-04-24 13:42:18.0) Permalink

20090407 Tuesday April 07, 2009

Add Effects to the right Container!

The Flubber application I described earlier has an old stop-watch style timer with second and minute hands:



Making the clock hand move was trivial using value binding and a rotation transform on the hand graphics object:

transforms: Rotate {
    angle: bind (360.0 / 60 * minutes) - 90.0
}
Since we are using a binding expression, setting the minutes variable anywhere (and yes, assigning to it!) will cause the hand angle to be recomputed and the graphics updated.

Anyway - once we had the clock moving, the first thing we wanted to do was improve the look of the clock by adding a drop shadow. That was trivial; all we had to add was this:
effect: DropShadow {
    offsetX: 5
    offsetY: 5
    color: Color.BLACK
    radius: 10
}
That looked pretty good:



But look what happened when we let the timer run... Where is the light source?



What's happening here is that the drop shadow is rotating with the hand. Not what we want. We were all learning JavaFX that day, so we hacked it, using the following code:
effect: DropShadow {
    offsetX: bind Math.sin(Math.toRadians(handAngle + 45)) * 5.0
    offsetY: bind Math.cos(Math.toRadians(handAngle + 45)) * 5.0
    color: Color.BLACK
    radius: 10
}
Now, the drop shadow offset moves along with the rotation such that the shadow always appears in the right place. It worked, and we moved on.

Now that I understand JavaFX and the scenegraph a bit better I realize that this approach is wrong - there's a much simpler solution! We don't want to apply the drop shadow to the Path object directly, since the path is what we are rotating with our minute angle. Instead, we should simply move the effect out to the surrounding parent. That will apply the drop shadow after the shape has been rotated. Doing that, we can set our drop shadow initialization back to the original simple 5,5 delta, and we get exactly the result we want:



So, think about which node you apply effects to! And by the way, the effects framework is really fun to play with - you should definitely explore javafx.scene.effect.* !

(2009-04-07 19:38:57.0) Permalink