jdk/src/share/classes/java/beans/PropertyEditorSupport.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 11120 f8576c769572
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1272
diff changeset
     2
 * Copyright (c) 1996, 2007, 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: 1272
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: 1272
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: 1272
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1272
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1272
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 java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This is a support class to help build property editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 11120
diff changeset
    33
 * It can be used either as a base class or as a delegate.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class PropertyEditorSupport implements PropertyEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Constructs a <code>PropertyEditorSupport</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public PropertyEditorSupport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        setSource(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Constructs a <code>PropertyEditorSupport</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param source the source used for event firing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public PropertyEditorSupport(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if (source == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
           throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        setSource(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Returns the bean that is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * source of events. If the source has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * been explicitly set then this instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <code>PropertyEditorSupport</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return the source object or this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Object getSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Sets the source bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The source bean is used as the source of events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * for the property changes. This source should be used for information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * purposes only and should not be modified by the PropertyEditor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param source source object to be used for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public void setSource(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Set (or change) the object that is to be edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param value The new target object to be edited.  Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *     object should not be modified by the PropertyEditor, rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *     the PropertyEditor should create a new object to hold any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *     modified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        firePropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Gets the value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return The value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Determines whether the class will honor the paintValue method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return  True if the class will honor the paintValue method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public boolean isPaintable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Paint a representation of the value into a given area of screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * real estate.  Note that the propertyEditor is responsible for doing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * its own clipping so that it fits into the given rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * If the PropertyEditor doesn't honor paint requests (see isPaintable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * this method should be a silent noop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param gfx  Graphics object to paint into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param box  Rectangle within graphics object into which we should paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * This method is intended for use when generating Java code to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the value of the property.  It should return a fragment of Java code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * that can be used to initialize a variable with the current property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return A fragment of Java code representing an initializer for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *          current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public String getJavaInitializationString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return "???";
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Gets the property value as a string suitable for presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * to a human to edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return The property value as a string suitable for presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *       to a human to edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <p>   Returns null if the value can't be expressed as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>   If a non-null value is returned, then the PropertyEditor should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *       be prepared to parse that string back in setAsText().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String getAsText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return (this.value != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                ? this.value.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Sets the property value by parsing a given String.  May raise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * java.lang.IllegalArgumentException if either the String is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * badly formatted or if this kind of property can't be expressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * as text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param text  The string to be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void setAsText(String text) throws java.lang.IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            setValue(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        throw new java.lang.IllegalArgumentException(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * If the property value must be one of a set of known tagged values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * then this method should return an array of the tag values.  This can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * be used to represent (for example) enum values.  If a PropertyEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * supports tags, then it should support the use of setAsText with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * a tag value as a way of setting the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return The tag values for this property.  May be null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *   property cannot be represented as a tagged value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public String[] getTags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * A PropertyEditor may chose to make available a full custom Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * that edits its property value.  It is the responsibility of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * PropertyEditor to hook itself up to its editor Component itself and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * to report property value changes by firing a PropertyChange event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * The higher-level code that calls getCustomEditor may either embed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the Component in some larger property sheet, or it may put it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * its own individual dialog, or ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return A java.awt.Component that will allow a human to directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *      edit the current property value.  May be null if this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *      not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public java.awt.Component getCustomEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Determines whether the propertyEditor can provide a custom editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return  True if the propertyEditor can provide a custom editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public boolean supportsCustomEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
1272
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   236
     * Adds a listener for the value change.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   237
     * When the property editor changes its value
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   238
     * it should fire a {@link PropertyChangeEvent}
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   239
     * on all registered {@link PropertyChangeListener}s,
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   240
     * specifying the {@code null} value for the property name.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   241
     * If the source property is set,
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   242
     * it should be used as the source of the event.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   243
     * <p>
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   244
     * The same listener object may be added more than once,
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   245
     * and will be called as many times as it is added.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   246
     * If {@code listener} is {@code null},
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   247
     * no exception is thrown and no action is taken.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
1272
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   249
     * @param listener  the {@link PropertyChangeListener} to add
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public synchronized void addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (listeners == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   254
            listeners = new java.util.Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        listeners.addElement(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
1272
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   260
     * Removes a listener for the value change.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   261
     * <p>
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   262
     * If the same listener was added more than once,
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   263
     * it will be notified one less time after being removed.
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   264
     * If {@code listener} is {@code null}, or was never added,
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   265
     * no exception is thrown and no action is taken.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
1272
40d9533e1505 4114658: DOC: Unspecified behaviour for java.beans.PropertyEditorSupport
malenkov
parents: 2
diff changeset
   267
     * @param listener  the {@link PropertyChangeListener} to remove
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public synchronized void removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (listeners == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        listeners.removeElement(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Report that we have been modified to any interested listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void firePropertyChange() {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   281
        java.util.Vector<PropertyChangeListener> targets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (listeners == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   286
            targets = unsafeClone(listeners);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // Tell our listeners that "everything" has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        PropertyChangeEvent evt = new PropertyChangeEvent(source, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        for (int i = 0; i < targets.size(); i++) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   292
            PropertyChangeListener target = targets.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            target.propertyChange(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   297
    @SuppressWarnings("unchecked")
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   298
    private <T> java.util.Vector<T> unsafeClone(java.util.Vector<T> v) {
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   299
        return (java.util.Vector<T>)v.clone();
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   300
    }
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   301
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private Object source;
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 5506
diff changeset
   306
    private java.util.Vector<PropertyChangeListener> listeners;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}