jdbreport.model
Class ReportRowModel

java.lang.Object
  extended by jdbreport.model.ReportRowModel
All Implemented Interfaces:
PropertyChangeListener, Serializable, Iterable<TableRow>, EventListener, ListSelectionListener, TableRowModel
Direct Known Subclasses:
TemplateRowModel

public class ReportRowModel
extends Object
implements TableRowModel, PropertyChangeListener, ListSelectionListener, Serializable

Version:
2.0 12.05.2011
Author:
Andrey Kholmanskih
See Also:
Serialized Form

Field Summary
protected  ChangeEvent changeEvent
          Change event (only one needed)
protected  EventListenerList listenerList
           
protected  ArrayList<TableRow> rowList
           
protected  int rowMargin
           
 
Fields inherited from interface jdbreport.model.TableRowModel
maxHeight, minHeight
 
Constructor Summary
ReportRowModel(JReportModel reportModel)
           
 
Method Summary
 void addColumn(int column)
          Adds column in the model
 TableRow addRow()
          Adds the new row
 TableRow addRow(int row)
          Adds the row at the specified position
 int addRow(int arow, TableRow tableRow)
          Adds the row at the specified position
 int addRow(RowsGroup group, int indexInGroup)
          Adds the row to the group
 int addRow(RowsGroup group, int indexInGroup, TableRow tableRow)
          Adds the row to the group
 void addRowModelListener(TableRowModelListener x)
          Adds a listener for report row model events.
 int addRows(int count, int index)
          Adds rows' count to the index of the model.
protected  void clearPageHeader(int startRow)
          removes all page headers and page footers from report
 void clearUnion(int topRow, int leftCol, int bottomRow, int rightCol)
          Clears the unions of the selected cells
protected  RootGroup createRootGroup()
           
 TableRow createTableRow()
          Creates new default TableRow
 void disableSpan()
          Clears all cells unions before moving of rows or columns
 void enableSpan()
          Restores all cells unions after moving of rows or columns
 void endUpdate()
          Allows notification of listeners after updates of model
protected  void fireRowAdded(TableRowModelEvent e)
           
protected  void fireRowMarginChanged()
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRowMoved(TableRowModelEvent e)
           
