View Javadoc

1   /***
2    * ValueDrivenTableCellEditor.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.AbstractCellEditor;
31  import javax.swing.JTable;
32  import javax.swing.table.TableCellEditor;
33  
34  /***
35   * This TableCellEditor is designed to be used with a transposable model. It
36   * should be defined as the Default editor for the
37   * TransposableTableModel.TransposedValue class.
38   * 
39   * This editor only works through the default editors defined on a per class
40   * basis. A mechanism can be developped to provide an editor on a per line basis
41   * (to match the per column renderer) but would hardly resist to sorting in
42   * general.
43   * 
44   * @author $Author: dbregeon $
45   * @version $Revision: 1.1 $
46   */
47  public class ValueDrivenTableCellEditor extends AbstractCellEditor implements
48          TableCellEditor {
49      /***
50       * The actual editor in use.
51       */
52      private TableCellEditor currentEditor = null;
53  
54      /***
55       * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable,
56       *      java.lang.Object, boolean, int, int)
57       */
58      public Component getTableCellEditorComponent(JTable table, Object value,
59              boolean isSelected, int row, int column) {
60          Component result = null;
61          if ((table != null) && (value != null)) {
62              this.currentEditor = table.getDefaultEditor(value.getClass());
63              result = this.currentEditor.getTableCellEditorComponent(table,
64                      value, isSelected, row, column);
65          }
66          return result;
67      }
68  
69      /***
70       * @see javax.swing.CellEditor#getCellEditorValue()
71       */
72      public Object getCellEditorValue() {
73          Object result = null;
74          if (this.currentEditor != null) {
75              result = this.currentEditor.getCellEditorValue();
76          }
77          return result;
78      }
79  }