Path: blob/master/src/java.desktop/share/classes/javax/swing/CellEditor.java
41153 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.swing;2627import java.util.EventObject;28import javax.swing.event.*;2930/**31* This interface defines the methods any general editor should be able32* to implement. <p>33*34* Having this interface enables complex components (the client of the35* editor) such as <code>JTree</code> and36* <code>JTable</code> to allow any generic editor to37* edit values in a table cell, or tree cell, etc. Without this generic38* editor interface, <code>JTable</code> would have to know about specific editors,39* such as <code>JTextField</code>, <code>JCheckBox</code>, <code>JComboBox</code>,40* etc. In addition, without this interface, clients of editors such as41* <code>JTable</code> would not be able42* to work with any editors developed in the future by the user43* or a 3rd party ISV. <p>44*45* To use this interface, a developer creating a new editor can have the46* new component implement the interface. Or the developer can47* choose a wrapper based approach and provide a companion object which48* implements the <code>CellEditor</code> interface (See49* <code>DefaultCellEditor</code> for example). The wrapper approach50* is particularly useful if the user want to use a 3rd party ISV51* editor with <code>JTable</code>, but the ISV didn't implement the52* <code>CellEditor</code> interface. The user can simply create an object53* that contains an instance of the 3rd party editor object and "translate"54* the <code>CellEditor</code> API into the 3rd party editor's API.55*56* @see javax.swing.event.CellEditorListener57*58* @author Alan Chung59* @since 1.260*/61public interface CellEditor {6263/**64* Returns the value contained in the editor.65* @return the value contained in the editor66*/67public Object getCellEditorValue();6869/**70* Asks the editor if it can start editing using <code>anEvent</code>.71* <code>anEvent</code> is in the invoking component coordinate system.72* The editor can not assume the Component returned by73* <code>getCellEditorComponent</code> is installed. This method74* is intended for the use of client to avoid the cost of setting up75* and installing the editor component if editing is not possible.76* If editing can be started this method returns true.77*78* @param anEvent the event the editor should use to consider79* whether to begin editing or not80* @return true if editing can be started81* @see #shouldSelectCell82*/83public boolean isCellEditable(EventObject anEvent);8485/**86* Returns true if the editing cell should be selected, false otherwise.87* Typically, the return value is true, because is most cases the editing88* cell should be selected. However, it is useful to return false to89* keep the selection from changing for some types of edits.90* eg. A table that contains a column of check boxes, the user might91* want to be able to change those checkboxes without altering the92* selection. (See Netscape Communicator for just such an example)93* Of course, it is up to the client of the editor to use the return94* value, but it doesn't need to if it doesn't want to.95*96* @param anEvent the event the editor should use to start97* editing98* @return true if the editor would like the editing cell to be selected;99* otherwise returns false100* @see #isCellEditable101*/102public boolean shouldSelectCell(EventObject anEvent);103104/**105* Tells the editor to stop editing and accept any partially edited106* value as the value of the editor. The editor returns false if107* editing was not stopped; this is useful for editors that validate108* and can not accept invalid entries.109*110* @return true if editing was stopped; false otherwise111*/112public boolean stopCellEditing();113114/**115* Tells the editor to cancel editing and not accept any partially116* edited value.117*/118public void cancelCellEditing();119120/**121* Adds a listener to the list that's notified when the editor122* stops, or cancels editing.123*124* @param l the CellEditorListener125*/126public void addCellEditorListener(CellEditorListener l);127128/**129* Removes a listener from the list that's notified130*131* @param l the CellEditorListener132*/133public void removeCellEditorListener(CellEditorListener l);134}135136137