The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Richard Bair

Richard is a longtime speaker and member of the Swing Team at Sun Microsystems. He has his roots as an application developer turned toolkit developer and is the lead of the component toolkit API for JavaFX. He is a frequent presenter and teams up frequently with other UI luminaries to produce demos for JavaOne and other conferences. As an application developer he had a specific penchant for databases and multi-tier design,

 

Richard Bair's blog

Keep your FX Code Clean (My version)

Posted by rbair on March 24, 2009 at 11:54 AM PDT
The Exploding Pixels blog has an entry on clean FX code formatting. I didn't really like the options provided so far, so I decided to write a quick blog with my version.
def backgroundImage = Image { url: "{__DIR__}background.png" };
var verticalPositionOfLine:Number;

var s = Stage {
    title: "Background Image"
    scene: Scene {
        width: 200
        height: 232
        content: [
            ImageView { image: backgroundImage },
            // Paints two moving lines
            Group {
                translateY: bind verticalPositionOfLine
                content: [
                    Line { startX:0, startY:20, endX:200, endY:0, stroke:Color.RED }
                    Line { startX:0, startY:30, endX:200, endY:10, stroke:Color.RED }
                ]
            }
        ]
    }
}

// Start the line animation
Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
      at (0s) { verticalPositionOfLine => -20 }
      at (3s) { verticalPositionOfLine => 200 tween Interpolator.LINEAR }
    }
}.play();
s
Comments
Comments are listed in date ascending order (oldest first)

Nice...I think your version of the code is quite readable. -Ken
Syndicate content