001:
002: //The contents of this file are subject to the Mozilla Public License Version 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
014: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
015: //
016: //All Rights Reserved.
017:
018: package org.columba.calendar.ui.list;
019:
020: import java.awt.Component;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.DefaultCellEditor;
026: import javax.swing.JCheckBox;
027: import javax.swing.JTable;
028: import javax.swing.SwingUtilities;
029:
030: import org.columba.calendar.base.api.ICalendarItem;
031:
032: /**
033: *
034: *
035: * @author fdietz
036: */
037:
038: public class CheckableListEditor extends DefaultCellEditor implements
039: ActionListener {
040:
041: private JCheckBox checkbox = new JCheckBox();
042:
043: private Boolean selected;
044:
045: /**
046: *
047: */
048: public CheckableListEditor() {
049: super (new JCheckBox());
050:
051: checkbox.setHorizontalAlignment(SwingUtilities.CENTER);
052:
053: checkbox.addActionListener(this );
054: checkbox.setOpaque(true);
055: //checkbox.setBorder(BorderFactory.createEmptyBorder(2,4,2,4));
056:
057: }
058:
059: public Component getTableCellEditorComponent(JTable table,
060: Object value, boolean isSelected, int row, int column) {
061:
062: if (isSelected) {
063: checkbox.setForeground(table.getSelectionForeground());
064: checkbox.setBackground(table.getSelectionBackground());
065: } else {
066: checkbox.setForeground(table.getForeground());
067: checkbox.setBackground(table.getBackground());
068: }
069:
070: ICalendarItem item = (ICalendarItem) value;
071:
072: //checkbox.setBackground(item.getColor());
073:
074: checkbox.setSelected(item.isSelected());
075:
076: return checkbox;
077: }
078:
079: /**
080: * @see javax.swing.CellEditor#getCellEditorValue()
081: */
082: public Object getCellEditorValue() {
083:
084: return selected;
085: }
086:
087: public void actionPerformed(ActionEvent e) {
088:
089: //item.setSelected(checkbox.isSelected());
090: selected = Boolean.valueOf(checkbox.isSelected());
091:
092: fireEditingStopped(); //Make the renderer reappear.
093:
094: }
095:
096: /**
097: * @see javax.swing.DefaultCellEditor#getComponent()
098: */
099: public Component getComponent() {
100: return checkbox;
101: }
102:
103: }
|