1   package org.wcb.gui.renderer;
2   
3   
4   import org.wcb.model.vo.TotalLogEntriesVO;
5   
6   
7   import javax.swing.*;
8   import javax.swing.table.TableCellRenderer;
9   import javax.swing.table.TableCellEditor;
10  import javax.swing.table.TableColumnModel;
11  
12  import java.awt.*;
13  
14  
15  /**
16   * <small>
17   * Copyright (c)  2006  wbogaardt.
18   * This library is free software; you can redistribute it and/or
19   * modify it under the terms of the GNU Lesser General Public
20   * License as published by the Free Software Foundation; either
21   * version 2.1 of the License, or (at your option) any later version.
22   *
23   * This library is distributed in the hope that it will be useful,
24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26   * Lesser General Public License for more details.
27   *
28   * You should have received a copy of the GNU Lesser General Public
29   * License along with this library; if not, write to the Free Software
30   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31   * <p/>
32   * $File:  $ <br>
33   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 30, 2006 10:27:43 AM $ <br>
34   * </small>
35   *
36   * @author wbogaardt
37   * @version 1
38   *          Date: Mar 30, 2006
39   *          Time: 10:27:43 AM
40   */
41  
42  public class RowButtonTableCell extends AbstractCellEditor
43          implements TableCellRenderer, TableCellEditor
44  {
45      private JButton renderButton;
46      private JButton editButton;
47      private Object tableObject;
48  
49      public RowButtonTableCell(JTable table, int column)
50      {
51          super();
52          renderButton = new JButton();
53          editButton = new JButton();
54          editButton.setFocusPainted(false);
55          TableColumnModel columnModel = table.getColumnModel();
56          columnModel.getColumn(column).setCellRenderer(this);
57          columnModel.getColumn(column).setCellEditor(this);
58          columnModel.getColumn(column).setMaxWidth(60);
59      }
60  
61      public Component getTableCellRendererComponent(
62              JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
63      {
64          if(value instanceof TotalLogEntriesVO)
65          {
66              return new JLabel("");
67          }
68          renderButton.setText(Integer.toString(row));
69          if (hasFocus)
70          {
71              renderButton.setForeground(table.getForeground());
72              renderButton.setBackground(UIManager.getColor("Button.background"));
73          }
74          else if (isSelected)
75          {
76              renderButton.setForeground(table.getSelectionForeground());
77              renderButton.setBackground(table.getSelectionBackground());
78          }
79          else
80          {
81              renderButton.setForeground(table.getForeground());
82              renderButton.setBackground(UIManager.getColor("Button.background"));
83          }
84          return renderButton;
85      }
86  
87      public Component getTableCellEditorComponent(
88              JTable table, Object value, boolean isSelected, int row, int column)
89      {
90           if(value instanceof TotalLogEntriesVO) {
91              return new JLabel("");
92          }
93          tableObject = value;
94          editButton.setText(" " + row );
95          return editButton;
96      }
97  
98      public Object getCellEditorValue()
99      {
100         return tableObject;
101     }
102 }