KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > list > CheckableListEditor


1
2
3 //The contents of this file are subject to the Mozilla Public License Version 1.1
4
//(the "License"); you may not use this file except in compliance with the
5
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
6
//
7
//Software distributed under the License is distributed on an "AS IS" basis,
8
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9
//for the specific language governing rights and
10
//limitations under the License.
11
//
12
//The Original Code is "The Columba Project"
13
//
14
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18

19 package org.columba.calendar.ui.list;
20 import java.awt.Component JavaDoc;
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23
24 import javax.swing.BorderFactory JavaDoc;
25 import javax.swing.DefaultCellEditor JavaDoc;
26 import javax.swing.JCheckBox JavaDoc;
27 import javax.swing.JTable JavaDoc;
28 import javax.swing.SwingUtilities JavaDoc;
29
30 import org.columba.calendar.base.api.ICalendarItem;
31
32 /**
33  *
34  *
35  * @author fdietz
36  */

37
38 public class CheckableListEditor
39     extends DefaultCellEditor JavaDoc
40     implements ActionListener JavaDoc {
41
42     private JCheckBox JavaDoc checkbox = new JCheckBox JavaDoc();
43     
44     private Boolean JavaDoc selected;
45
46     /**
47      *
48      */

49     public CheckableListEditor() {
50         super(new JCheckBox JavaDoc());
51
52         checkbox.setHorizontalAlignment(SwingUtilities.CENTER);
53         
54         checkbox.addActionListener(this);
55         checkbox.setOpaque(true);
56         //checkbox.setBorder(BorderFactory.createEmptyBorder(2,4,2,4));
57

58     }
59
60     public Component JavaDoc getTableCellEditorComponent(
61         JTable JavaDoc table,
62         Object JavaDoc value,
63         boolean isSelected,
64         int row,
65         int column) {
66
67         if (isSelected) {
68             checkbox.setForeground(table.getSelectionForeground());
69             checkbox.setBackground(table.getSelectionBackground());
70         } else {
71             checkbox.setForeground(table.getForeground());
72             checkbox.setBackground(table.getBackground());
73         }
74
75         ICalendarItem item = (ICalendarItem) value;
76
77         //checkbox.setBackground(item.getColor());
78

79         checkbox.setSelected(item.isSelected());
80         
81
82         return checkbox;
83     }
84
85     /**
86      * @see javax.swing.CellEditor#getCellEditorValue()
87      */

88     public Object JavaDoc getCellEditorValue() {
89
90         return selected;
91     }
92
93     public void actionPerformed(ActionEvent JavaDoc e) {
94
95         //item.setSelected(checkbox.isSelected());
96
selected= Boolean.valueOf(checkbox.isSelected());
97
98         fireEditingStopped(); //Make the renderer reappear.
99

100     }
101
102     /**
103      * @see javax.swing.DefaultCellEditor#getComponent()
104      */

105     public Component JavaDoc getComponent() {
106         return checkbox;
107     }
108
109 }
110
Popular Tags