/*
* $Id: XRefTableModel.java 49 2007-05-19 19:24:42Z chammer $
* Copyright (c) 2005-2007 Carsten Hammer, Bruno Lowagie
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This class was originally published under the MPL by Carsten Hammer.
* It was a part of iText, a Java-PDF library. You can now use it under
* the MIT License; for backward compatibility you can also use it under
* the MPL version 1.1: http://www.mozilla.org/MPL/
* A copy of the MPL license is bundled with the source code FYI.
*/
package com.lowagie.tools.swing;
import javax.swing.table.AbstractTableModel;
import com.lowagie.text.pdf.PdfObject;
import com.lowagie.text.pdf.PdfReader;
/**
* Given a PdfReader object, this class gives you access to the cross-reference
* table of the PDF file using the AbstractTableModel API.
*/
public class XRefTableModel extends AbstractTableModel {
/** a serial version id */
private static final long serialVersionUID = 8820950528057757413L;
/** The reader object. */
private PdfReader reader;
/**
* Constructs the table model class.
*
* @param reader PdfReader
*/
public XRefTableModel(PdfReader reader) {
this.reader = reader;
}
/**
*
* @see javax.swing.table.TableModel#getColumnCount()
* @return int
*/
public int getColumnCount() {
return 2;
}
/**
*
* @see javax.swing.table.TableModel#getRowCount()
* @return int
*/
public int getRowCount() {
return reader.getXrefSize() - 1;
}
/**
*
* @see javax.swing.table.TableModel#getValueAt(int, int)
* @param rowIndex int
* @param columnIndex int
* @return Object
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return new Integer(rowIndex + 1);
case 1:
PdfObject object = reader.getPdfObject(rowIndex + 1);
if (object != null && object.isStream()) {
return "Stream " + object;
} else {
return object;
}
default:
return null;
}
}
/**
* Returns the name of the column at <code>columnIndex</code>.
*
* @param columnIndex
* the index of the column
* @return the name of the column
*/
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0:
return "XRefNr";
case 1:
return "Object";
default:
return null;
}
}
}