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 */ 031 package org.jfree.report.modules.misc.tablemodel; 032 033 import javax.swing.event.TableModelListener; 034 import javax.swing.table.TableModel; 035 036 /** 037 * A tablemodel that allows to override the column names. This is usefull 038 * in internationalized environments, where the tablemodel returns diffent 039 * columnnames depending on the current locale. 040 * 041 * @author LordOfCode 042 */ 043 public class PrintableTableModel implements TableModel 044 { 045 046 /** The original TableModel. */ 047 private TableModel model; 048 /** 049 * The column keys to retrieve the internationalized names from the 050 * ResourceBundle. 051 */ 052 private String[] i18nKeys; 053 054 055 public PrintableTableModel(final TableModel source, final String[] keys) 056 { 057 model = source; 058 i18nKeys = keys; 059 } 060 061 public int getColumnCount() 062 { 063 return model.getColumnCount(); 064 } 065 066 public int getRowCount() 067 { 068 return model.getRowCount(); 069 } 070 071 072 public boolean isCellEditable(final int rowIndex, final int columnIndex) 073 { 074 return model.isCellEditable(rowIndex, columnIndex); 075 } 076 077 public Class getColumnClass(final int columnIndex) 078 { 079 return model.getColumnClass(columnIndex); 080 } 081 082 public Object getValueAt(final int rowIndex, final int columnIndex) 083 { 084 return model.getValueAt(rowIndex, columnIndex); 085 } 086 087 public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) 088 { 089 model.setValueAt(aValue, rowIndex, columnIndex); 090 } 091 092 /** 093 * Retrieves the internationalized column name from the string array. 094 * 095 * @see TableModel#getColumnName(int) 096 */ 097 public String getColumnName(final int columnIndex) 098 { 099 if (columnIndex < i18nKeys.length) 100 { 101 final String columnName = i18nKeys[columnIndex]; 102 if (columnName != null) 103 { 104 return columnName; 105 } 106 } 107 return model.getColumnName(columnIndex); 108 } 109 110 public void addTableModelListener(final TableModelListener l) 111 { 112 model.addTableModelListener(l); 113 } 114 115 public void removeTableModelListener(final TableModelListener l) 116 { 117 model.removeTableModelListener(l); 118 } 119 }