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: TableModelInfo.java,v 1.9 2007/04/01 18:49:32 taqua Exp $
027 * ------------
028 * (C) Copyright 2000-2005, by Object Refinery Limited.
029 * (C) Copyright 2005-2007, by Pentaho Corporation.
030 */
031
032 package org.jfree.report.modules.misc.tablemodel;
033
034 import javax.swing.table.TableModel;
035
036 /**
037 * A utility class that prints out information about a TableModel.
038 *
039 * @author Thomas Morgner
040 */
041 public final class TableModelInfo
042 {
043 /**
044 * DefaultConstructor.
045 */
046 private TableModelInfo ()
047 {
048 }
049
050 /**
051 * Prints a table model to standard output.
052 *
053 * @param mod the model.
054 */
055 public static void printTableModel (final TableModel mod)
056 {
057 System.out.println("Tablemodel contains " + mod.getRowCount() + " rows.");
058 for (int i = 0; i < mod.getColumnCount(); i++)
059 {
060 System.out.println("Column: " + i + " Name = " + mod.getColumnName(i) + "; DataType = "
061 + mod.getColumnClass(i));
062 }
063
064 System.out.println("Checking the data inside");
065 for (int rows = 0; rows < mod.getRowCount(); rows++)
066 {
067 for (int i = 0; i < mod.getColumnCount(); i++)
068 {
069 final Object value = mod.getValueAt(rows, i);
070 final Class c = mod.getColumnClass(i);
071 if (value == null)
072 {
073 System.out.println("ValueAt (" + rows + ", " + i + ") is null");
074 }
075 else
076 {
077 if (c.isAssignableFrom(value.getClass()) == false)
078 {
079 System.out.println
080 ("ValueAt (" + rows + ", " + i + ") is not assignable from " + c);
081 }
082 if (c.equals(Object.class))
083 {
084 System.out.println
085 ("ValueAt (" + rows + ", " + i + ") is in a generic column and is of "
086 + "type " + value.getClass());
087 }
088 }
089 }
090 }
091 }
092
093 /**
094 * Prints a table model to standard output.
095 *
096 * @param mod the model.
097 */
098 public static void printTableModelContents (final TableModel mod)
099 {
100 System.out.println("Tablemodel contains " + mod.getRowCount() + " rows.");
101 for (int i = 0; i < mod.getColumnCount(); i++)
102 {
103 System.out.println("Column: " + i + " Name = " + mod.getColumnName(i) + "; DataType = "
104 + mod.getColumnClass(i));
105 }
106
107 System.out.println("Checking the data inside");
108 for (int rows = 0; rows < mod.getRowCount(); rows++)
109 {
110 for (int i = 0; i < mod.getColumnCount(); i++)
111 {
112 final Object value = mod.getValueAt(rows, i);
113 //final Class c = mod.getColumnClass(i);
114 System.out.println("ValueAt (" + rows + ", " + i + ") is " + value);
115 }
116 }
117 }
118 }