View Javadoc

1   package org.wcb.common;
2   
3   import javax.swing.*;
4   import java.awt.*;
5   import java.awt.event.ActionListener;
6   import java.awt.event.ActionEvent;
7   
8   /***
9    * Copyright (C) 2003  Walter Bogaardt
10   *
11   * This library is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU Lesser General Public
13   * License as published by the Free Software Foundation; either
14   * version 2 of the License, or (at your option) any later version.
15   *
16   * This library is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   * Lesser General Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser General Public
22   * License along with this library; if not, write to the Free Software
23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
24   *
25   *  Project:   Home Automation Interface
26   *
27   *  Abstract:  User Interface options dialog box
28   *  Filename:  $Id: ColorCellEditor.java,v 1.3 2004/01/08 15:06:29 wbogaardt Exp $
29   *
30   *  $Log: ColorCellEditor.java,v $
31   *  Revision 1.3  2004/01/08 15:06:29  wbogaardt
32   *  refactored the email, color, font, and general panels out of the UIDialog Panel.
33   *
34   *  Revision 1.2  2003/12/30 22:15:59  wbogaardt
35   *  added javadoc comments
36   *
37   */
38  public class ColorCellEditor  extends DefaultCellEditor {
39  
40      public Color currentColor = null;
41  
42      public ColorCellEditor(JButton b) {
43          super(new JCheckBox()); //Unfortunately, the constructor
44          //expects a check box, combo box,
45          //or text field.
46          editorComponent = b;
47          setClickCountToStart(1); //This is usually 1 or 2.
48  
49          //Must do this so that editing stops when appropriate.
50          b.addActionListener(new ActionListener() {
51              public void actionPerformed(ActionEvent e) {
52                  fireEditingStopped();
53              }
54          });
55      }
56  
57      protected void fireEditingStopped() {
58          super.fireEditingStopped();
59      }
60  
61      public Object getCellEditorValue() {
62          return currentColor;
63      }
64  
65      public Component getTableCellEditorComponent(JTable table,
66                                                   Object value,
67                                                   boolean isSelected,
68                                                   int row,
69                                                   int column) {
70          ((JButton)editorComponent).setText(value.toString());
71          currentColor = (Color)value;
72          return editorComponent;
73      }
74  }