![]() ![]() ![]() |
Appendix D
Porting JClass 3.6.x Applications
Overview
Swing-like API
New Data Model
New Data Subpackage
New Beans Subpackage
Data Binding Changes
New Applet Subpackage
Pluggable Header/Footer
JCChartLabelManager
Chart Label Components
Use of Collection Classes
No More JCString
D.1 Overview
The major changes are listed in the table below. Each change is discussed in more detail with a recommended porting strategy.
D.2 Swing-like API
Chart's header, footer, chart area, and legend, and the chart itself are all derived from
JComponent
. The following changes to methods apply:In general, any property in Chart 3.* that started with "Is" has been modified. Changes include:
D.3 New Data Model
The data model for Chart 4 is a change to a data series-based model from a table-based model used in Chart 3.
As an example, consider charting the following data points:
(1,20)
(2,70)
(3,50)In Chart 3.*, the data model would have looked like:
import jclass.chart.Chartable;
import java.util.Vector;
public class simple implements Chartable {
double xdata[] = {1, 2, 3,};
double ydata[] = {20, 70, 50,};
public int getDataInterpretation() {
return Chartable.ARRAY;
}
public Object getDataItem(int row, int column) {
if (row == 0) {
return new Double(xdata[column]);
}
else if (row == 1) {
return new Double(ydata[column]);
}
return null;
}
public Vector getRow(int row) {
Vector rval = new Vector();
if (row == 0) {
for (int i = 0; i < xdata.length; i++) {
rval.addElement(new Double(xdata[i]));
}
}
else if (row == 1) {
for (int i = 0; i < ydata.length; i++) {
rval.addElement(new Double(xdata[i]));
}
}
return rval;
}
public int getNumRows() {
return 2;
}
public String[] getPointLabels() {
return pointLabels;
}
}(Note that the series and point label methods are not shown.)
In Chart 4.* and higher, the corresponding code is much simpler:
import com.klg.jclass.chart.ChartDataModel;
public class simple implements ChartDataModel {
double xdata[] = {1, 2, 3,};
double ydata[] = {20, 70, 50,};
public double[] getXSeries(int index) {
return xdata;
}
public double[] getYSeries(int index) {
return ydata;
}
public int getNumSeries() {
return 1;
}
}Most important to note is the different focus. In Chart 3.*, the model viewed data as a table. Depending on the data interpretation, each row was either an X-series or a Y-series. In Chart 4.* and higher, the X- and Y-data series are returned explicitly. Also, Double objects are no longer used. (Chart simply converted them to double.)
Chart 3.* allowed data models to update chart via Observer/Observable or event/listener. Chart 4.* and higher only allows event/listener.
Listed below are Chart 3.* data model classes, and their equivalent in Chart 4.* and higher
Chart 3.*
Chart 4.* and higher
No equivalent.
Observer/Observable
is no longer used for updated chart data sources.
D.4 New Data Subpackage
All stock data sources have been moved into a data subpackage. Some of the data source names have been changed. The next table explains the changes.
Chart 3.* (jclass.chart)
Chart 4.* and higher (com.klg.jclass.chart.data)
Note that
JCDefaultDataSource
provides functionality thatVectorDataSource
did not.
D.5 New Beans Subpackage
All the beans have been moved to the beans subpackage. There has been no bean property changes.
D.6 Data Binding Changes
The data binding beans remain in the same places. However, the
dataBindingMetaData
property has been replaced bydataBindingConfig
.
D.7 New Applet Subpackage
All code dealing with loading or saving of Chart as HTML PARAM tags has been moved to an applet subpackage. This change should be transparent to users. Deployment JARs for users not using HTML load/save can be made smaller by removing the applet subpackage.
Some parameter changes were necessary, mostly as a result of core chart API changes.
These changes are shown below:
Chart 3.*
Chart 4.* and higher
Note that
axis.grid
now supports all line style properties, including patterns
D.8 Pluggable Header/Footer
Headers and footers can now be any JComponent-derived object. By default,
chart.getHeader().setText("Foo")JCChart.getHeader()
andJCChart.getFooter()
return a JLabel. However, both methods return objects of type JComponent. This means a cast is required. Code that used to look like this:can be converted to look like this:
JLabel header = (JLabel)chart.getHeader();
header.setText("Foo");The full API for headers and footers is now defined by the
JComponent
-derived object used for header/footer. By default, this isJLabel
. Refer to theJLabel
API for more details.
D.9 JCChartLabelManager
As previously mentioned, chart label management has been removed to a delegate object. The delegate must be of type
JCChartLabelManager
. A default implementation calledJCDefaultChartLabelManager
is provided.Use of the delegate results in a smaller deployment JAR for users who don't use chart labels. It also helps focus the
JCChart
API by removing the chart label-related methods.
D.10 Chart Label Components
JCChartLabel
is no longer a component, but contains a component. Therefore, all of the usual component methods likegetBackground()
,getFont()
, and so on, need to be changed and prefaced by a call togetComponent()
e.g.
getComponent().getBackground()
D.11 Use of Collection Classes
JClass Chart aggregates objects like
JCAxis
,ChartDataView
andChartDataViewSeries
using collections. In Chart3.*, Vectors were used. The API has been updated to take advantage of the flexibility offered by collections.In most cases, Chart would build the object arrays manually. Collections (and their iterators) allow Chart to expose the internal collection directly.
For convenience, many of the index-based accessors remain. For example, you can still grab axes based on an index:
JCAxis xaxis = chart.getChartArea().getXAxis(1);Collections allow users to take advantage of iterators. In Chart 3.*, iterating over all the X-axes required the following code:
JCAxis[] xaxes = chart.getChartArea().getXAxis();
for (int i = 0; i < xaxes; i++) {
JCAxis xaxis = xaxes[i];
// Do something interesting
}In Chart 4.* and higher, iterators can be used:
for (ListIterator li = chart.getChartArea().getXAxes().listIterator();
i.hasNext();) {
JCAxis xaxis = (JCAxis)li.next();
}
D.12 No More JCString
JCString
s have been replaced by HTML in cells. This is supported by Swing, and has been added to Chart where appropriate.You can now put raw HTML into headers and footers, as long as the text starts with
"<html>"
. HTML is also valid in axis annotations, axis titles and legend elements.
![]() ![]() ![]() |