Chapter 10.
Abstract Classes & Interfaces
This chapter describes the functions that are defined in the Perspective abstract interface. If you use any of these interfaces, your application must implement these function in the format described in this chapter. |
||
|
tdg Class NumberFormatCallback Class |
|
|
tdg.data.in Interface TDGDataCallbackIF Interface |
|
|
tdg.data.in Interface TDGDataGrid Interface |
|
|
tdg.data.in Interface TDGDataGridPieBar Interface |
|
|
tdg.event Class TDGEvent Class |
|
|
tdg.event Interface TDGListener Interface |
|
|
tdg Interface TDGNestedLabel Interface |
|
|
tdg.data.in Interface TDGPreScaleIF Interface |
|
|
tdg Interface ToolTipCallback Interface |
NumberFormatCallBack Class
The NumberFormatCallBack class defines the following static variables and methods: |
||
|
public static final int AXIS_LABEL |
|
|
public static final int PIE_LABEL |
|
|
public static final int PIE_TOTAL |
|
|
public static final int DATA_LABEL |
|
|
public static final int TOOLTIP_VALUE |
|
|
public static final int DATA_LABEL_HILO_VOL |
|
|
void init(Perspective a PerspectiveInstance); Initialize a perspective instance. |
|
|
void setState(int LabelType, int Series, int Group, tdg.AxisTemplate Axis_ID, int Axis_Ord); Reserved for internal use. |
|
|
String toString(double dVal); Convert a double value to a string. This function must be implemented by your application. |
|
The NumberFormatCallback class represents an abstract interface to an object that formats the numbers in a Perspective for Java chart. To use this class, do the following: |
||
|
subclass NumberFormatCallback |
|
|
override the toString() method to format the numbers as required by your application. |
|
|
call setNumberFormatCallBack() to register the "number format callback" object |
|
You may also use: |
||
|
getNumberFormatCallBack() to determine if a NumberFormatCallBack has been assigned with setNumberFormatCallBack() |
|
|
isNumberFormatCallBack() to determine if an object is a number format callback |
|
The following methods can be used to view information that is set by the reserved setState() method: |
||
|
protected int getSeries() |
|
|
protected int getGroup() |
|
|
protected int getLabelType() |
|
|
protected boolean isAxisLabel() |
|
|
protected boolean isY1AxisLabel() |
|
|
protected boolean isY2AxisLabel() |
|
|
protected boolean isX1AxisLabel() |
|
|
protected int getAxisLabelOrdinalPosition() |
|
The following example program shows a simple implementation of the NumberFormatCallback interface: |
||
import tdg.NumberFormatCallBack; // PUBLIC MEMBER FUNCTIONS //------------------------------------------------ public String toString( double dVal ) { String labelType; String resultValue; String axisValue; String dataValue; switch ( getLabelType() ) { // switch on labelType case AXIS_LABEL: labelType = "Axis"; break; case PIE_LABEL: labelType = "Slice"; break; case PIE_TOTAL: labelType = "PieT"; break; case DATA_LABEL: labelType = "Data"; break; case TOOLTIP_VALUE: labelType = "ToolTip"; break; default: labelType = "BadLabelType"; System.out.println("Undefined LabelType = " + getLabelType() + " Value = " + dVal); break; } // switch on labelType |
||
if ( isAxisLabel() ) { if(isY1AxisLabel())axisValue = "Y1" + ";" + getAxisLabelOrdinalPosition(); else if(isY2AxisLabel())axisValue = "Y2" + ";" + getAxisLabelOrdinalPosition(); else if(isX1AxisLabel())axisValue = "X1" + ";" + getAxisLabelOrdinalPosition(); else axisValue = "BadAxis"; } |
||
else axisValue = "NA"; if ( dVal > 1 || dVal == 0 ) dataValue = new Double(dVal).toString(); else dataValue = new Integer((int) (dVal * 100 + .5)).toString() + "%"; |
||
resultValue = labelType + ";" + getSeries() + ";" + getGroup() + ";" + axisValue + ":" + dataValue; return resultValue; } } // PfjNumberFormatCallback |
init()
This method is used to initialize a Perspective instance for the NumberFormatCallback interface. |
|
Syntax: |
void init(Perspective aPerspectiveInstance) |
Input: |
aPerspectiveInstance; a Perspective Instance |
Return: |
void; |
Example: |
public void init( Perspective aPerspectiveInstance ) |
Also See: |
toString(), getNumberFormatCallBack(), isNumberFormatCallBack(), setNumberFormatCallBack() |
toString()
This function converts the double value identified by dVal to a string using a user-defined criteria. This function must be created by your NumberFormatCallback interface to format numeric labels as required by your application. |
|
Syntax: |
String toString(double dVal) |
Input: |
dVal; a double value |
Return: |
String; |
Example: |
public String toString( double dVal ) |
Also See: |
getNumberFormatCallBack(), isNumberFormatCallBack(), setNumberFormatCallBack() |
TDGDataCallbackIF Interface
This interface defines a group of methods that can be used to get and set data in a chart when the setDataFromCallBack() method is used to slave chart data to an arbitrary Java Object. |
||
|
java.lang.String columnLabel(int c) |
|
|
int getColumns() |
|
|
int getRows() |
|
|
java.lang.Object getValue(int r, int c) |
|
|
java.lang.String rowLabel(int r) |
|
These methods are identical to the methods defined in the TDGDataGrid interface. |
TDGDataGrid Interface
TDGDataGrid is an abstract interface. It defines a series of methods that you must implement into an object. The TDGDataGrid interface represents an abstract data model that is one way of preparing data for graphing. Use these methods to enable this interface. |
||
|
setDataFromCallBack(TDGDataGrid grid); Enable the chart data to be slaved to an arbitrary Java Object which implements the TDGDataGrid Interface |
|
|
setDataFromDataGrid(TDGDataGrid grid); Tell the charting engine to use the TDGDataGrid object to collect data for the chart. |
|
You may also use getDataGridCallback() to get the TDGDataGrid interface defined by setDataFromDataGrid() |
||
The TDGDataGrid interface defines these methods that must be implemented by your application: |
||
|
abstract String columnLabel(int c); |
|
|
abstract int getColumns (); |
|
|
abstract String getFootnote(); |
|
|
abstract String getO1AxisTitle(); |
|
|
abstract String getO2AxisTitle(); |
|
|
abstract int getRows(); |
|
|
abstract String getSubtitle(); |
|
|
abstract String getTitle(); |
|
|
abstract Object getValue(int r,int c); |
|
|
abstract String getX1AxisTitle(); . |
|
|
abstract String getY1AxisTitle(); . |
|
|
abstract String getY2AxisTitle(); |
|
|
abstract boolean isDirty(); |
|
|
abstract String rowLabel(int r); |
|
TDGPreScaleIF is an optional callback interface that users with large datasets may implement in their existing data callbacks (TDGDataGrid) to expedite processing of data. See the TDGPreScaleIF interface below for details. |
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object.This method is used to establish column labels/headings for the column specified by the input parameter c. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String columnLabel(int c) |
Input: |
c; a column number |
Return: |
String; Column label at column c. |
Example: |
public String columnLabel(int c) |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object. This method is used to get the number of columns in the chart. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public int getColumns (); |
Input: |
void |
Return: |
int; The number of columns in the chart. |
Example: |
public int getColumns() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object.This function is used to establish the chart footnote. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getFootnote(); |
Input: |
void; |
Return: |
String; The chart footnote string. |
Example: |
public String getFootnote() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object.This function is used to establish the chart O1-axis title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getO1AxisTitle(); |
Input: |
void; |
Return: |
String; O1-Axis title string. |
Example: |
public String getO1AxisTitle() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object.This function is used to establish the chart O2-axis title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getO2AxisTitle(); |
Input: |
void; |
Return: |
String; O2-Axis title string. |
Example: |
public String getO2AxisTitle() |
Also See: |
|
getRows()
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object.This method is used to get the number of rows in the chart. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public int getRows (); |
Input: |
void; |
Return: |
int; The number of rows in the chart. |
Example: |
public int getRows() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object. This function is used to establish the chart subtitle. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getSubtitle(); |
Input: |
void; |
Return: |
String; Chart subtitle string. |
Example: |
public String getSubtitle() |
Also See: |
|
getTitle()
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object.This function is used to establish the chart title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getTitle(); |
Input: |
void; |
Return: |
String; Chart title string. |
Example: |
public String getTitle() |
Also See: |
|
getValue()
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e., setDataFromDataGrid()), this method must be implemented by your application in an object. This function gets the contents of the specified cell (at row (r), column (c)). Note that any type of Object can be returned. Perspective will interpret the Object type as a String or Double. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public Object getValue(int r, int c) |
Input: |
r; row number |
Input: |
c; column number |
Return: |
Object; Chart Data a row (r), column (c) |
Example: |
public Object getValue(int row, int col) |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object. This function is used to establish the chart X1-axis title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getX1AxisTitle() |
Input: |
void; |
Return: |
String; The X1-Axis Title String |
Example: |
public String getX1AxisTitle() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object. This function is used to establish the chart Y1-axis title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getY1AxisTitle() |
Input: |
void; |
Return: |
String; The Y1-Axis Title String |
Example: |
public String getY1AxisTitle() |
Also See: |
|
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object. This function is used to establish the chart Y2-axis title. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String getY2AxisTitle() |
Input: |
void; |
Return: |
String; The Y2-Axis Title String |
Example: |
public String getY2AxisTitle() |
Also See: |
|
isDirty()
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object. This function is used to determine if data in the chart has changed: TRUE = data has changed, FALSE = data has not changed. The syntax shows the format in which this method must be implemented by your application. |
||
Syntax: |
public boolean isDirty(); |
|
Input: |
void; |
|
Return: |
boolean; true/false |
|
true= |
Chart data has changed |
|
false= |
Chart data has not changed |
|
Example: |
public boolean isDirty() |
|
Also See: |
rowLabel()
This is a required method for the TDGDataGrid object. If you use TDGDataGrid (i.e.g, setDataFromDataGrid(), this method must be implemented by your application in an object.This method is used to establish row labels/headings for the row specified by the input parameter r. The syntax shows the format in which this method must be implemented by your application. |
|
Syntax: |
public String rowLabel(int r) |
Input: |
r; a row number |
Return: |
String; Row label at row r. |
Example: |
public String rowLabel(int r) |
Also See: |
TDGDataGridPieBar Interface
This interface defines a method to get the title string from a Pie-Bar chart. |
This method establishes the chart title in a Pie-Bar chart. |
|
Syntax: |
java.lang.String getPieBarLabel() |
Input: |
void; |
Return: |
String; chart title |
TDGListener Interface
The addPerspectiveListener() method creates an instance of an abstract class or interface to catch high-level events defined by the Perspective for Java integration. This method also tells the charting engine to notify the perspectiveEvent() method defined in the TDGListener interface when a Perspective event occurs. |
The perspectiveEvent() method will be called with an event object when an Perspective event occurs. The perspectiveEvent() must be included and defined in the object identified by addPerspectiveListener(). The definition of the perspectiveEvent() method should indicate handling of events that are reported by the charting engine. |
||
Syntax: |
void perspectiveEvent ( TDGEvent e ); |
|
Input: |
e: A location to store the event. On return, it will be set to the perspective event. Currently defined events include: |
|
|
TDG_3DPRESET_CHANGED : 3D Preset Changed |
|
|
TDG_APPLY_COLOR : Apply color change to current selection, if any. |
|
|
TDG_CALC_PERFORMED : Calculation has been performed. |
|
|
TDG_EDITOR_STATE_TOGGLE : Editing state has been toggled. |
|
|
TDG_FIRST_EVENT_ID: Lowest event ID in Perspective JavaChart |
|
|
TDG_GRAPHTYPE_CHANGED : GraphType was changed. |
|
|
TDG_KEY_PRESSED : Key was pressed. |
|
|
TDG_KEY_RELEASED : Key was release. |
|
|
TDG_KEY_TYPED : Key was typed. |
|
|
TDG_LAST_EVENT_ID: Highest event ID in Perspective JavaChart |
|
|
TDG_MOUSE_CLICKED : Mouse click event. |
|
|
TDG_MOUSE_DRAGGED : Mouse drag event. |
|
|
TDG_MOUSE_ENTERED : Mouse entered. |
|
|
TDG_MOUSE_EXITED : Mouse exited. |
|
|
TDG_MOUSE_MOVED : Mouse move. |
|
|
TDG_MOUSE_PRESSED : Mouse button pressed. |
|
|
TDG_MOUSE_RELEASED : Mouse button released. |
|
|
TDG_NOT_ENOUGH_DATA : Not enough data to draw the chart |
|
|
TDG_RESIZE_HANDLE_CHANGED: Mouse is over a resize handle. |
|
|
TDG_SELECTION_CHANGE : Perspective selection changes |
|
Return: |
void; |
|
Example: |
See FullMetalListener() in Appendix G |
|
Also See: |
TDGNestedLabel Interface
The TDGNestedLabel Interface defines the following methods: |
||
|
java.util.Vector getAllLabels(int nLevel); |
|
|
java.lang.String getLabel(int nGroup, int nLevel); |
|
|
int getLabelGrouping(int nGroup, int nLevel); |
|
|
int getNumLabelsOnLevel(int nLevel); |
|
|
int getNumLevels(); |
|
Perspective supports nested/multi-dimensional labels on the O1 axis with these properties and methods: |
||
|
setO1LabelCallback(): This method assigns a callback function to the nested labels interface. |
|
|
getO1LabelCallback(): This method determines if a callback function has been assigned with setO1LabelCallback(). |
|
|
NestedLabels (true/false): This property enables/disables nested labels. |
|
Use the following procedures to implement the nested labels interface: |
||
1. |
You must create your own version of the nested labels callback. It must implement all of the abstract methods defined in the TDGNestedLabel interface. |
|
2. |
Register the callback with the setO1LabelCallback() method. |
|
Example: |
m_chart.setO1LabelCallback (TDGNestedLabel cb); |
|
3. |
Enable the NestedLabel property. |
|
Example: |
m_chart.setNestedLabels (true); |
|
Perspective includes a simple example of nested labels in the TDGTestNestedGroupsLabels class. The example class can be enabled by setting the NestedLabels properrty to true. |
This method gets all the labels at the specified level (for batch autofitting). |
|
Syntax: |
java.util.Vector getAllLabels(int nLevel); |
Input: |
nLevel; Level to get the labels from. |
Return: |
Vector; Vector of String objects. |
This method gets the string specified by the group and level. If nLevel is zero, the group label is returned. If nLevel is 1, its immediate parent in the hierarchy, etc. is returned. |
|
Syntax: |
java.lang.String getLabel(int nGroup, int nLevel); |
Input: |
nGroup; a group number. |
nLevel; a multi-dimensional label level |
|
Return: |
String; the label at nGroup, nLevel |
This method gets the number of labels grouped at the level specified by the group and level. |
|
Syntax: |
int getLabelGrouping(int nGroup, int nLevel); |
Input: |
nGroup; a group number. |
nLevel; a multi-dimensional label level |
|
Return: |
int; Number of labels grouped at nGroup, nLevel |
This method returns an integer value that identifies how many labels there are on a given level. |
|
Syntax: |
int getNumLabelsOnLevel(int nLevel); |
Input: |
nLevel; a multi-dimensional label level |
Return: |
int; Number of labels on nLevel |
This method returns an integer value that defines the number nested-label levels. |
|
Syntax: |
int getNumLevels(); |
Input: |
None |
Return: |
int; Number of nested label levels. |
TDGPreScaleIF Interface
TDGPreScaleIF is an optional callback interface that users with large datasets may implement in their existing data callbacks (TDGDataGrid) to expedite processing of data. There are 2 methods in the interface: |
||
|
public double getScaleMinimum(int nAxis, int scaling) throws Exception |
|
|
public double getScaleMaximum(int nAxis, int scaling) throws Exception |
|
The following code shows an example implementation of this interface. |
||
Example: |
package tdg; |
|
public int getColumns() { return numCols; } |
||
// Needed for TDGPreScaleIF interface to speed PFJ |
||
public double getScaleMaximum(int nAxis, |
||
Based on the axis and scaling parameters, you may decide at runtime NOT to handle this call and choose to throw an Exception. If the call to the callback method results in an exception, Perspective for Java will catch the exception and do the scaling. |
||
Syntax: |
public double getScaleMaximum( |
|
Input: |
nAxis; an integer that identifies an axis |
|
scaling; an integer that identifies the type of scaling |
||
|
SCALING_ABSOLUTE |
|
|
SCALING_STACKED |
|
|
SCALING_PERCENT |
|
|
SCALING_HIST |
|
Return: |
double; maximum value to calculate scaling |
|
Example: |
public double getScaleMaximum(int nAxis, |
|
Also See: |
Based on the axis and scaling parameters, you may decide at runtime NOT to handle this call and choose to throw an Exception. If the call to the callback method results in an exception, Perspective for Java will catch the exception and do the scaling. |
||
Syntax: |
public double getScaleMinimum( |
|
input: |
nAxis; an integer that identifies an axis |
|
scaling; an integer that identifies the type of scaling |
||
|
SCALING_ABSOLUTE |
|
|
SCALING_STACKED |
|
|
SCALING_PERCENT |
|
|
SCALING_HIST |
|
Return: |
double; minimum value to calculate scaling |
|
Example: |
public double getScaleMinimum(int nAxis, |
|
Also See: |
||
ToolTipCallback Interface
This interface defines a dynamic callback function to produce a tooltip: |
This function is a dynamic callback to produce a tooltip. When this method is called, your application should provide a very fast method that returns the proper string for the object in question. |
||
Syntax: |
String getDynamicToolTip( |
|
Input: |
aMouseState; an object of class TDGMouseState which provides all the information about the object for which the tooltip is being generated. |
|
UserOrDeveloper; true/false |
||
true= |
Developer information |
|
false= |
User information |
|
Return: |
String; tooltip result string. |
|
Notes: |
getDynamicToolTip() is defined in the ToolTipCallBack interface. |
|
Example: |
public class TestToolTipCallBack |
|
Also See: |