Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/AbstractCellEditor.java
38829 views
/*1* Copyright (c) 1999, 2013, 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 javax.swing.event.*;28import java.util.EventObject;29import java.io.Serializable;3031/**32*33* A base class for <code>CellEditors</code>, providing default34* implementations for the methods in the <code>CellEditor</code>35* interface except <code>getCellEditorValue()</code>.36* Like the other abstract implementations in Swing, also manages a list37* of listeners.38*39* <p>40* <strong>Warning:</strong>41* Serialized objects of this class will not be compatible with42* future Swing releases. The current serialization support is43* appropriate for short term storage or RMI between applications running44* the same version of Swing. As of 1.4, support for long term storage45* of all JavaBeans™46* has been added to the <code>java.beans</code> package.47* Please see {@link java.beans.XMLEncoder}.48*49* @author Philip Milne50* @since 1.351*/5253public abstract class AbstractCellEditor implements CellEditor, Serializable {5455protected EventListenerList listenerList = new EventListenerList();56transient protected ChangeEvent changeEvent = null;5758// Force this to be implemented.59// public Object getCellEditorValue()6061/**62* Returns true.63* @param e an event object64* @return true65*/66public boolean isCellEditable(EventObject e) {67return true;68}6970/**71* Returns true.72* @param anEvent an event object73* @return true74*/75public boolean shouldSelectCell(EventObject anEvent) {76return true;77}7879/**80* Calls <code>fireEditingStopped</code> and returns true.81* @return true82*/83public boolean stopCellEditing() {84fireEditingStopped();85return true;86}8788/**89* Calls <code>fireEditingCanceled</code>.90*/91public void cancelCellEditing() {92fireEditingCanceled();93}9495/**96* Adds a <code>CellEditorListener</code> to the listener list.97* @param l the new listener to be added98*/99public void addCellEditorListener(CellEditorListener l) {100listenerList.add(CellEditorListener.class, l);101}102103/**104* Removes a <code>CellEditorListener</code> from the listener list.105* @param l the listener to be removed106*/107public void removeCellEditorListener(CellEditorListener l) {108listenerList.remove(CellEditorListener.class, l);109}110111/**112* Returns an array of all the <code>CellEditorListener</code>s added113* to this AbstractCellEditor with addCellEditorListener().114*115* @return all of the <code>CellEditorListener</code>s added or an empty116* array if no listeners have been added117* @since 1.4118*/119public CellEditorListener[] getCellEditorListeners() {120return listenerList.getListeners(CellEditorListener.class);121}122123/**124* Notifies all listeners that have registered interest for125* notification on this event type. The event instance126* is created lazily.127*128* @see EventListenerList129*/130protected void fireEditingStopped() {131// Guaranteed to return a non-null array132Object[] listeners = listenerList.getListenerList();133// Process the listeners last to first, notifying134// those that are interested in this event135for (int i = listeners.length-2; i>=0; i-=2) {136if (listeners[i]==CellEditorListener.class) {137// Lazily create the event:138if (changeEvent == null)139changeEvent = new ChangeEvent(this);140((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);141}142}143}144145/**146* Notifies all listeners that have registered interest for147* notification on this event type. The event instance148* is created lazily.149*150* @see EventListenerList151*/152protected void fireEditingCanceled() {153// Guaranteed to return a non-null array154Object[] listeners = listenerList.getListenerList();155// Process the listeners last to first, notifying156// those that are interested in this event157for (int i = listeners.length-2; i>=0; i-=2) {158if (listeners[i]==CellEditorListener.class) {159// Lazily create the event:160if (changeEvent == null)161changeEvent = new ChangeEvent(this);162((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);163}164}165}166}167168169