jdk/src/java.desktop/share/classes/javax/swing/AbstractCellEditor.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 30464 929bafd0db6f
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30464
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A base class for <code>CellEditors</code>, providing default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * implementations for the methods in the <code>CellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * interface except <code>getCellEditorValue()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Like the other abstract implementations in Swing, also manages a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * of listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 5506
diff changeset
    46
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    53
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public abstract class AbstractCellEditor implements CellEditor, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
30464
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    56
    /**
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    57
     * The list of listeners.
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    58
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected EventListenerList listenerList = new EventListenerList();
30464
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    60
    /**
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    61
     * The change event.
929bafd0db6f 8075082: Fix missing doclint warnings in the javax.swing package
darcy
parents: 25859
diff changeset
    62
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30464
diff changeset
    63
    protected transient ChangeEvent changeEvent = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // Force this to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // public Object  getCellEditorValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param e  an event object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public boolean isCellEditable(EventObject e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param anEvent  an event object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public boolean shouldSelectCell(EventObject anEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Calls <code>fireEditingStopped</code> and returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        fireEditingStopped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Calls <code>fireEditingCanceled</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public void  cancelCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        fireEditingCanceled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Adds a <code>CellEditorListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param l  the new listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public void addCellEditorListener(CellEditorListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        listenerList.add(CellEditorListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Removes a <code>CellEditorListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param l  the listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void removeCellEditorListener(CellEditorListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        listenerList.remove(CellEditorListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Returns an array of all the <code>CellEditorListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * to this AbstractCellEditor with addCellEditorListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return all of the <code>CellEditorListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public CellEditorListener[] getCellEditorListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   127
        return listenerList.getListeners(CellEditorListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * is created lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void fireEditingStopped() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (listeners[i]==CellEditorListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * is created lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void fireEditingCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (listeners[i]==CellEditorListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}