Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/CellEditor.java
38829 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*/60public interface CellEditor {6162/**63* Returns the value contained in the editor.64* @return the value contained in the editor65*/66public Object getCellEditorValue();6768/**69* Asks the editor if it can start editing using <code>anEvent</code>.70* <code>anEvent</code> is in the invoking component coordinate system.71* The editor can not assume the Component returned by72* <code>getCellEditorComponent</code> is installed. This method73* is intended for the use of client to avoid the cost of setting up74* and installing the editor component if editing is not possible.75* If editing can be started this method returns true.76*77* @param anEvent the event the editor should use to consider78* whether to begin editing or not79* @return true if editing can be started80* @see #shouldSelectCell81*/82public boolean isCellEditable(EventObject anEvent);8384/**85* Returns true if the editing cell should be selected, false otherwise.86* Typically, the return value is true, because is most cases the editing87* cell should be selected. However, it is useful to return false to88* keep the selection from changing for some types of edits.89* eg. A table that contains a column of check boxes, the user might90* want to be able to change those checkboxes without altering the91* selection. (See Netscape Communicator for just such an example)92* Of course, it is up to the client of the editor to use the return93* value, but it doesn't need to if it doesn't want to.94*95* @param anEvent the event the editor should use to start96* editing97* @return true if the editor would like the editing cell to be selected;98* otherwise returns false99* @see #isCellEditable100*/101public boolean shouldSelectCell(EventObject anEvent);102103/**104* Tells the editor to stop editing and accept any partially edited105* value as the value of the editor. The editor returns false if106* editing was not stopped; this is useful for editors that validate107* and can not accept invalid entries.108*109* @return true if editing was stopped; false otherwise110*/111public boolean stopCellEditing();112113/**114* Tells the editor to cancel editing and not accept any partially115* edited value.116*/117public void cancelCellEditing();118119/**120* Adds a listener to the list that's notified when the editor121* stops, or cancels editing.122*123* @param l the CellEditorListener124*/125public void addCellEditorListener(CellEditorListener l);126127/**128* Removes a listener from the list that's notified129*130* @param l the CellEditorListener131*/132public void removeCellEditorListener(CellEditorListener l);133}134135136