Path: blob/master/src/java.desktop/share/classes/javax/swing/ClientPropertyKey.java
41153 views
/*1* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.swing;2627import sun.awt.AWTAccessor;2829/**30* An enumeration for keys used as client properties within the Swing31* implementation.32* <p>33* This enum holds only a small subset of the keys currently used within Swing,34* but we may move more of them here in the future.35* <p>36* Adding an item to, and using, this class instead of {@code String} for37* client properties protects against conflicts with developer-set client38* properties. Using this class also avoids a problem with {@code StringBuilder}39* and {@code StringBuffer} keys, whereby the keys are not recognized upon40* deserialization.41* <p>42* When a client property value associated with one of these keys does not43* implement {@code Serializable}, the result during serialization depends44* on how the key is defined here. Historically, client properties with values45* not implementing {@code Serializable} have simply been dropped and left out46* of the serialized representation. To define keys with such behavior in this47* enum, provide a value of {@code false} for the {@code reportValueNotSerializable}48* property. When migrating existing properties to this enum, one may wish to49* consider using this by default, to preserve backward compatibility.50* <p>51* To instead have a {@code NotSerializableException} thrown when a52* {@code non-Serializable} property is encountered, provide the value of53* {@code true} for the {@code reportValueNotSerializable} property. This54* is useful when the property represents something that the developer55* needs to know about when it cannot be serialized.56*57* @author Shannon Hickey58*/59enum ClientPropertyKey {6061/**62* Key used by JComponent for storing InputVerifier.63*/64JComponent_INPUT_VERIFIER(true),6566/**67* Key used by JComponent for storing TransferHandler.68*/69JComponent_TRANSFER_HANDLER(true),7071/**72* Key used by JComponent for storing AncestorNotifier.73*/74JComponent_ANCESTOR_NOTIFIER(true),7576/**77* Key used by PopupFactory to force heavy weight popups for a78* component.79*/80PopupFactory_FORCE_HEAVYWEIGHT_POPUP(true);818283/**84* Whether or not a {@code NotSerializableException} should be thrown85* during serialization, when the value associated with this key does86* not implement {@code Serializable}.87*/88private final boolean reportValueNotSerializable;8990static {91AWTAccessor.setClientPropertyKeyAccessor(92new AWTAccessor.ClientPropertyKeyAccessor() {93public Object getJComponent_TRANSFER_HANDLER() {94return JComponent_TRANSFER_HANDLER;95}96});97}9899/**100* Constructs a key with the {@code reportValueNotSerializable} property101* set to {@code false}.102*/103private ClientPropertyKey() {104this(false);105}106107/**108* Constructs a key with the {@code reportValueNotSerializable} property109* set to the given value.110*/111private ClientPropertyKey(boolean reportValueNotSerializable) {112this.reportValueNotSerializable = reportValueNotSerializable;113}114115/**116* Returns whether or not a {@code NotSerializableException} should be thrown117* during serialization, when the value associated with this key does118* not implement {@code Serializable}.119*/120public boolean getReportValueNotSerializable() {121return reportValueNotSerializable;122}123}124125126