New Event Model · JCChart and JCChartComponent
Java Beans is a specification that calls for the design of reusable, pre-built Java software components. It is designed to be a full platform-independent component model written for the Java programming language. It enables developers to write components that can be re-used in other applications, reducing the total time needed to write complete applications. JClass Chart components are Java Bean-compliant.
The three main features that make a Bean are:
Properties are the named set and get public attributes associated with a Bean that can be read/write, read-only or write-only. A Bean also allows its methods to be called from other components. Beans fire events to notify other components that an action has happened.
Under the new model, "properties" are the named method attributes of a class that can affect its appearance or its behavior. Properties that are readable have a "get" method which enables the developer to read a property's value, and those properties which are writable have a "set" method which enable a property's value to be changed.
For example, the JCAxis object in JClass Chart has a property called AnnotationMethod. This property is used to control how an axis is labelled. To set the property value, the setAnnotationMethod() method is used. To get the property value, the getAnnotationMethod() method is used.
The main advantage of following the Java Beans specification is that it makes it very easy for an Integrated Development Environment to "discover" the set of properties belonging to an object. The developer can then manipulate the properties of the object easily through the graphical interface of the IDE when constructing a program.
There are four ways in which JClass Chart properties can be modified:
In JClass Chart, all four methods use the same property name. As a result, this manual documents the behavior of a particular property instead of the behavior of a particular method or HTML tag.
The next four sections demonstrate how to modify properties using each of the four techniques. For illustrative purposes, the AnnotationMethod property will be used.
The following illustration depicts a user modifying the AnnotationMethod property for the first X-axis using a popular Java IDE. The property is modified simply by finding the property in the property sheet, and then using the provided control to modify the property's value.
Note that the property pages may appear slightly differently in the IDE.
For more detailed information on which properties are available from within a component, consult the JClass Chart API.
If enabled by the developer, users can manipulate property values at run-time. The user can position the cursor over the part of the chart to modify. Clicking on a button (right mouse button under Windows 95/NT, middle button under Unix OS, or the button associated with launching a popup menu on your OS) brings up a property sheet displaying the values that can be changed. Note while the user can change these values at run-time, the changes are not reflected in the code, only to the user's display.
Note: Run-time property pages only appear if the AllowUserChanges property of JCChart is set to true .
Note: Property pages are generated using JDK 1.1 introspection and are therefore only available in the JDK 1.1 version of JClass Chart.
The property mechanism allows the user to read component parameters from within an HTML file. The mechanism is not hierarchical; instead it is tag-based. An applet is constructed incorporating JClass Chart components that contain property settings. (A pre-built applet called JCChartApplet.class is provided with JClass Chart). The compiled applet obtains its operating parameters from the NAME and VALUE elements of the <PARAM> tag in an HTML file. Many JClass Chart properties can be set within HTML files in this manner. Properties that cannot be set using a property are generally too complex or too obscure for end-users to want direct control over them.
HTML files for all the components in an application can also be combined to create an application default file. The following is a sample HTML file (plot1.html, provided with JClass Chart) that shows how to use HTML tags to configure JCChartApplet.class:
<HTML> <HEAD> <TITLE>plot1</TITLE> </HEAD> <BODY> <CENTER><H2>plot1</H2></CENTER> <APPLET CODE=jclass/chart/JCChartApplet.class CODEBASE="../../.." HEIGHT=300 WIDTH=400> <PARAM NAME=data VALUE=" ARRAY 2 4 # X-values 1.0 2.0 3.0 4.0 # Y-values 150.0 175.0 160.0 170.0 # Y-values set 2 125.0 100.0 225.0 300.0 "> </APPLET> </BODY> </HTML>
It displays the following when run in a Java-compatible browser.
To change the AnnotationMethod property for the X-axis, use the following HTML code:
<PARAM NAME="xaxis.annotationMethod" VALUE="POINT_LABELS">
More examples of HTML use with JClass Chart can be found in the jclass/chart/applet/ directory. A full listing of JClass Chart HTML properties and their values can be found in Appendix E: JClass Chart HTML Property Listing.
xaxis.getAnnotationMethod()To set the AnnotationMethod property in the same object:
xaxis.setAnnotationMethod(JCAxis.POINT_LABELS);
In the JDK 1.0.2, the behavior of Java programs was typically modified by subclassing and overriding event handling classes. Subclassing overrode the default behavior of a method. This approach was clumsy because it required the programmer to have a thorough understanding of base class methods and internals before writing any code.
Bean-compliant JClass programs (like JClass Chart) provide the means for an application to be notified when an event occurs through event listeners. It works like this: if a component is acted upon by the user or from within the program, a JCFooEvent is fired. The JCFooListener (which has been registered by calling addFooListener() on the component) receives the instance and enacts the action to be taken. The programmer uses the JCFooListener to define what action or actions should take place when it receives the JCFooEvent.
JCChartComponent exists because the current generation of Java IDEs do not support properties in contained objects. While current Java IDEs allow properties in contained objects to be modified, they cannot yet properly generate code for the property change. JCChartComponent works around this problem by exposing many JClass Chart properties in one object. While not all properties are provided, the most common properties are available.
Since JCChartComponent is a subclass of JCChart, it is possible to switch and use the contained properties in JCChart.