Progress Indicator - JavaFX !
Sunday Aug 02, 2009
Probably I missed something. But this is the way we can add indefinite progress indicator with any unpredictable events. Here I am just calling a Web service to show yahoo maps for NY city.
Here how progress indicator looks like :
Progress Indicator is very small :
var pi = ProgressIndicator {
scaleX: 2
scaleY: 2
translateX: 90
translateY: 110
progress: -1
visible: bind vLoad
};
Make visibility false when Map is loaded. So, vLoad: false in:
onDone: function() {
Main.status = "Done ...";
Main.vLoad = false;
}
Somehow, I am not getting such a good result. I guess, progress thread stuck when Data loading start. May be because one single thread is doing both work.
Here is the code :
package progressbarshow;
import java.lang.Math;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import progressbarshow.MapLocate;
var pi = ProgressIndicator {
scaleX: 2
scaleY: 2
translateX: 90
translateY: 110
progress: -1
visible: bind vLoad
};
public var status: String = "Start Loading Data...";
var ml: MapLocate = MapLocate{zip:"10001"}; // 10001 - Newyork, i guess
var x1: Number = 0;
var y1: Number = 0;
var im: Image = bind Image {
url: ml.location
}
public var vLoad = true;
var loadingText = Text {
visible: bind vLoad
font: Font {
size: 12
}
x: 30,
y: 70
content: bind status
}
/* Image of the map from Yahoo WS */
var imview = ImageView {
cache: true
translateX: bind x1
translateY: bind y1
image: bind im
cursor: Cursor.MOVE
/* Navigation from Mouse event*/
onMouseDragged: function( e: MouseEvent ):Void {
if(e.dragX < 0 and x1 < 0) {
x1 = x1 + 5;
}
if(e.dragX > 0 and Math.abs(x1 - 240) < im.width) {
x1 = x1 - 5;
}
if(e.dragY < 0 and y1 < 0 ) {
y1 = y1 + 5;
}
if(e.dragY > 0 and Math.abs(y1 - 320) < im.height) {
y1 = y1 - 5;
}
}
/* Navigation from key event */
onKeyPressed: function( e: KeyEvent ):Void {
if(e.code == KeyCode.VK_LEFT)
{
if(x1 < 0) {
x1+=10;
}
}
if(
e.code == KeyCode.VK_RIGHT)
{
if(Math.abs(x1 - 240) < im.width) {
x1-=10;
}
}
if(
e.code == KeyCode.VK_DOWN)
{
if(Math.abs(y1 - 320) < im.height) {
y1-=10;
}
}
if(e.code == KeyCode.VK_UP)
{
if(y1 < 0) {
y1+=10;
}
}
}
};
function run() {
Stage {
title: "Yahoo Map Navigation"
width: 240
height: 320
scene: Scene {
content: [
loadingText, imview, pi
]
}
}
}
Navigation Code:
package progressbarshow;
import java.lang.Exception;
import javafx.data.pull.PullParser;
import javafx.io.http.HttpRequest;
/* Class to show Map from Yahoo Web service, input zip code */
public class MapLocate {
public var location: String;
public var zip: String;
public var isguid: Boolean = false;
var url = bind "http://local.yahooapis.com/MapsService/V1/mapImage?appid=P6pToNnV34GfP9zgTALgVW3CUTL5qHTnKjz5bLXPikqNjcMZTkF6h1xsnhm.P1WIs3U-&zip={zip}";
var p: PullParser;
var h: HttpRequest;
init {
if (url.length() > 0) {
Main.status = "Reading HTTP
h = HttpRequest {
location: url
onException: function(exception: Exception) {
print("Please check the internet connectivity/Data Input");
}
onConnecting: function() {
Main.status = "Connection Established ... "
}
onInput: function(input) {
Main.status = "Parsing Input
p = PullParser {
input: input
onEvent: function(event) {
if ((event.type == PullParser.END_ELEMENT)) {
if (event.qname.name == "Result") {
isguid = true;
location = event.text;
}
}
}
};
p.parse();
p.input.close();
}
onDone: function() {
Main.status = "Done ...";
Main.vLoad = false;
}
};
h.start();
}
}
}















It was a very nice idea! Just wanna say thank...