protected  void fireRowRemoved(TableRowModelEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRowResizing(int row, boolean dragging)
           
protected  void fireRowSelectionChanged(ListSelectionEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRowUpdated()
           
 CellCoord getCellPosition(Cell cell)
           
 int getColCount()
          Returns columns' count in the model
 int getFirstPageNumber()
          Returns number of the first page
 RowsGroup getGroup(int row)
          Returns the group which contains the TableRow by specified row index
 Group getGroup(int[] path)
           
 RowsGroup getGroup(TableRow row)
          Returns the group which contains the tableRow
 int getGroupRowIndex(Group group)
          Returns the index of the first group's row in rowList
 Object getHeaderValue(int row)
          Returns value for row's header
 int getMaxRowHeight()
          Returns the maximum height of a report row, in pixels.
 int getMinRowHeight()
          Returns the minimum height of a report row, in pixels.
protected  TableRow getNullRow()
           
 int getOwnerRow(Cell cell, int row, int column)
           
 int getPageCount()
          Returns count of pages
 int getPageHeight()
           
 Integer getPageNumber(int row, int column)
          Returns number of page for a cell on a row and a column
 int getPreferredRowHeight()
          Returns the preferred height of a report row, in pixels.
 RootGroup getRootGroup()
           
 TableRow getRow(int row)
          Returns the TableRow from the specified position
 int getRowCount()
          Returns rows' count in the model
 int getRowHeight(int row)
          Returns the height, in pixels, of the row.
 int getRowIndex(TableRow row)
          Returns row's position in the model
 int getRowIndexAtY(int y)
          Returns the index of the row that lies on the vertical point, y; or -1 if it lies outside the any of the row's bounds.
 int getRowMargin()
          Returns the row between the cells in each row.
 TableRowModelListener[] getRowModelListeners()
           
 int getTotalRowHeight()
          Returns the total height of all the rows.
protected  void hideGroup(Group group)
           
 boolean isCanHideGroup()
           
 boolean isCanUpdatePages()
          Returns the possibility of calculation of pages' size
 boolean isCollapse(Group group)
           
protected  boolean isDirtyHeader()
           
 boolean isPrintLeftToRight()
          Direction of an output of pages on the printer.
 boolean isUpdate()
           
 Iterator<TableRow> iterator()
           
 void moveColumn(int columnIndex, int newIndex)
          Moves the column at columnIndex to newIndex.
 void moveDraggedRow(int rowIndex, int newIndex)
          Moves the dragged row and its header at rowIndex to newIndex.
 void moveRow(int rowIndex, int newIndex)
          Moves the row and its header at rowIndex to newIndex.
 void propertyChange(PropertyChangeEvent evt)
           
protected  void recalcHeightCache()
           
 void removeColumn(int column)
          Removes column from the model
protected  void removeGroup(Group group)
           
 void removeRowModelListener(TableRowModelListener x)
          Removes a listener for report row model events.
 void removeRows()
          Removes all rows
 void removeRows(int count, int index)
          Removes rows' count begining with the index from the model.
protected  void setCanHideGroup(boolean canHideGroup)
           
 void setCanUpdatePages(boolean b)
          Sets canUpdatePages property
 void setColCount(int colcount)
          Sets the columns' count in the model If the columns' count is bigger than parameter, the columns are removed from the model If the columns' count is smaller than parameter, the columns are added to the model
protected  void setDirtyHeader(boolean dirtyHeader)
           
 void setFirstPageNumber(int firstPageNumber)
          Sets number of the first page
 void setPageHeight(int pageHeight)
           
 void setPreferredRowHeight(int preferredHeight)
          Sets the preferred height for row.
 void setPrintLeftToRight(boolean value)
          Direction of an output of pages on the printer.
 void setRowCount(int value)
           
 void setRowHeight(int row, double h)
          Sets the height for row to h.
 void setRowHeight(int row, int rowHeight)
          Sets the height for row to rowHeight.
 void setRowHeight(TableRow row, int newHeight)
          Sets the height for tableRow to newHeight.
 void setRowMargin(int newMargin)
          Sets the row margin to newMargin.
 void setShowPageNumber(boolean show)
           
 void setVisibleGroup(Group group, boolean b)
          If parameter b is true, sets the group that is visible in report, otherwise removes rows containing in the group from report
protected  void showGroup(Group group)
           
 void startUpdate()
          Bans notification of listeners before updates of model
 void unionCells(int topRow, int leftColumn, int bottomRow, int rightColumn)
          Unions the cells by coordinates
protected  void updateCellChild(BaseRowGroup group)
           
protected  void updateHeaderValue()
           
 void updatePages(int startRow, int pageHeight)
          Calculates pages' size
 void valueChanged(ListSelectionEvent e)
          A ListSelectionListener that forwards ListSelectionEvents when there is a column selection change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowMargin

protected int rowMargin

rowList

protected ArrayList<TableRow> rowList

listenerList

protected EventListenerList listenerList

changeEvent

protected transient ChangeEvent changeEvent
Change event (only one needed)

Constructor Detail

ReportRowModel

public ReportRowModel(JReportModel reportModel)
Method Detail

getColCount

public int getColCount()
Description copied from interface: TableRowModel
Returns columns' count in the model

Specified by:
getColCount in interface TableRowModel
Returns:
the columns count

setColCount

public void setColCount(int colcount)
Description copied from interface: TableRowModel
Sets the columns' count in the model If the columns' count is bigger than parameter, the columns are removed from the model If the columns' count is smaller than parameter, the columns are added to the model

Specified by:
setColCount in interface TableRowModel
Parameters:
colcount - new columns' count

getRow

public TableRow getRow(int row)
Description copied from interface: TableRowModel
Returns the TableRow from the specified position

Specified by:
getRow in interface TableRowModel
Parameters:
row - the row's number
Returns:
the TableRow

getNullRow

protected TableRow getNullRow()

addColumn

public void addColumn(int column)
Description copied from interface: TableRowModel
Adds column in the model

Specified by:
addColumn in interface TableRowModel
Parameters:
column - the specified position in this model

removeColumn

public void removeColumn(int column)
Description copied from interface: TableRowModel
Removes column from the model

Specified by:
removeColumn in interface TableRowModel
Parameters:
column - the index of the removing column

createTableRow

public TableRow createTableRow()
Description copied from interface: TableRowModel
Creates new default TableRow

Specified by:
createTableRow in interface TableRowModel
Returns:
the TableRow object

addRows

public int addRows(int count,
                   int index)
Description copied from interface: TableRowModel
Adds rows' count to the index of the model. The new rows will contain null values. Notification of the row being added will be generated.

Specified by:
addRows in interface TableRowModel
Parameters:
count - rows' count
index - the row index of the rows to be inserted
Returns:
rows' count in the model

addRow

public TableRow addRow()
Description copied from interface: TableRowModel
Adds the new row

Specified by:
addRow in interface TableRowModel
Returns:
the index of the inserted row

addRow

public TableRow addRow(int row)
Description copied from interface: TableRowModel
Adds the row at the specified position

Specified by:
addRow in interface TableRowModel
Parameters:
row - index at which the row is to be inserted.
Returns:
the inserted TableRow

addRow

public int addRow(RowsGroup group,
                  int indexInGroup)
Description copied from interface: TableRowModel
Adds the row to the group

Specified by:
addRow in interface TableRowModel
indexInGroup - index in group
Returns:
row's index in rows list

addRow

public int addRow(RowsGroup group,
                  int indexInGroup,
                  TableRow tableRow)
Description copied from interface: TableRowModel
Adds the row to the group

Specified by:
addRow in interface TableRowModel
Returns:
row's index in the list

addRow

public int addRow(int arow,
                  TableRow tableRow)
Description copied from interface: TableRowModel
Adds the row at the specified position

Specified by:
addRow in interface TableRowModel
Parameters:
arow - the row's number
tableRow - the TableRow object
Returns:
the index of the inserted row

isUpdate

public boolean isUpdate()

startUpdate

public void startUpdate()
Description copied from interface: TableRowModel
Bans notification of listeners before updates of model

Specified by:
startUpdate in interface TableRowModel

endUpdate

public void endUpdate()
Description copied from interface: TableRowModel
Allows notification of listeners after updates of model

Specified by:
endUpdate in interface TableRowModel

removeRows

public void removeRows()
Description copied from interface: TableRowModel
Removes all rows

Specified by:
removeRows in interface TableRowModel

removeGroup

protected void removeGroup(Group group)
Parameters:
group -

removeRows

public void removeRows(int count,
                       int index)
Description copied from interface: TableRowModel
Removes rows' count begining with the index from the model.

Specified by:
removeRows in interface TableRowModel
Parameters:
count - rows' count
index - index of the first removed row

getRowCount

public int getRowCount()
Description copied from interface: TableRowModel
Returns rows' count in the model

Specified by:
getRowCount in interface TableRowModel
Returns:
the rows count

setRowCount

public void setRowCount(int value)

getTotalRowHeight

public int getTotalRowHeight()
Description copied from interface: TableRowModel
Returns the total height of all the rows.

Specified by:
getTotalRowHeight in interface TableRowModel
Returns:
the total computed height of all rows

recalcHeightCache

protected void recalcHeightCache()

addRowModelListener

public void addRowModelListener(TableRowModelListener x)
Description copied from interface: TableRowModel
Adds a listener for report row model events.

Specified by:
addRowModelListener in interface TableRowModel
Parameters:
x - a TableRowModelListener object

removeRowModelListener

public void removeRowModelListener(TableRowModelListener x)
Description copied from interface: TableRowModel
Removes a listener for report row model events.

Specified by:
removeRowModelListener in interface TableRowModel
Parameters:
x - a TableRowModelListener object

getRowModelListeners

public TableRowModelListener[] getRowModelListeners()

getRowIndexAtY

public int getRowIndexAtY(int y)
Description copied from interface: TableRowModel
Returns the index of the row that lies on the vertical point, y; or -1 if it lies outside the any of the row's bounds.

Specified by:
getRowIndexAtY in interface TableRowModel
Parameters:
y - y coordinate of point
Returns:
the index of the row; or -1 if no row is found

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

moveDraggedRow

public void moveDraggedRow(int rowIndex,
                           int newIndex)
Description copied from interface: TableRowModel
Moves the dragged row and its header at rowIndex to newIndex.

Specified by:
moveDraggedRow in interface TableRowModel
Parameters:
rowIndex - the index of row to be moved
newIndex - index of the row's new location

moveRow

public void moveRow(int rowIndex,
                    int newIndex)
Description copied from interface: TableRowModel
Moves the row and its header at rowIndex to newIndex. The old row at rowIndex will now be found at newIndex. The row that used to be at newIndex is shifted top or bottom to make room. This will not move any rows if rowIndex equals newIndex. This method posts a rowMoved event to its listeners.

Specified by:
moveRow in interface TableRowModel
Parameters:
rowIndex - the index of row to be moved
newIndex - index of the row's new location

isCollapse

public boolean isCollapse(Group group)

moveColumn

public void moveColumn(int columnIndex,
                       int newIndex)
Description copied from interface: TableRowModel
Moves the column at columnIndex to newIndex.

Specified by:
moveColumn in interface TableRowModel
Parameters:
columnIndex - the index of column to be moved
newIndex - index of the column's new location

enableSpan

public void enableSpan()
Description copied from interface: TableRowModel
Restores all cells unions after moving of rows or columns

Specified by:
enableSpan in interface TableRowModel

disableSpan

public void disableSpan()
Description copied from interface: TableRowModel
Clears all cells unions before moving of rows or columns

Specified by:
disableSpan in interface TableRowModel

clearUnion

public void clearUnion(int topRow,
                       int leftCol,
                       int bottomRow,
                       int rightCol)
Description copied from interface: TableRowModel
Clears the unions of the selected cells

Specified by:
clearUnion in interface TableRowModel
Parameters:
topRow - the number of the top row
leftCol - the number of the left column
bottomRow - the number of the bottom row
rightCol - the number of the right column

unionCells

public void unionCells(int topRow,
                       int leftColumn,
                       int bottomRow,
                       int rightColumn)
Description copied from interface: TableRowModel
Unions the cells by coordinates

Specified by:
unionCells in interface TableRowModel
Parameters:
topRow - the number of the top row
leftColumn - the number of the left column
bottomRow - the number of the bottom row
rightColumn - the number of the right column

updateCellChild

protected void updateCellChild(BaseRowGroup group)

setRowMargin

public void setRowMargin(int newMargin)
Sets the row margin to newMargin. This method also posts a rowMarginChanged event to its listeners.

Parameters:
newMargin - the new margin width, in pixels
See Also:
getRowMargin(), getTotalRowHeight()

valueChanged

public void valueChanged(ListSelectionEvent e)
A ListSelectionListener that forwards ListSelectionEvents when there is a column selection change.

Specified by:
valueChanged in interface ListSelectionListener
Parameters:
e - the change event

fireRowUpdated

protected void fireRowUpdated()

fireRowResizing

protected void fireRowResizing(int row,
                               boolean dragging)

fireRowAdded

protected void fireRowAdded(TableRowModelEvent e)
Parameters:
e - the event received
See Also:
EventListenerList

fireRowRemoved

protected void fireRowRemoved(TableRowModelEvent e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event received

fireRowSelectionChanged

protected void fireRowSelectionChanged(ListSelectionEvent e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event received
See Also:
EventListenerList

fireRowMarginChanged

protected void fireRowMarginChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

See Also:
EventListenerList

fireRowMoved

protected void fireRowMoved(TableRowModelEvent e)

getRowMargin

public int getRowMargin()
Description copied from interface: TableRowModel
Returns the row between the cells in each row.

Specified by:
getRowMargin in interface TableRowModel
Returns:
the margin, in pixels, between the cells

getMinRowHeight

public int getMinRowHeight()
Description copied from interface: TableRowModel
Returns the minimum height of a report row, in pixels. The default minimum row height is 2.0.

Specified by:
getMinRowHeight in interface TableRowModel
Returns:
the mimimum height in pixels of a report row

getMaxRowHeight

public int getMaxRowHeight()
Description copied from interface: TableRowModel
Returns the maximum height of a report row, in pixels. The default maximum row height is 4096.0.

Specified by:
getMaxRowHeight in interface TableRowModel
Returns:
the maximum height in pixels of a report row

getPreferredRowHeight

public int getPreferredRowHeight()
Description copied from interface: TableRowModel
Returns the preferred height of a report row, in pixels. The default row height is 17.0.

Specified by:
getPreferredRowHeight in interface TableRowModel
Returns:
the preferred height in pixels of a report row

setPreferredRowHeight

public void setPreferredRowHeight(int preferredHeight)
Description copied from interface: TableRowModel
Sets the preferred height for row.

Specified by:
setPreferredRowHeight in interface TableRowModel
Parameters:
preferredHeight - new preferred row height, in pixels

getRowHeight

public int getRowHeight(int row)
Description copied from interface: TableRowModel
Returns the height, in pixels, of the row. The default row height is 17.0.

Specified by:
getRowHeight in interface TableRowModel
Parameters:
row - the row whose height is to be returned
Returns:
the height in pixels of a report row

setRowHeight

public void setRowHeight(int row,
                         int rowHeight)
Description copied from interface: TableRowModel
Sets the height for row to rowHeight. The height of the cells in this row will be equal to the row height minus the row margin.

Specified by:
setRowHeight in interface TableRowModel
Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels

setRowHeight

public void setRowHeight(TableRow row,
                         int newHeight)
Description copied from interface: TableRowModel
Sets the height for tableRow to newHeight. The height of the cells in this row will be equal to the row height minus the row margin.

Specified by:
setRowHeight in interface TableRowModel
Parameters:
row - the row whose height is being changed
newHeight - new row height, in pixels

getRootGroup

public RootGroup getRootGroup()
Specified by:
getRootGroup in interface TableRowModel
Returns:
the RootGroup of repoprt model

createRootGroup

protected RootGroup createRootGroup()

getGroup

public RowsGroup getGroup(int row)
Description copied from interface: TableRowModel
Returns the group which contains the TableRow by specified row index

Specified by:
getGroup in interface TableRowModel
Parameters:
row - the row's index in rowList
Returns:
the RowsGroup object

getGroup

public RowsGroup getGroup(TableRow row)
Description copied from interface: TableRowModel
Returns the group which contains the tableRow

Specified by:
getGroup in interface TableRowModel
Parameters:
row - the TableRow object
Returns:
the RowsGroup object

showGroup

protected void showGroup(Group group)

hideGroup

protected void hideGroup(Group group)

setVisibleGroup

public void setVisibleGroup(Group group,
                            boolean b)
Description copied from interface: TableRowModel
If parameter b is true, sets the group that is visible in report, otherwise removes rows containing in the group from report

Specified by:
setVisibleGroup in interface TableRowModel
Parameters:
group - Group object
b - visible property

getRowIndex

public int getRowIndex(TableRow row)
Description copied from interface: TableRowModel
Returns row's position in the model

Specified by:
getRowIndex in interface TableRowModel
Parameters:
row - TableRow to search for.
Returns:
the index in this model of the first occurrence of the specified tableRow, or -1 if this model does not contain this tableRow.

getGroupRowIndex

public int getGroupRowIndex(Group group)
Description copied from interface: TableRowModel
Returns the index of the first group's row in rowList

Specified by:
getGroupRowIndex in interface TableRowModel
Parameters:
group - the Group object
Returns:
index first group's row in rowList

getHeaderValue

public Object getHeaderValue(int row)
Description copied from interface: TableRowModel
Returns value for row's header

Specified by:
getHeaderValue in interface TableRowModel
Parameters:
row - the row's number
Returns:
value for row's header

updateHeaderValue

protected void updateHeaderValue()

clearPageHeader

protected void clearPageHeader(int startRow)
removes all page headers and page footers from report


getCellPosition

public CellCoord getCellPosition(Cell cell)

updatePages

public void updatePages(int startRow,
                        int pageHeight)
Description copied from interface: TableRowModel
Calculates pages' size

Specified by:
updatePages in interface TableRowModel
Parameters:
startRow - the first row for calculation
pageHeight - page height in pixels

getOwnerRow

public int getOwnerRow(Cell cell,
                       int row,
                       int column)

getGroup

public Group getGroup(int[] path)
Specified by:
getGroup in interface TableRowModel

setPageHeight

public void setPageHeight(int pageHeight)
Parameters:
pageHeight - The pageHeight to set.

getPageHeight

public int getPageHeight()
Returns:
Returns the pageHeight.

setRowHeight

public void setRowHeight(int row,
                         double h)
Description copied from interface: TableRowModel
Sets the height for row to h. The height of the cells in this row will be equal to the row height minus the row margin.

Specified by:
setRowHeight in interface TableRowModel
Parameters:
row - the row whose height is being changed
h - new row height, in 1/72 of inch

setCanHideGroup

protected void setCanHideGroup(boolean canHideGroup)
Parameters:
canHideGroup - the canHideGroup to set

isCanHideGroup

public boolean isCanHideGroup()
Specified by:
isCanHideGroup in interface TableRowModel
Returns:
the canHideGroup

setDirtyHeader

protected void setDirtyHeader(boolean dirtyHeader)
Parameters:
dirtyHeader - the dirtyHeader to set

isDirtyHeader

protected boolean isDirtyHeader()
Returns:
the dirtyHeader

isCanUpdatePages

public boolean isCanUpdatePages()
Description copied from interface: TableRowModel
Returns the possibility of calculation of pages' size

Specified by:
isCanUpdatePages in interface TableRowModel
Returns:
if true, pages' size are calculated automatically

setCanUpdatePages

public void setCanUpdatePages(boolean b)
Description copied from interface: TableRowModel
Sets canUpdatePages property

Specified by:
setCanUpdatePages in interface TableRowModel
Parameters:
b - the canUpdatePages property

getFirstPageNumber

public int getFirstPageNumber()
Description copied from interface: TableRowModel
Returns number of the first page

Specified by:
getFirstPageNumber in interface TableRowModel
Returns:
number of the first page

setFirstPageNumber

public void setFirstPageNumber(int firstPageNumber)
Description copied from interface: TableRowModel
Sets number of the first page

Specified by:
setFirstPageNumber in interface TableRowModel
Parameters:
firstPageNumber - number of the first page

getPageNumber

public Integer getPageNumber(int row,
                             int column)
Description copied from interface: TableRowModel
Returns number of page for a cell on a row and a column

Specified by:
getPageNumber in interface TableRowModel
Returns:
number of page

isPrintLeftToRight

public boolean isPrintLeftToRight()
Description copied from interface: TableRowModel
Direction of an output of pages on the printer. If true that pages are printed from left to right, from top to down, differently pages are printed from top to down, from left to right.

Specified by:
isPrintLeftToRight in interface TableRowModel
Returns:
true if pages are printed from left to right, otherwise false

setPrintLeftToRight

public void setPrintLeftToRight(boolean value)
Description copied from interface: TableRowModel
Direction of an output of pages on the printer. If true that pages are printed from left to right, from top to down, differently pages are printed from top to down, from left to right.

Specified by:
setPrintLeftToRight in interface TableRowModel

getPageCount

public int getPageCount()
Description copied from interface: TableRowModel
Returns count of pages

Specified by:
getPageCount in interface TableRowModel
Returns:
count of pages

iterator

public Iterator<TableRow> iterator()
Specified by:
iterator in interface Iterable<TableRow>

setShowPageNumber

public void setShowPageNumber(boolean show)
Specified by:
setShowPageNumber in interface TableRowModel