JClass Chart

PreviousNextIndex

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.

Change

Rationale

applet subpackage

Makes it easier to find applet load/save code. Important for users who wish to remove the applet code from deployment JARs.

beans subpackage

Makes it easier to find beans. Important for users who wish to remove the beans from deployment JARs.

Chart label components

Chart labels are no longer derived from components. Instead, they contain components. This is a more flexible scheme, since any JComponent-derived object can be used as a chart label.

Data Binding Changes

The data binding for Chart has been rewritten, resulting in some minor API changes.

data subpackage

Makes it easier to find stock data sources. Stock data sources now include the JC prefix.

JCChartLabelManager

Not every user requires chart labels. To reduce download, chart label management is deferred to an object called JCChartLabelManager.

New data model

Old model dated back to JDK 1.0.2. New model is easier to understand.

No more JCString

JCString has been replaced by HTML in cells.

Package name change

(com.klg.jclass.chart)

Old package name pre-dated naming standard.

Pluggable header/footer

Header and footer are now JComponents. This allows re-use of Swing code, and adds flexibility to the product. It also adds casts to your code.

Swing-like API

JClass 4 is Swing-based. Applies to applet PARAM tags as well.

Use of collection classes

Collection classes weren't available for JDK 1.0.2. Use of collection classes adds flexibility.

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:

Chart 3.*

Chart 4.* and higher

get/setBorderType()

Replaced by JComponent.setBorder()
Note that enum-based replacements for standard Swing borders from BorderFactory may be created.

get/setBorderWidth()

In Swing, borders have their own width.

get/setHeight()

All replaced by JComponent.setBounds().

get/setHeight()

get/setWidth()
get/setLeft()

get/setTop()
Related IsDefault methods

All replaced by JComponent.setBounds(), JComponent.setLocation() and JComponent.setSize(). In Chart 4.* and higher, layout options for chart area, legend, header and footer are somewhat more limited. However, JCChart will now accept new layout managers. Also, JCChart allows specification of layout hints for header, footer, chart area and legend using JCChart.setLayoutHints().

setInets()

No direct equivalent. Use borders.

get/setIsShowing()

JComponent.get/setVisible()

draw()

Now using Swing's paint mechanism.

In general, any property in Chart 3.* that started with "Is" has been modified. Changes include:

Category

Chart 3.*

Chart 4.* and higher

IsShowingVisible

ChartDataViewSeries.IsShowing

ChartDataViewSeries.
 visible

 

ChartDataViewSeries.IsShowing
  InLegend

ChartDataViewSeries.
 visibleInLegend

 

ChartDataView.IsShowingInLegend

ChartDataView.

 visibleInLegend

 

JCAxis.GridIsShowing

JCAxis.GridVisible

 

JCAxis.IsShowing

JCAxis.visible

 

JCAxisTitle.IsShowing

JCAxisTitle.visible

IsIncluded

ChartDataViewSeries.IsIncluded

ChartDataViewSeries.
 Included

IncludedIs
 Editable

JCAxis.IsEditable

JCAxis.Editable

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

Chartable

ChartDataModel and LabelledChartDataModel

EditableChartable

EditableChartDataModel

ChartDataModel

No equivalent. Observer/Observable is no longer used for updated chart data sources.

ChartDataListener

ChartDataListener

ChartDataEvent

ChartDataEvent

ChartDataSupport

ChartDataSupport

No equivalent

ChartDataManageable

Tells JCChart that an object can manage ChartDataListeners

No equivalent

ChartDataManager

Manages ChartDataListeners

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)

No equivalent

BaseDataSource

Common base class for most stock data sources.

AppletDataSource

JCAppletDataSource

ChartSwingDataSource

JCChartSwingDataSource

VectorDataSource

JCDefaultDataSource

Note that JCDefaultDataSource provides functionality that VectorDataSource did not.

No equivalent

JCEditableDataSource

Editable version of JCDefaultDataSource

JCFileDataSource

InputStreamDataSource

JCInputStreamDataSource

StringDataSource

JCStringDataSource

URLDataSource

JCURLDataSource

JDBCDataSource

JDBCDataSource

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 by dataBindingConfig.

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

LeftMargin, TopMargin, BottomMargin, RightMargin

No equivalent

BorderType

No equivalent

BorderWidth

No equivalent

DoubleBuffer

No equivalent

Offset

No equivalent

IsShowing

IsVisible

IsShowingInLegend

VisibleInLegend

IsIncluded

Included

No equivalent

Join, Cap and Background in series.line

axis.IsVertical

axis.Vertical

axis.IsLogarithmic

axis.Logarithmic

axis.IsReversed

axis.Reversed

axis.GridIsShowing

axis.grid.visible

axis.Grid*

axis.grid.*

Note that axis.grid now supports all line style properties, including patterns

axis.IsEditable

axis.editable

chartLabel.attachX/Y

chartLabel.coord format: x,y

chartLabel.IsConnected

chartLabel.connected

chartLabel.IsDwellLabel

chartLabel.dwellLabel

candleChartFormat.isComplex

candleChartFormat.complex

HLOCChartFormat.isShowingOpen

HLOCChartFormat.showingOpen

HLOCChartFormat.isShowingClose

HLOCChartFormat.showingClose

HLOCChartFormat.isOpenCloseFullWidth

HLOCChartFormat.openCloseFullWidth

D.8 Pluggable Header/Footer

Headers and footers can now be any JComponent-derived object. By default, JCChart.getHeader() and JCChart.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:

chart.getHeader().setText("Foo")

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 is JLabel. Refer to the JLabel 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 called JCDefaultChartLabelManager 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.

3.* (JCChart)

4.* and higher (JCChartLabelManager)

void addChartLabel(JCChartLabel label)

Moved to JCChartLabelManager

void removeChartLabel(JCChartLabel label)

Moved to JCChartLabelManager

int getNumChartLabels()

Moved to JCChartLabelManager

void removeAllChartLabels()

Moved to JCChartLabelManager

JCChartLabel getChartLabels(int index)

Moved to JCChartLabelManager

void setChartLabels(int index, JCChartLabel label)

Moved to JCChartLabelManager

JCChartLabel[] getChartLabels()

List JCChartLabelManager.getChartLabels()

void setChartLabels(JCChartLabel[] s)

void JCChartLabelManager.setChartLabels(List s)

D.10 Chart Label Components

JCChartLabel is no longer a component, but contains a component. Therefore, all of the usual component methods like getBackground(), getFont(), and so on, need to be changed and prefaced by a call to getComponent()

e.g. getComponent().getBackground()

D.11 Use of Collection Classes

JClass Chart aggregates objects like JCAxis, ChartDataView and ChartDataViewSeries 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.

Changes include:

Chart 3.*

Chart 4.* and higher

String[] ChartDataView.getPointLabels()

List ChartDataView.getPointLabels()

ChartDataViewSeries[] ChartDataView.getSeries()

List ChartDataView.getSeries()

JCChartStyle[] ChartDataView.getChartStyle()

List ChartDataView.getChartStyle()

ChartDataView[] JCChart.getDataView()

List JCChart.getDataView()

JCChartLabel[] JCChart.getChartLabels()

List JCChartLabelManager.
  getChartLabels()

List JCDefaultChartLabelManager.
  getChartLabels()

JCAxis[] JCChartArea.getXAxis()

List JCChartArea.getXAxes()

JCAxis[] JCChartArea.getYAxis()

List JCChartArea.getYAxes()

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

JCStrings 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 "&lt;html&gt;". HTML is also valid in axis annotations, axis titles and legend elements.


PreviousNextIndex