lt.monarch.chart.models
Class StackedDataModel

java.lang.Object
  extended by lt.monarch.chart.models.AbstractDataModel
      extended by lt.monarch.chart.models.StackedDataModel
All Implemented Interfaces:
java.io.Serializable, ArrayDataModel, ChartDataModelListener, DataModel, MatrixDataModel

public class StackedDataModel
extends AbstractDataModel
implements ChartDataModelListener

Stacked data model. On the first created StackDataModel You must to set the key, which will be used for stacking. All latter data models will use this stacking key. Here is the sample how to stack simple array data model:

 ChartDataModel m1 = new ChartDataModel(2);
 m1.add(new Double[] { 10d, 15d });
 m1.add(new Double[] { 20d, 25d });
 m1.add(new Double[] { 30d, 35d });

 ChartDataModel m2 = new ChartDataModel(2);
 m2.add(new Double[] { 10d, 150d });
 m2.add(new Double[] { 20d, 250d });
 m2.add(new Double[] { 30d, 350d });

 model1 = new StackedDataModel(m1);
 model2 = model1.setStackedModel(m2);
Stacking matrixes is a little bit tricky, since all values in the matrix will be stacked. All the values in the data model are stored as double values.

NOTE: The stacking is performed either on KEY or VALUE columns, but EXTENT and further columns are not stacked.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
protected  ArrayDataModel array
          Array data model instance
protected  lt.monarch.chart.models.StackedDataModel.SubValue bottomModel
          Bottom model of the stack.
protected  DataColumnType keyType
          Specifies what is the key type, i.e.
protected  MatrixDataModel matrix
          Matrix data model instance
protected  DataModel model
          Original data model
protected  boolean stackedByValue
          Specifies if the models are stacked by value.
protected  lt.monarch.chart.models.StackedDataModel.SubValue topModel
          Top model of the stack.
 
Fields inherited from class lt.monarch.chart.models.AbstractDataModel
columns, data, dataListeners, dimensions, suspended
 
Constructor Summary
Constructor and Description
StackedDataModel(DataModel dataModel)
          Stacked data model constructor.
StackedDataModel(DataModel dataModel, DataColumnType keyType)
          Stacked data model constructor.
 
Method Summary
Modifier and Type Method and Description
 void dispose()
          Disposes data model
 DataModelDimensions getAddressDimensions()
          Address dimensions, which shows if the model is array or matrix.
 StackedDataModel getBottomModel()
          Gets the bottom data model.
 java.lang.Double getBottomValueAt(DataColumnType type, int index)
          Returns bottom value from the array model according to the index of the current data model.
 java.lang.Double getBottomValueAt(DataColumnType type, int row, int column)
          Returns bottom value from the array model according to the index of the current data model
 DataColumnType getKeyType()
          Gets key type
 DataModel getModel()
          Gets current model (not stacked)
 int getPointCount()
          Counts the data model size.
 int getPointCount(MatrixDimensions dimension)
          Gets the count of point in the specified dimension.
 StackedDataModel getTopModel()
          Gets the top data model.
 java.lang.Object getValueAt(DataColumnType valType, int index)
          Gets the data value at the specified point.
 java.lang.Object getValueAt(DataColumnType valType, int row, int column)
          Get value at specified point.
 int getValuesInPoint()
          Gets the count of the data columns at each point in the data model.
 boolean hasColumn(DataColumnType type)
          Returns flag showing if this data model contains column of the given type.
 boolean isStackedByValue()
          Gets if the data model is stacked by value.
 void modelChanged(DataModelChangeEvent event)
           
 void setKeyType(DataColumnType keyType)
          Sets the stacking key type.
 void setStackedByValue(boolean stackedByValue)
          Sets the stacking type.
 StackedDataModel setStackedModel(DataModel topModel)
          Stacks the data model on the specified data model and returns the stacked top data model.
 void setValueAt(DataColumnType valType, int row, int column, java.lang.Object value)
          Sets value at the specified point.
 void setValueAt(DataColumnType valType, int index, java.lang.Object value)
          Sets value at specified point.
 void unstackModel()
          Unstacks data model, thus removes it from the stack setting bottom model to null and the top model in bottom model is set to null too.
 
Methods inherited from class lt.monarch.chart.models.AbstractDataModel
addColumn, addListener, castToArray, castToMatrix, fireDataChanged, getColumns, removeListener, resumeListeners, setColumns, suspendListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected DataModel model
Original data model


array

protected ArrayDataModel array
Array data model instance


matrix

protected MatrixDataModel matrix
Matrix data model instance


bottomModel

protected lt.monarch.chart.models.StackedDataModel.SubValue bottomModel
Bottom model of the stack. It is never null, but sub values can be null.


topModel

protected lt.monarch.chart.models.StackedDataModel.SubValue topModel
Top model of the stack. It is never null, but sub values can be null.


stackedByValue

protected boolean stackedByValue
Specifies if the models are stacked by value. Not applicable for matrixes.


keyType

protected DataColumnType keyType
Specifies what is the key type, i.e. that column is not stacked. Not applicable for matrixes.

Constructor Detail

StackedDataModel

public StackedDataModel(DataModel dataModel)
Stacked data model constructor. First you must construct this data model, then stack other data model on it. Default value stacking is by column with type DataColumnType.KEY.

Parameters:
dataModel - top data model. Other data model will be stacked on top of it.

StackedDataModel

public StackedDataModel(DataModel dataModel,
                        DataColumnType keyType)
