jdk/src/java.desktop/share/classes/javax/swing/CellEditor.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26035 jdk/src/share/classes/javax/swing/CellEditor.java@250f55e44bea
parent 25859 jdk/src/share/classes/javax/swing/CellEditor.java@3317bb8137f4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26035
250f55e44bea 6302052: Reference to nonexistant Class in javadoc
serb
parents: 25201
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This interface defines the methods any general editor should be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * to implement. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Having this interface enables complex components (the client of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * editor) such as <code>JTree</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <code>JTable</code> to allow any generic editor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * edit values in a table cell, or tree cell, etc.  Without this generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * editor interface, <code>JTable</code> would have to know about specific editors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * such as <code>JTextField</code>, <code>JCheckBox</code>, <code>JComboBox</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * etc.  In addition, without this interface, clients of editors such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>JTable</code> would not be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * to work with any editors developed in the future by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * or a 3rd party ISV. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * To use this interface, a developer creating a new editor can have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * new component implement the interface.  Or the developer can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * choose a wrapper based approach and provide a companion object which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * implements the <code>CellEditor</code> interface (See
26035
250f55e44bea 6302052: Reference to nonexistant Class in javadoc
serb
parents: 25201
diff changeset
    50
 * <code>DefaultCellEditor</code> for example).  The wrapper approach
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * is particularly useful if the user want to use a 3rd party ISV
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * editor with <code>JTable</code>, but the ISV didn't implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>CellEditor</code> interface.  The user can simply create an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * that contains an instance of the 3rd party editor object and "translate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the <code>CellEditor</code> API into the 3rd party editor's API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see javax.swing.event.CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Alan Chung
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 5506
diff changeset
    60
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public interface CellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Returns the value contained in the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return the value contained in the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public Object getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Asks the editor if it can start editing using <code>anEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>anEvent</code> is in the invoking component coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The editor can not assume the Component returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>getCellEditorComponent</code> is installed.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * is intended for the use of client to avoid the cost of setting up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * and installing the editor component if editing is not possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * If editing can be started this method returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param   anEvent         the event the editor should use to consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *                          whether to begin editing or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @return  true if editing can be started
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @see #shouldSelectCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public boolean isCellEditable(EventObject anEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Returns true if the editing cell should be selected, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Typically, the return value is true, because is most cases the editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * cell should be selected.  However, it is useful to return false to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * keep the selection from changing for some types of edits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * eg. A table that contains a column of check boxes, the user might
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * want to be able to change those checkboxes without altering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * selection.  (See Netscape Communicator for just such an example)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Of course, it is up to the client of the editor to use the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * value, but it doesn't need to if it doesn't want to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param   anEvent         the event the editor should use to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *                          editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return  true if the editor would like the editing cell to be selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *    otherwise returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #isCellEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public boolean shouldSelectCell(EventObject anEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Tells the editor to stop editing and accept any partially edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * value as the value of the editor.  The editor returns false if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * editing was not stopped; this is useful for editors that validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * and can not accept invalid entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return  true if editing was stopped; false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public boolean stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Tells the editor to cancel editing and not accept any partially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * edited value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Adds a listener to the list that's notified when the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * stops, or cancels editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param   l               the CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public void addCellEditorListener(CellEditorListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Removes a listener from the list that's notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param   l               the CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void removeCellEditorListener(CellEditorListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}