Perforce JViews Charts Sample: Importing a Swing Table Model
Description
This sample loads data stored in a Swing TableModel
and displays it in a chart as polylines. It also shows how to print the
chart to PDF.
How to Use the Sample
- Modify data in the table to change the value in the table model. The modification is propagated to the data sets and automatically updates the renderers. Note that modifying the "Year" column modifies the X series of all the data sets, since they are all sharing the same X series.
- Click with the left mouse button on a chart point and drag it to modify its value. The corresponding value in the table model is changed. If the X editing allowed box is checked, dragging a point along the X-axis will modify the corresponding X value in the table model. This table model then notifies all the data sets sharing this series of its modification, leading finally to an update of all the renderers.
- Click the button to open the "Print" dialog (if run as an application).
- Click the button to open the "Page Setup" dialog (if run as an application).
- Click the button to open the "Print Preview" dialog (if run as an application).
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
chart-tablemodel.jar
,
that allows you to execute the sample with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the sample application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Importing data from a Swing
TableModel
into anIlvDataSource
. - Using the JViews Printing Framework.
- Converting a chart to PDF.
Detailed Description
This sample shows how to import a Swing TableModel
into an
IlvChart
. The data is stored in a Swing table model that is
wrapped within an IlvSwingTableDataSource
. This specialized
data source handles an in-out notification mechanism so that updates on the
table model itself are propagated to the chart data model (the data set
containing the data), and updates on the chart data model are propagated to
the original table model. You can see this mechanism in action if you
modify data in a cell of a table. The chart is automatically updated to
reflect the new value.
The printing support is provided through the JViews Printing framework.
Printing the table along with the chart in the same document is performed
by means of an IlvChartPrintableDocument
subclass.
This subclass computes the location of the table in the page and adds a
table printable object to all the document pages.
The PDF generation is provided through the JViews Printing framework and Apache FOP.
Installation Directory
The Importing a Swing Table Model sample is installed here.
Classes Involved
- ilog.views.chart.IlvChart
- ilog.views.chart.data.IlvSwingTableDataSource
- ilog.views.chart.renderer.IlvPolylineChartRenderer
- ilog.views.chart.print.IlvChartPrintableDocument
- ilog.views.util.print.IlvFOUtil