Path: blob/master/src/java.desktop/share/classes/javax/accessibility/AccessibleRelation.java
41153 views
/*1* Copyright (c) 1999, 2017, 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.accessibility;2627/**28* Class {@code AccessibleRelation} describes a relation between the object that29* implements the {@code AccessibleRelation} and one or more other objects. The30* actual relations that an object has with other objects are defined as an31* {@code AccessibleRelationSet}, which is a composed set of32* {@code AccessibleRelations}.33* <p>34* The {@link #toDisplayString()} method allows you to obtain the localized35* string for a locale independent key from a predefined {@code ResourceBundle}36* for the keys defined in this class.37* <p>38* The constants in this class present a strongly typed enumeration of common39* object roles. If the constants in this class are not sufficient to describe40* the role of an object, a subclass should be generated from this class and it41* should provide constants in a similar manner.42*43* @author Lynn Monsanto44* @since 1.345*/46public class AccessibleRelation extends AccessibleBundle {4748/**49* The group of objects that participate in the relation. The relation may50* be one-to-one or one-to-many. For example, in the case of a51* {@code LABEL_FOR} relation, the target vector would contain a list of52* objects labeled by the object that implements this53* {@code AccessibleRelation}. In the case of a {@code MEMBER_OF} relation,54* the target vector would contain all of the components that are members of55* the same group as the object that implements this56* {@code AccessibleRelation}.57*/58private Object [] target = new Object[0];5960/**61* Indicates an object is a label for one or more target objects.62*63* @see #getTarget64* @see #CONTROLLER_FOR65* @see #CONTROLLED_BY66* @see #LABELED_BY67* @see #MEMBER_OF68*/69public static final String LABEL_FOR = new String("labelFor");7071/**72* Indicates an object is labeled by one or more target objects.73*74* @see #getTarget75* @see #CONTROLLER_FOR76* @see #CONTROLLED_BY77* @see #LABEL_FOR78* @see #MEMBER_OF79*/80public static final String LABELED_BY = new String("labeledBy");8182/**83* Indicates an object is a member of a group of one or more target objects.84*85* @see #getTarget86* @see #CONTROLLER_FOR87* @see #CONTROLLED_BY88* @see #LABEL_FOR89* @see #LABELED_BY90*/91public static final String MEMBER_OF = new String("memberOf");9293/**94* Indicates an object is a controller for one or more target objects.95*96* @see #getTarget97* @see #CONTROLLED_BY98* @see #LABEL_FOR99* @see #LABELED_BY100* @see #MEMBER_OF101*/102public static final String CONTROLLER_FOR = new String("controllerFor");103104/**105* Indicates an object is controlled by one or more target objects.106*107* @see #getTarget108* @see #CONTROLLER_FOR109* @see #LABEL_FOR110* @see #LABELED_BY111* @see #MEMBER_OF112*/113public static final String CONTROLLED_BY = new String("controlledBy");114115/**116* Indicates an object is logically contiguous with a second object where117* the second object occurs after the object. An example is a paragraph of118* text that runs to the end of a page and continues on the next page with119* an intervening text footer and/or text header. The two parts of the120* paragraph are separate text elements but are related in that the second121* element is a continuation of the first element. In other words, the first122* element "flows to" the second element.123*124* @since 1.5125*/126public static final String FLOWS_TO = "flowsTo";127128/**129* Indicates an object is logically contiguous with a second object where130* the second object occurs before the object. An example is a paragraph of131* text that runs to the end of a page and continues on the next page with132* an intervening text footer and/or text header. The two parts of the133* paragraph are separate text elements but are related in that the second134* element is a continuation of the first element. In other words, the135* second element "flows from" the second element.136*137* @since 1.5138*/139public static final String FLOWS_FROM = "flowsFrom";140141/**142* Indicates that an object is a subwindow of one or more objects.143*144* @since 1.5145*/146public static final String SUBWINDOW_OF = "subwindowOf";147148/**149* Indicates that an object is a parent window of one or more objects.150*151* @since 1.5152*/153public static final String PARENT_WINDOW_OF = "parentWindowOf";154155/**156* Indicates that an object has one or more objects embedded in it.157*158* @since 1.5159*/160public static final String EMBEDS = "embeds";161162/**163* Indicates that an object is embedded in one or more objects.164*165* @since 1.5166*/167public static final String EMBEDDED_BY = "embeddedBy";168169/**170* Indicates that an object is a child node of one or more objects.171*172* @since 1.5173*/174public static final String CHILD_NODE_OF = "childNodeOf";175176/**177* Identifies that the target group for a label has changed.178*/179public static final String LABEL_FOR_PROPERTY = "labelForProperty";180181/**182* Identifies that the objects that are doing the labeling have changed.183*/184public static final String LABELED_BY_PROPERTY = "labeledByProperty";185186/**187* Identifies that group membership has changed.188*/189public static final String MEMBER_OF_PROPERTY = "memberOfProperty";190191/**192* Identifies that the controller for the target object has changed.193*/194public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";195196/**197* Identifies that the target object that is doing the controlling has198* changed.199*/200public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";201202/**203* Indicates the {@code FLOWS_TO} relation between two objects has changed.204*205* @since 1.5206*/207public static final String FLOWS_TO_PROPERTY = "flowsToProperty";208209/**210* Indicates the {@code FLOWS_FROM} relation between two objects has211* changed.212*213* @since 1.5214*/215public static final String FLOWS_FROM_PROPERTY = "flowsFromProperty";216217/**218* Indicates the {@code SUBWINDOW_OF} relation between two or more objects219* has changed.220*221* @since 1.5222*/223public static final String SUBWINDOW_OF_PROPERTY = "subwindowOfProperty";224225/**226* Indicates the {@code PARENT_WINDOW_OF} relation between two or more227* objects has changed.228*229* @since 1.5230*/231public static final String PARENT_WINDOW_OF_PROPERTY = "parentWindowOfProperty";232233/**234* Indicates the {@code EMBEDS} relation between two or more objects has235* changed.236*237* @since 1.5238*/239public static final String EMBEDS_PROPERTY = "embedsProperty";240241/**242* Indicates the {@code EMBEDDED_BY} relation between two or more objects243* has changed.244*245* @since 1.5246*/247public static final String EMBEDDED_BY_PROPERTY = "embeddedByProperty";248249/**250* Indicates the {@code CHILD_NODE_OF} relation between two or more objects251* has changed.252*253* @since 1.5254*/255public static final String CHILD_NODE_OF_PROPERTY = "childNodeOfProperty";256257/**258* Create a new {@code AccessibleRelation} using the given locale259* independent key. The key {@code String} should be a locale independent260* key for the relation. It is not intended to be used as the actual261* {@code String} to display to the user. To get the localized string, use262* {@link #toDisplayString()}.263*264* @param key the locale independent name of the relation265* @see AccessibleBundle#toDisplayString266*/267public AccessibleRelation(String key) {268this.key = key;269this.target = null;270}271272/**273* Creates a new {@code AccessibleRelation} using the given locale274* independent key. The key {@code String} should be a locale independent275* key for the relation. It is not intended to be used as the actual276* {@code String} to display to the user. To get the localized string, use277* {@link #toDisplayString()}.278*279* @param key the locale independent name of the relation280* @param target the target object for this relation281* @see AccessibleBundle#toDisplayString282*/283public AccessibleRelation(String key, Object target) {284this.key = key;285this.target = new Object[1];286this.target[0] = target;287}288289/**290* Creates a new {@code AccessibleRelation} using the given locale291* independent key. The key {@code String} should be a locale independent292* key for the relation. It is not intended to be used as the actual293* {@code String} to display to the user. To get the localized string, use294* {@link #toDisplayString()}.295*296* @param key the locale independent name of the relation297* @param target the target object(s) for this relation298* @see AccessibleBundle#toDisplayString299*/300public AccessibleRelation(String key, Object[] target) {301this.key = key;302this.target = target;303}304305/**306* Returns the key for this relation.307*308* @return the key for this relation309* @see #CONTROLLER_FOR310* @see #CONTROLLED_BY311* @see #LABEL_FOR312* @see #LABELED_BY313* @see #MEMBER_OF314*/315public String getKey() {316return this.key;317}318319/**320* Returns the target objects for this relation.321*322* @return an array containing the target objects for this relation323*/324public Object [] getTarget() {325if (target == null) {326target = new Object[0];327}328Object [] retval = new Object[target.length];329for (int i = 0; i < target.length; i++) {330retval[i] = target[i];331}332return retval;333}334335/**336* Sets the target object for this relation.337*338* @param target the target object for this relation339*/340public void setTarget(Object target) {341this.target = new Object[1];342this.target[0] = target;343}344345/**346* Sets the target objects for this relation.347*348* @param target an array containing the target objects for this relation349*/350public void setTarget(Object [] target) {351this.target = target;352}353}354355356