View Javadoc

1   /*
2      Copyright 2009 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.ui.field;
17  
18  import static fulmine.util.Utils.EMPTY_STRING;
19  
20  import java.awt.Component;
21  
22  import javax.swing.JCheckBox;
23  import javax.swing.JTable;
24  
25  /**
26   * A field UI that uses a {@link JCheckBox} as the UI.
27   * 
28   * @author Ramon Servadei
29   */
30  public class JCheckBoxUI extends AbstractFieldUI
31  {
32      private static final long serialVersionUID = 1L;
33  
34      /** The backing renderer */
35      private final JCheckBox renderer;
36  
37      /** The backing editor */
38      private final JCheckBox editor;
39  
40      public JCheckBoxUI()
41      {
42          this.renderer = new JCheckBox();
43          this.renderer.setOpaque(true);
44          this.editor = new JCheckBox();
45          this.editor.setOpaque(true);
46      }
47  
48      public Component getTableCellEditorComponent(JTable table, Object value,
49          boolean isSelected, int row, int column)
50      {
51          this.editor.setSelected(Boolean.parseBoolean(EMPTY_STRING + value));
52          return this.editor;
53      }
54  
55      public Object getCellEditorValue()
56      {
57          return new Boolean(this.editor.isSelected());
58      }
59  
60      public Component getTableCellRendererComponent(JTable table, Object value,
61          boolean isSelected, boolean hasFocus, int row, int column)
62      {
63          this.renderer.setSelected(Boolean.parseBoolean(EMPTY_STRING + value));
64          return this.renderer;
65      }
66  }