Wednesday, May 26, 2010

Yet another JavaFX App !

This application has won the RIA Exemplar Challenge Award organized by Java Champion Jim Weaver, Stephen Chin and Jasper Potts check the winner announcement here and here

Being a Java EE developer,I am always attracted towards the "grass on the other side" :P . I have been working on a JavaFX app, which tries to solve a typical engineering problem of loading cargo containers to a BeechCraft 1900C cargo airplane. Although the aircraft data and equations are taken from the authentic FAA weight and balance handbook (see Chapter 7 , page 60) , this application is not intended to be used for realtime cargo loading as it is just for JavaFX demo purposes and does not guarantee the accuracy of data and calculations. I must say again, being a newbie to the language its fun to learn JavaFX. Although I still regret not visiting Amy Fowlers blog post during the early stages of this app . Shown below is the screen-shot of the work done till date. Shown on the upper left side of the screen-shot are cargo containers which are supposed to be loaded on the horizontal cross section of Beechcraft main deck shown on the center-top. The parallel red blocks denotes left and right position of sections where cargo containers can be placed. Just below the red blocks is a scale which shows the section names and their distance in inches from a reference point referred as 'Datum' which in our case is aircraft's nose. So starting from Nose at 0 inches from datum , the tail of the aircraft is at 533 inches. The cargo containers are of different weights which can be seen by a mouse-hover tool-tip. User can drag these containers and place it on the aircraft's deck , which recalculates the center of gravity of the aircraft. The line chart on the lower right is Weight vs CG chart.It is actually combination or 3 overlapped line charts, One is in which the polygons are drawn, 2nd is with no data , but with X and Y axis on opposite sides, and the 3rd one contains just one yellow dot. The polygons drawn inside these charts are operational center of gravity limits defined by aircraft manufacturer. The yellow dot in the chart denotes the current center of gravity of the aircraft which gets updated when you place a container on the deck, The yellow dot(CG) should fall within these polygons (operational limits), otherwise the aircraft is either nose heavy or tail heavy. The data grid in the center is the XTableView control from JFXtras library (they have some nice controls and utilities for JavaFX). Parameters in this table are dynamically updated when the container is placed on the deck . The pie-chart on the lower left shows the total traffic weight of an aircraft by showing weight covered by each section of the deck. You can also click on these charts to get a larger view. Double click the dropped container to revert it back from the deck to the container panel. Just below the Main Deck is a JavaFx Toolbar component which contains normal and toogle buttons styled using an external CSS file. A user can revert back all the placed containers by clicking on the "Reset Containers" button. The animation on drag-drop can be toggled using the "Disable Animation" button on the toolbar. By default weight of each cargo containers can bee seen on the tool-tip displayed by the mouse-hover, optionally one can choose to quick view/hide weights on the containers by toggling the "View Weights" . Do check out the help and about buttons for more information about the application.



I am improving this application when ever I get free time and I will be updating the source code to JFxtras repository to ensure its compatibility with future releases of JavaFx Please let me know your valuable feedback.

Thursday, February 18, 2010

My first experience with JavaFx Charts

In one of my previous projects I was involved in developing a 2D line chart which shows the center of gravity of large cargo aircrafts like Airbus A380 and Boeing 747 etc .We used Java2D with more than a thousand lines of code and Richfaces paint2D to draw it as an image on a JSF web page .Being a newbie to the language, I was just wondering how much effort can it take to develop such a chart in JavaFx . I finally managed some time to try it out. So this chart is a Weight vs. Index chart where weight of the aircraft is on the y-axis and change in center of gravity index is on the x-axis. The polygons drawn inside the chart reflect the structural limits of an aircraft. If your current (index,weight) point falls outside these polygons in a certain condition, than the aircraft cannot fly because it is either nose-heavy or tail-heavy so it will crash.

I was able to create the chart shown in the image above with almost 105 lines of code excluding the data inputs,in almost 3 hours. JavaFX charting takes care of drawing axis and tickmarks, tickmark gaps, axis and axis-label gaps, scaling factors, title, legend attributes and many more things like anti-aliasing and drop shadows. You just need to bother about configuring it and providing the chart data.


Launch it here. Launch Image

Download source code