KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > CellEditor


1 /*
2  * @(#)CellEditor.java 1.24 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing;
9
10 import java.util.EventObject JavaDoc;
11 import javax.swing.event.*;
12
13 /**
14  * This interface defines the methods any general editor should be able
15  * to implement. <p>
16  *
17  * Having this interface enables complex components (the client of the
18  * editor) such as <code>JList</code>, <code>JTree</code>, and
19  * <code>JTable</code> to allow any generic editor to
20  * edit values in a table cell, or tree cell, etc. Without this generic
21  * editor interface, <code>JTable</code> would have to know about specific editors,
22  * such as <code>JTextField</code>, <code>JCheckBox</code>, <code>JComboBox</code>,
23  * etc. In addition, without this interface, clients of editors such as
24  * <code>JTable</code> would not be able
25  * to work with any editors developed in the future by the user
26  * or a 3rd party ISV. <p>
27  *
28  * To use this interface, a developer creating a new editor can have the
29  * new component implement the interface. Or the developer can
30  * choose a wrapper based approach and provide a companion object which
31  * implements the <code>CellEditor</code> interface (See
32  * <code>JCellEditor</code> for example). The wrapper approach
33  * is particularly useful if the user want to use a 3rd party ISV
34  * editor with <code>JTable</code>, but the ISV didn't implement the
35  * <code>CellEditor</code> interface. The user can simply create an object
36  * that contains an instance of the 3rd party editor object and "translate"
37  * the <code>CellEditor</code> API into the 3rd party editor's API.
38  *
39  * @see javax.swing.event.CellEditorListener
40  *
41  * @version 1.24 12/19/03
42  * @author Alan Chung
43  */

44 public interface CellEditor {
45
46     /**
47      * Returns the value contained in the editor.
48      * @return the value contained in the editor
49      */

50     public Object JavaDoc getCellEditorValue();
51
52     /**
53      * Asks the editor if it can start editing using <code>anEvent</code>.
54      * <code>anEvent</code> is in the invoking component coordinate system.
55      * The editor can not assume the Component returned by
56      * <code>getCellEditorComponent</code> is installed. This method
57      * is intended for the use of client to avoid the cost of setting up
58      * and installing the editor component if editing is not possible.
59      * If editing can be started this method returns true.
60      *
61      * @param anEvent the event the editor should use to consider
62      * whether to begin editing or not
63      * @return true if editing can be started
64      * @see #shouldSelectCell
65      */

66     public boolean isCellEditable(EventObject JavaDoc anEvent);
67
68     /**
69      * Returns true if the editing cell should be selected, false otherwise.
70      * Typically, the return value is true, because is most cases the editing
71      * cell should be selected. However, it is useful to return false to
72      * keep the selection from changing for some types of edits.
73      * eg. A table that contains a column of check boxes, the user might
74      * want to be able to change those checkboxes without altering the
75      * selection. (See Netscape Communicator for just such an example)
76      * Of course, it is up to the client of the editor to use the return
77      * value, but it doesn't need to if it doesn't want to.
78      *
79      * @param anEvent the event the editor should use to start
80      * editing
81      * @return true if the editor would like the editing cell to be selected;
82      * otherwise returns false
83      * @see #isCellEditable
84      */

85     public boolean shouldSelectCell(EventObject JavaDoc anEvent);
86
87     /**
88      * Tells the editor to stop editing and accept any partially edited
89      * value as the value of the editor. The editor returns false if
90      * editing was not stopped; this is useful for editors that validate
91      * and can not accept invalid entries.
92      *
93      * @return true if editing was stopped; false otherwise
94      */

95     public boolean stopCellEditing();
96
97     /**
98      * Tells the editor to cancel editing and not accept any partially
99      * edited value.
100      */

101     public void cancelCellEditing();
102
103     /**
104      * Adds a listener to the list that's notified when the editor
105      * stops, or cancels editing.
106      *
107      * @param l the CellEditorListener
108      */

109     public void addCellEditorListener(CellEditorListener l);
110
111     /**
112      * Removes a listener from the list that's notified
113      *
114      * @param l the CellEditorListener
115      */

116     public void removeCellEditorListener(CellEditorListener l);
117 }
118
Popular Tags