/* * InfiniteProgressPanel.fx * * Created on Dec 3, 2008, 10:03:03 AM */ package progressbar; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.CustomNode; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.paint.Paint; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextOrigin; import javafx.scene.text.Font; import javafx.animation.Timeline; import javafx.animation.Interpolator; import javafx.scene.shape.Rectangle; /** * @author jclarke */ public class IndeterminateProgressBar extends CustomNode { public var text:String; public var width:Number; public var height: Number; public var background: Paint = Color.rgb(153,153,204); public var foreground: Paint = Color.WHITE; public var font = Font{name: "Dialog" size: 16}; public var borderWidth: Number = 1; public var cursorWidth = bind width / 5; // used for text geometry var geomText = Text { content: bind text font: bind font }; var cursorX: Number; var timeline = Timeline { repeatCount: Timeline.INDEFINITE autoReverse: true keyFrames: [ at(0s) { cursorX => 0 + borderWidth; } at(1.5s) { cursorX => width-2*borderWidth - cursorWidth; } ] }; var showing = bind visible on replace { if(showing) { timeline.play(); }else { timeline.stop(); } } public override function create(): Node { var cursor: Rectangle; return Group { content: [ Rectangle { width: bind width height: bind height fill: Color.TRANSPARENT; stroke: bind foreground strokeWidth: bind borderWidth arcWidth: 5 arcHeight: bind height cache: true }, cursor = Rectangle { translateX: bind cursorX translateY: bind borderWidth + 2 width: bind cursorWidth height: bind height - borderWidth*2 - 4 arcWidth: 5 arcHeight: bind height - borderWidth*2 - 4 fill: bind background cache: true }, Text { x: bind width/2 - geomText.boundsInLocal.width/2; y: bind height/2 + geomText.boundsInLocal.height/2; textOrigin: TextOrigin.BOTTOM font: bind font stroke: bind background fill: bind background content: bind text }, Text { x: bind width/2 - geomText.boundsInLocal.width/2; y: bind height/2 + geomText.boundsInLocal.height/2; textOrigin: TextOrigin.BOTTOM font: bind font stroke: bind foreground fill: bind foreground content: bind text clip: bind cursor }, ] }; } } function run(args:String[]):Void { var stage:Stage = Stage { title: "Indeterminate Progress Bar" scene: Scene { width: 920 height: 60 content: IndeterminateProgressBar { translateX: 10 translateY:10 width: 890 height: 35 text: "Loading..." } } } }