001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * $Id: PrintableTableModel.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.modules.misc.tablemodel;
031:
032: import javax.swing.event.TableModelListener;
033: import javax.swing.table.TableModel;
034:
035: /**
036: * A tablemodel that allows to override the column names. This is usefull
037: * in internationalized environments, where the tablemodel returns diffent
038: * columnnames depending on the current locale.
039: *
040: * @author LordOfCode
041: */
042: public class PrintableTableModel implements TableModel {
043:
044: /** The original TableModel. */
045: private TableModel model;
046: /**
047: * The column keys to retrieve the internationalized names from the
048: * ResourceBundle.
049: */
050: private String[] i18nKeys;
051:
052: public PrintableTableModel(final TableModel source,
053: final String[] keys) {
054: model = source;
055: i18nKeys = keys;
056: }
057:
058: public int getColumnCount() {
059: return model.getColumnCount();
060: }
061:
062: public int getRowCount() {
063: return model.getRowCount();
064: }
065:
066: public boolean isCellEditable(final int rowIndex,
067: final int columnIndex) {
068: return model.isCellEditable(rowIndex, columnIndex);
069: }
070:
071: public Class getColumnClass(final int columnIndex) {
072: return model.getColumnClass(columnIndex);
073: }
074:
075: public Object getValueAt(final int rowIndex, final int columnIndex) {
076: return model.getValueAt(rowIndex, columnIndex);
077: }
078:
079: public void setValueAt(final Object aValue, final int rowIndex,
080: final int columnIndex) {
081: model.setValueAt(aValue, rowIndex, columnIndex);
082: }
083:
084: /**
085: * Retrieves the internationalized column name from the string array.
086: *
087: * @see TableModel#getColumnName(int)
088: */
089: public String getColumnName(final int columnIndex) {
090: if (columnIndex < i18nKeys.length) {
091: final String columnName = i18nKeys[columnIndex];
092: if (columnName != null) {
093: return columnName;
094: }
095: }
096: return model.getColumnName(columnIndex);
097: }
098:
099: public void addTableModelListener(final TableModelListener l) {
100: model.addTableModelListener(l);
101: }
102:
103: public void removeTableModelListener(final TableModelListener l) {
104: model.removeTableModelListener(l);
105: }
106: }
|