/************************************************************************
*
* TableView.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2011 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2011-04-20)
*
*/
package writer2latex.office;
import org.w3c.dom.Element;
import writer2latex.util.Misc;
/**
* This class represents a view of a TableRange
. A view provides
* read access to the range using a simple grid model.
*/
public class TableView {
private TableReader reader;
private TableRange range;
// The size of the view (visible part of the range)
private int nRowCount;
private int nColCount;
// Map view row/col index to original index
private int[] nRowMap;
private int[] nColMap;
// The cells in the view
private CellView[][] cells;
public TableView(TableReader reader, TableRange range) {
this.reader = reader;
this.range = range;
// Count visible rows & cols in this range
nRowCount = 0;
for (int nRow=range.getFirstRow(); nRow<=range.getLastRow(); nRow++) {
if (isVisibleRow(nRow)) { nRowCount++; }
}
nColCount = 0;
for (int nCol=range.getFirstCol(); nCol<=range.getLastCol(); nCol++) {
if (isVisibleCol(nCol)) { nColCount++; }
}
// Fill the row & col maps
nRowMap = new int[nRowCount];
int nRealRow = range.getFirstRow();
for (int nRow=0; nRow=range.getFirstRow() && nRow<=range.getLastRow() &&
(range.includeHidden() || !reader.getRow(nRow).isCollapse()) &&
(range.includeFiltered() || !reader.getRow(nRow).isFilter());
}
// Helper method: Is this column visible in this view?
private boolean isVisibleCol(int nCol) {
return nCol>=range.getFirstCol() && nCol<=range.getLastCol() &&
(range.includeHidden() || !reader.getCol(nCol).isCollapse()) &&
(range.includeFiltered() || !reader.getCol(nCol).isFilter());
}
}