View Javadoc

1   /***
2    * CompositeTableCellRenderer.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2004 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.swing.table;
27  
28  import java.awt.Component;
29  
30  import javax.swing.JTable;
31  import javax.swing.table.DefaultTableCellRenderer;
32  import javax.swing.table.TableCellRenderer;
33  
34  /***
35   * This TableCellRenderer is designed to be used with a transposable model. It
36   * should be defined as the Default renderer for the
37   * TransposableTableModel.TransposedValue class.
38   * 
39   * This renderer only works through the default renderers defined on a per class
40   * basis. A mechanism can be developped to provide a renderer on a per line
41   * basis (to match the per column renderer) but would hardly resist to sorting
42   * in general.
43   * 
44   * @author $Author: dbregeon $
45   * @version $Revision: 1.1 $
46   */
47  public class ValueDrivenTableCellRenderer implements TableCellRenderer {
48      /***
49       * The default renderer if none is not found in the JTable.
50       */
51      private final TableCellRenderer defaultRenderer = new DefaultTableCellRenderer();
52  
53      /***
54       * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
55       *      java.lang.Object, boolean, boolean, int, int)
56       */
57      public Component getTableCellRendererComponent(JTable table, Object value,
58              boolean isSelected, boolean hasFocus, int row, int column) {
59          TableCellRenderer renderer = null;
60          if ((table != null) && (value != null)) {
61              renderer = table.getDefaultRenderer(value.getClass());
62          }
63          if (renderer == null) {
64              renderer = this.defaultRenderer;
65          }
66          return renderer.getTableCellRendererComponent(table, value, isSelected,
67                  hasFocus, row, column);
68      }
69  }