/************************************************************************ * * TableView.java * * Copyright: 2002-2011 by Henrik Just * * This file is part of Writer2LaTeX. * * Writer2LaTeX is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Writer2LaTeX 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Writer2LaTeX. If not, see . * * 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()); } }