KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > plugin > EnabledEditor


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.plugin;
17
18 import java.awt.Component JavaDoc;
19
20 import javax.swing.AbstractCellEditor JavaDoc;
21 import javax.swing.JCheckBox JavaDoc;
22 import javax.swing.JTable JavaDoc;
23 import javax.swing.SwingConstants JavaDoc;
24 import javax.swing.table.TableCellEditor JavaDoc;
25
26
27 /**
28  * @author frd
29  *
30  * To change the template for this generated type comment go to
31  * Window>Preferences>Java>Code Generation>Code and Comments
32  */

33
34 public class EnabledEditor extends AbstractCellEditor JavaDoc implements TableCellEditor JavaDoc {
35     protected JCheckBox JavaDoc component = new JCheckBox JavaDoc();
36     protected PluginNode currentNode;
37
38     /**
39  *
40  */

41     public EnabledEditor() {
42         component.setHorizontalAlignment(SwingConstants.CENTER);
43     }
44
45     public int getClickCountToStart() {
46         return 1;
47     }
48
49     // This method is called when a cell value is edited by the user.
50
public Component JavaDoc getTableCellEditorComponent(JTable JavaDoc table, Object JavaDoc value,
51         boolean isSelected, int rowIndex, int vColIndex) {
52         currentNode = (PluginNode) value;
53
54         // Configure the component with the specified value
55
((JCheckBox JavaDoc) component).setSelected(currentNode.isEnabled());
56
57         if (isSelected) {
58             ((JCheckBox JavaDoc) component).setBackground(table.getSelectionBackground());
59         } else {
60             ((JCheckBox JavaDoc) component).setBackground(table.getBackground());
61         }
62
63         // Return the configured component
64
return component;
65     }
66
67     // This method is called when editing is completed.
68
// It must return the new value to be stored in the cell.
69
public Object JavaDoc getCellEditorValue() {
70         Boolean JavaDoc b = Boolean.valueOf(((JCheckBox JavaDoc) component).isSelected());
71
72         // enable/disable tree node
73
currentNode.setEnabled(b.booleanValue());
74
75         /*
76 // enable/disable plugin
77 String id = currentNode.getId();
78
79 MainInterface.pluginManager.setEnabled(id, b.booleanValue());
80 */

81         return b;
82     }
83
84     public Component JavaDoc getComponent() {
85         return component;
86     }
87 }
88
Popular Tags