Stacked data model constructor. First you must construct this data model, then stack other data model on it. Default value stacking is by column with type DataColumnType.KEY.

Parameters:
dataModel - top data model. Other data model will be stacked on top of it.
keyType - data value type which is used as a key for stacking.
Method Detail

setStackedModel

public StackedDataModel setStackedModel(DataModel topModel)
Stacks the data model on the specified data model and returns the stacked top data model.

Parameters:
topModel - model to stack on this model.
Returns:
Stacked data model

unstackModel

public void unstackModel()
Unstacks data model, thus removes it from the stack setting bottom model to null and the top model in bottom model is set to null too.


getAddressDimensions

public DataModelDimensions getAddressDimensions()
Description copied from interface: DataModel
Address dimensions, which shows if the model is array or matrix.

Specified by:
getAddressDimensions in interface DataModel
Overrides:
getAddressDimensions in class AbstractDataModel
Returns:
address dimensions

getValuesInPoint

public int getValuesInPoint()
Description copied from interface: DataModel
Gets the count of the data columns at each point in the data model.

Specified by:
getValuesInPoint in interface DataModel
Overrides:
getValuesInPoint in class AbstractDataModel
Returns:
count of data columns at each data point

getValueAt

public java.lang.Object getValueAt(DataColumnType valType,
                                   int index)
Description copied from interface: ArrayDataModel
Gets the data value at the specified point.

Specified by:
getValueAt in interface ArrayDataModel
Parameters:
valType - data column type (KEY, VALUE and etc.)
index - data value index in the data model
Returns:
requested data value

setValueAt

public void setValueAt(DataColumnType valType,
                       int index,
                       java.lang.Object value)
Description copied from interface: ArrayDataModel
Sets value at specified point.

Specified by:
setValueAt in interface ArrayDataModel
Parameters:
valType - data column type (KEY, VALUE and etc.)
index - data value index in the data model
value - value to set

getBottomValueAt

public java.lang.Double getBottomValueAt(DataColumnType type,
                                         int index)
Returns bottom value from the array model according to the index of the current data model.

Parameters:
type - column type which value has to be turned
index - index of the current data model value
Returns:
value of the bottom model

getPointCount

public int getPointCount()
Description copied from interface: ArrayDataModel
Counts the data model size.

Specified by:
getPointCount in interface ArrayDataModel
Returns:
data model size.

getValueAt

public java.lang.Object getValueAt(DataColumnType valType,
                                   int row,
                                   int column)
Description copied from interface: MatrixDataModel
Get value at specified point.

Specified by:
getValueAt in interface MatrixDataModel
Parameters:
valType - data column type
row - row of the matrix
column - column of the matrix
Returns:
matrix element value

setValueAt

public void setValueAt(DataColumnType valType,
                       int row,
                       int column,
                       java.lang.Object value)
Description copied from interface: MatrixDataModel
Sets value at the specified point.

Specified by:
setValueAt in interface MatrixDataModel
Parameters:
valType - data column type
row - row number of the matrix
column - column number of the matrix
value - value to set to the specified point

getBottomValueAt

public java.lang.Double getBottomValueAt(DataColumnType type,
                                         int row,
                                         int column)
Returns bottom value from the array model according to the index of the current data model

Parameters:
type - column type which value has to be turned
row - row of the current data model value
column - column of the current data model value
Returns:
value of the bottom model

getPointCount

public int getPointCount(MatrixDimensions dimension)
Description copied from interface: MatrixDataModel
Gets the count of point in the specified dimension. If dimension is ROWS then it returns the count of rows, if COLUMNS then count of columns.

Specified by:
getPointCount in interface MatrixDataModel
Parameters:
dimension - dimension of the matrix
Returns:
count of either rows or columns

getBottomModel

public StackedDataModel getBottomModel()
Gets the bottom data model. Null is returned if this data model is not stacked on any data model.

Returns:
the bottom Model

getTopModel

public StackedDataModel getTopModel()
Gets the top data model. Null is returned if no data model is stacked on it.

Returns:
the top Model

isStackedByValue

public boolean isStackedByValue()
Gets if the data model is stacked by value.

Returns:
the boolean value specifying if the data model is stacked by value (true) or by index (false)

setStackedByValue

public void setStackedByValue(boolean stackedByValue)
Sets the stacking type. Either by value - true, or by index - false. It is enough to set this option only for the first constructed data model in the stack (i.e. the base of the stack), since other stacked models will be set accordingly to this data model. Models must be stacked already.

Parameters:
stackedByValue - the stacking type. True if stacked by value.

setKeyType

public void setKeyType(DataColumnType keyType)
Sets the stacking key type. You must set to any part of stacked data model, so that further models stacked on or beneath it, would be set automatically. If you use setting key value type in the constructor, you don't have to use this methods, only if you want to change the stacking key type.

Parameters:
keyType - key value type

getModel

public DataModel getModel()
Gets current model (not stacked)

Returns:
the current model

getKeyType

public DataColumnType getKeyType()
Gets key type

Returns:
the key type

modelChanged

public void modelChanged(DataModelChangeEvent event)
Specified by:
modelChanged in interface ChartDataModelListener

dispose

public void dispose()
Description copied from interface: DataModel
Disposes data model

Specified by:
dispose in interface DataModel
Overrides:
dispose in class AbstractDataModel

hasColumn

public boolean hasColumn(DataColumnType type)
Description copied from interface: DataModel
Returns flag showing if this data model contains column of the given type.

Specified by:
hasColumn in interface DataModel
Parameters:
type - data column type
Returns:
true if column with the given type exists.