Monday, November 26, 2007

JAXX and JFreeChart

JAXX is an XML-based user interface framework for developing Swing applications. As such, JAXX looks and feels like OpenLaszlo's LZX language and Flex's MXML language. Like LZX and MXML, JAXX code is written primarily in XML and supports scripting in special tags within the XML. In the case of JAXX, the scripting language is Java (compared to a JavaScript subset for OpenLaszlo and to ActionScript 3 for Flex 2 MXML).

JAXX shares other characteristics with OpenLaszlo LZX and Flex MXML. All three frameworks support an id attribute to uniquely identify each tag in the XML. The id attribute provides a handle for code in the script to access what is in the XML elements. JAXX also supports data binding, a very nifty feature of both Flex MXML and OpenLaszlo LZX. In fact, its syntax is exactly like Flex's MXML binding syntax (use of curly braces { and } around binding) and very similar to OpenLaszlo's LZX binding syntax (curly braces with $ in front similar to Ant).

In our article Visualize Your Oracle Database Data with JFreeChart, Michael Martin and I demonstrated an extremely simple example of using JFreeChart in conjunction with a Swing application (Code Listing 4 and Figure 7). In this blog entry, I will be adapting that example to use JAXX rather than direct Swing (JAXX compiles into Swing).

JAXX can be downloaded at http://www.jaxxframework.org/wiki/Download and can be installed as described at http://www.jaxxframework.org/wiki/Installing_JAXX. The version of JAXX that I used for this example is JAX 1.0.2. The zip file you download for this is well under 1 MB. Installation consists of unzipping the downloaded file (expanded directories and files still come in under 1 MB), setting JAVA_HOME to point to your JDK directory (this may already be the case on your system for Ant or other Java-based applications to use), and placing the JAXX installation's bin directory in your environment's path.

The following code listing shows the JAXX code for my file jaxxexample.jaxx (notice the extension .jaxx).

<Application title="Jaxx Example Using JFreeChart"
width="750"
height="450">
<JLabel id="mainLabel"
icon="{generateBarChartImage()}" />
<script>
private ImageIcon generateBarChartImage()
{
org.marx.hr.charting.HrChartCreator chartCreator =
new org.marx.hr.charting.HrChartCreator("");
org.jfree.chart.JFreeChart barChart =
chartCreator.createSalaryPerFinanceEmployeeBarChart(
org.jfree.chart.plot.PlotOrientation.VERTICAL );
return new ImageIcon(barChart.createBufferedImage(750,450));
}
</script>
</Application>


The above code is compiled using the following syntax (assuming that JAXX has been downloaded and installed as described previously):


jaxxc -cp "C:\jfreechart\articleSourceCode\visualizeOracleDb\build\classes;C:\jfreechart\jfreechart-1.0.7\lib\jfreechart-1.0.7.jar" -keep jaxxexample.jaxx


There are several things worth special mention regarding the jaxxc compilation shown above.

First, jaxxc works much like javac in terms of available options. The -keep option keeps the intermediate .java files and another option (-java, not shown here) only generates the .java files without building the corresponding .class files.

Second, I needed to place quotation marks around my classpath after the -cp if I had more than one path in the classpath designation. A single path in the classpath worked appropriately (compiled), but having more than one without the quotes led the JAXX compiler to showing its usage instead of compiling the .jaxx file. For this example, I did need two paths: one to the Java class with the chart generation code and one to the JFreeChart library.

After the .class files have been generated (and in this case, the .java file was retained as well), the code needs to be run to show JAXX in action. The following command was used to run this code:


java -cp .;C:\jaxx-1.0.2\lib\jaxx-runtime.jar;C:\jfreechart\articleSourceCode\visualizeOracleDb\build\classes;C:\jfreechart\jfreechart-1.0.7\lib\jfreechart-1.0.7.jar;C:\jfreechart\jfreechart-1.0.7\lib\jcommon-1.0.12.jar;C:\batik-1.7\batik.jar;C:\iText\itext-2.0.2.jar;C:\jdevstudio1111\jdbc\lib\*;C:\jdevstudio1111\lib\* jaxxexample


The highlighted portion of the classpath shows that the JAXX runtime JAR is necessary for running this code compiled with jaxxc. Several other libraries must be added to this classpath as well because the included chart generation class access iText (for PDF), Batik (for SVG), and JDeveloper (for Oracle datasource) libraries. Notice that no quotations are needed for multiple paths in this classpath because this is a normal Java launcher executable. Quotes are not needed for Java's javac and java commands to use multiple paths in their classpaths.

When the above command is run with the Java application launcher, output similar to that shown in the next snapshot should be displayed (click on image to see larger version):



Not surprisingly, this image looks very similar to that in Figure 7 of the article that was generated with straight Swing. This is not surprising because JAXX compiles first to Swing. Ideally, I'd have most of the code in the <script> tag in the JAXX example in a separate Java class so that very little scripting would be in the file and it would be almost all XML.

There is much more to JAXX than what is shown here. This blog entry is merely an introduction to an approach to non-web Java HMIs that is very similar to that used in OpenLaszlo and Flex.

I have just started to investigate JAXX, but have already made a few observations in addition to those listed above that are worth consideration.

  • Perhaps the best method for further investigating JAXX is to read the newbie-friendly article Introducing JAXX: A New Way To Swing. This article is written by JAXX's author, Ethan Nicholas.

  • Ethan Nicholas also presented on JAXX at JavaOne 2006: User Interfaces in XML: The JAXX Framework.

  • It appears that JAXX has not been significantly supported in over a year. The last "News" release on the main page (as of today, November 26, 2007) is dated October 9, 2006, and announces the release of JAX 1.0.3-beta (I'm using JAXX 1.0.2 final for this article and that was announced in August 2006). Similarly, the most recent entry in the JAXX Announcements Forum is dated June 12, 2006, and announces JAXX 1.0.1. These observations, coupled with related observations noted below, create some questions about the current and future state of JAXX.

  • The JAXX Main Page is a Wiki and it seems that someone thought it was a good idea to add links to various lewd messages at the top of many of the JAXX Wiki pages.

  • The JAXX General Chat Forum has over 4000 messages, but this seems to be mostly due to it being overrun by spam.

  • The JAXX How Do I ... Forum does have some non-spam, fairly recent postings, but they are not numerous.

  • In Swing: Its Past, Present, and Future, Hans Muller has nice things to say about JAXX.

  • Having significantly more experience with XML-oriented presentation languages like JavaServer Pages (JSPs), LZX, and MXML than with Java Swing, there is much conceptually about JAXX that appeals to me. I really like the binding support in OpenLaszlo and Flex and like the idea of a Java framework providing this for simple but powerful event handling. However, a significant hurdle for JAXX is lack of the wide community support that MXML and LZX enjoy.

  • A common complaint in OpenLaszlo and Flex forums is the lack of an IDE or lack of features in the available IDEs for developing in these environments or the cost of any available IDEs. JAXX suffers from lack of an IDE and this is especially noticeable because of the powerful Java IDEs that are available and provide Swing GUI builders. This and other limitations are also noted in "JAXX ... Oh My."

1 comment:

susan said...

Hallo, i just read ya aticle in oracle about using jfreechart with oracle database. ihave been working on the same thing for the past 1month. How can i use a jfreechart Ganttchart in Oracle forms? i need to generate a gantt chart in oracle forms by selecting necesary data from the database? pls can you shed more light into this concept?
thanks
Susan