org.jfree.report.demo.invoice
public class: InvoiceTableModel [javadoc |
source]
java.lang.Object
javax.swing.table.AbstractTableModel
org.jfree.report.demo.invoice.InvoiceTableModel
All Implemented Interfaces:
Serializable, TableModel
========================================
JFreeReport : a free Java report library
========================================
Project Info: http://www.jfree.org/jfreereport/index.html
Project Lead: Thomas Morgner (taquera@sherito.org);
(C) Copyright 2000-2004, by Simba Management Limited and Contributors.
This library is free software; you can redistribute it and/or modify it under the terms
of the GNU Lesser General Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any later version.
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.
------------------------------
InvoiceTableModel.java
------------------------------
(C)opyright 2004, by Thomas Morgner and Contributors.
Original Author: Thomas Morgner;
Contributor(s): David Gilbert (for Simba Management Limited);
$Id: InvoiceTableModel.java,v 1.1.2.2 2004/04/05 16:49:34 taqua Exp $
Changes
-------------------------
26.03.2004 : Initial version
| Methods from javax.swing.table.AbstractTableModel: |
|---|
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt |
| Method from org.jfree.report.demo.invoice.InvoiceTableModel Detail: |
public void addInvoice(Invoice invoice) {
invoices.add (invoice);
invalidateCaches();
fireTableDataChanged();
}
|
public Class getColumnClass(int columnIndex) {
return COLUMN_TYPES[columnIndex];
}
Returns Object.class regardless of columnIndex. |
public int getColumnCount() {
return COLUMN_NAMES.length;
}
Returns the number of columns in the model. A JTable uses this method to
determine how many columns it should create and display by default. |
public String getColumnName(int column) {
return COLUMN_NAMES[column];
}
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z,
AA, AB, etc. If column cannot be found, returns an empty string. |
public Invoice getInvoice(int invoice) {
return (Invoice) invoices.get (invoice);
}
|
public int getRowCount() {
return totalSize;
}
Returns the number of rows in the model. A JTable uses this method to
determine how many rows it should display. This method should be quick, as it is
called frequently during rendering. |
public Object getValueAt(int rowIndex,
int columnIndex) {
// just make sure we can access the invoices by the array
fillCache();
final Invoice inv = invoicePerRow[rowIndex];
final Article art = articlesPerRow[rowIndex];
switch (columnIndex)
{
case 0: return inv;
case 1: return inv.getCustomer().getFirstName();
case 2: return inv.getCustomer().getLastName();
case 3: return inv.getCustomer().getStreet();
case 4: return inv.getCustomer().getTown();
case 5: return inv.getCustomer().getPostalCode();
case 6: return inv.getCustomer().getCountry();
case 7: return inv.getCustomer().getSalutation();
case 8: return inv.getDate();
case 9: return inv.getInvoiceNumber();
case 10: return art.getName();
case 11: return art.getArticleNumber();
case 12: return art.getArticleDetails();
case 13: return new Float(art.getPrice());
case 14: return new Integer(inv.getArticleCount());
}
throw new IndexOutOfBoundsException("ColumnIndex");
}
Returns the value for the cell at columnIndex and
rowIndex. |
public void invalidateCaches() {
int size = 0;
for (int i = 0; i < invoices.size(); i++)
{
final Invoice inv = getInvoice(i);
size += inv.getArticleCount();
}
this.totalSize = size;
this.invoicePerRow = null;
this.articlesPerRow = null;
}
|
public void removeInvoice(Invoice invoice) {
invoices.remove (invoice);
invalidateCaches();
fireTableDataChanged();
}
|