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