1 /*
2  * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.accessibility;
27 
28 import java.util.Vector;
29 import java.util.Locale;
30 import java.util.MissingResourceException;
31 import java.util.ResourceBundle;
32 
33 /**
34  * <P>Class AccessibleRelation describes a relation between the
35  * object that implements the AccessibleRelation and one or more other
36  * objects.  The actual relations that an object has with other
37  * objects are defined as an AccessibleRelationSet, which is a composed
38  * set of AccessibleRelations.
39  * <p>The toDisplayString method allows you to obtain the localized string
40  * for a locale independent key from a predefined ResourceBundle for the
41  * keys defined in this class.
42  * <p>The constants in this class present a strongly typed enumeration
43  * of common object roles. If the constants in this class are not sufficient
44  * to describe the role of an object, a subclass should be generated
45  * from this class and it should provide constants in a similar manner.
46  *
47  * @author      Lynn Monsanto
48  * @since 1.3
49  */
50 public class AccessibleRelation extends AccessibleBundle {
51 
52     /*
53      * The group of objects that participate in the relation.
54      * The relation may be one-to-one or one-to-many.  For
55      * example, in the case of a LABEL_FOR relation, the target
56      * vector would contain a list of objects labeled by the object
57      * that implements this AccessibleRelation.  In the case of a
58      * MEMBER_OF relation, the target vector would contain all
59      * of the components that are members of the same group as the
60      * object that implements this AccessibleRelation.
61      */
62     private Object [] target = new Object[0];
63 
64     /**
65      * Indicates an object is a label for one or more target objects.
66      *
67      * @see #getTarget
68      * @see #CONTROLLER_FOR
69      * @see #CONTROLLED_BY
70      * @see #LABELED_BY
71      * @see #MEMBER_OF
72      */
73     public static final String LABEL_FOR = new String("labelFor");
74 
75     /**
76      * Indicates an object is labeled by one or more target objects.
77      *
78      * @see #getTarget
79      * @see #CONTROLLER_FOR
80      * @see #CONTROLLED_BY
81      * @see #LABEL_FOR
82      * @see #MEMBER_OF
83      */
84     public static final String LABELED_BY = new String("labeledBy");
85 
86     /**
87      * Indicates an object is a member of a group of one or more
88      * target objects.
89      *
90      * @see #getTarget
91      * @see #CONTROLLER_FOR
92      * @see #CONTROLLED_BY
93      * @see #LABEL_FOR
94      * @see #LABELED_BY
95      */
96     public static final String MEMBER_OF = new String("memberOf");
97 
98     /**
99      * Indicates an object is a controller for one or more target
100      * objects.
101      *
102      * @see #getTarget
103      * @see #CONTROLLED_BY
104      * @see #LABEL_FOR
105      * @see #LABELED_BY
106      * @see #MEMBER_OF
107      */
108     public static final String CONTROLLER_FOR = new String("controllerFor");
109 
110     /**
111      * Indicates an object is controlled by one or more target
112      * objects.
113      *
114      * @see #getTarget
115      * @see #CONTROLLER_FOR
116      * @see #LABEL_FOR
117      * @see #LABELED_BY
118      * @see #MEMBER_OF
119      */
120     public static final String CONTROLLED_BY = new String("controlledBy");
121 
122     /**
123      * Indicates an object is logically contiguous with a second
124      * object where the second object occurs after the object.
125      * An example is a paragraph of text that runs to the end of
126      * a page and continues on the next page with an intervening
127      * text footer and/or text header.  The two parts of
128      * the paragraph are separate text elements but are related
129      * in that the second element is a continuation
130      * of the first
131      * element.  In other words, the first element "flows to"
132      * the second element.
133      *
134      * @since 1.5
135      */
136     public static final String FLOWS_TO = "flowsTo";
137 
138     /**
139      * Indicates an object is logically contiguous with a second
140      * object where the second object occurs before the object.
141      * An example is a paragraph of text that runs to the end of
142      * a page and continues on the next page with an intervening
143      * text footer and/or text header.  The two parts of
144      * the paragraph are separate text elements but are related
145      * in that the second element is a continuation of the first
146      * element.  In other words, the second element "flows from"
147      * the second element.
148      *
149      * @since 1.5
150      */
151     public static final String FLOWS_FROM = "flowsFrom";
152 
153     /**
154      * Indicates that an object is a subwindow of one or more
155      * objects.
156      *
157      * @since 1.5
158      */
159     public static final String SUBWINDOW_OF = "subwindowOf";
160 
161     /**
162      * Indicates that an object is a parent window of one or more
163      * objects.
164      *
165      * @since 1.5
166      */
167     public static final String PARENT_WINDOW_OF = "parentWindowOf";
168 
169     /**
170      * Indicates that an object has one or more objects
171      * embedded in it.
172      *
173      * @since 1.5
174      */
175     public static final String EMBEDS = "embeds";
176 
177     /**
178      * Indicates that an object is embedded in one or more
179      * objects.
180      *
181      * @since 1.5
182      */
183     public static final String EMBEDDED_BY = "embeddedBy";
184 
185     /**
186      * Indicates that an object is a child node of one
187      * or more objects.
188      *
189      * @since 1.5
190      */
191     public static final String CHILD_NODE_OF = "childNodeOf";
192 
193     /**
194      * Identifies that the target group for a label has changed
195      */
196     public static final String LABEL_FOR_PROPERTY = "labelForProperty";
197 
198     /**
199      * Identifies that the objects that are doing the labeling have changed
200      */
201     public static final String LABELED_BY_PROPERTY = "labeledByProperty";
202 
203     /**
204      * Identifies that group membership has changed.
205      */
206     public static final String MEMBER_OF_PROPERTY = "memberOfProperty";
207 
208     /**
209      * Identifies that the controller for the target object has changed
210      */
211     public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";
212 
213     /**
214      * Identifies that the target object that is doing the controlling has
215      * changed
216      */
217     public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";
218 
219     /**
220      * Indicates the FLOWS_TO relation between two objects
221      * has changed.
222      *
223      * @since 1.5
224      */
225     public static final String FLOWS_TO_PROPERTY = "flowsToProperty";
226 
227     /**
228      * Indicates the FLOWS_FROM relation between two objects
229      * has changed.
230      *
231      * @since 1.5
232      */
233     public static final String FLOWS_FROM_PROPERTY = "flowsFromProperty";
234 
235     /**
236      * Indicates the SUBWINDOW_OF relation between two or more objects
237      * has changed.
238      *
239      * @since 1.5
240      */
241     public static final String SUBWINDOW_OF_PROPERTY = "subwindowOfProperty";
242 
243     /**
244      * Indicates the PARENT_WINDOW_OF relation between two or more objects
245      * has changed.
246      *
247      * @since 1.5
248      */
249     public static final String PARENT_WINDOW_OF_PROPERTY = "parentWindowOfProperty";
250 
251     /**
252      * Indicates the EMBEDS relation between two or more objects
253      * has changed.
254      *
255      * @since 1.5
256      */
257     public static final String EMBEDS_PROPERTY = "embedsProperty";
258 
259     /**
260      * Indicates the EMBEDDED_BY relation between two or more objects
261      * has changed.
262      *
263      * @since 1.5
264      */
265     public static final String EMBEDDED_BY_PROPERTY = "embeddedByProperty";
266 
267     /**
268      * Indicates the CHILD_NODE_OF relation between two or more objects
269      * has changed.
270      *
271      * @since 1.5
272      */
273     public static final String CHILD_NODE_OF_PROPERTY = "childNodeOfProperty";
274 
275     /**
276      * Create a new AccessibleRelation using the given locale independent key.
277      * The key String should be a locale independent key for the relation.
278      * It is not intended to be used as the actual String to display
279      * to the user.  To get the localized string, use toDisplayString.
280      *
281      * @param key the locale independent name of the relation.
282      * @see AccessibleBundle#toDisplayString
283      */
AccessibleRelation(String key)284     public AccessibleRelation(String key) {
285         this.key = key;
286         this.target = null;
287     }
288 
289     /**
290      * Creates a new AccessibleRelation using the given locale independent key.
291      * The key String should be a locale independent key for the relation.
292      * It is not intended to be used as the actual String to display
293      * to the user.  To get the localized string, use toDisplayString.
294      *
295      * @param key the locale independent name of the relation.
296      * @param target the target object for this relation
297      * @see AccessibleBundle#toDisplayString
298      */
AccessibleRelation(String key, Object target)299     public AccessibleRelation(String key, Object target) {
300         this.key = key;
301         this.target = new Object[1];
302         this.target[0] = target;
303     }
304 
305     /**
306      * Creates a new AccessibleRelation using the given locale independent key.
307      * The key String should be a locale independent key for the relation.
308      * It is not intended to be used as the actual String to display
309      * to the user.  To get the localized string, use toDisplayString.
310      *
311      * @param key the locale independent name of the relation.
312      * @param target the target object(s) for this relation
313      * @see AccessibleBundle#toDisplayString
314      */
AccessibleRelation(String key, Object [] target)315     public AccessibleRelation(String key, Object [] target) {
316         this.key = key;
317         this.target = target;
318     }
319 
320     /**
321      * Returns the key for this relation
322      *
323      * @return the key for this relation
324      *
325      * @see #CONTROLLER_FOR
326      * @see #CONTROLLED_BY
327      * @see #LABEL_FOR
328      * @see #LABELED_BY
329      * @see #MEMBER_OF
330      */
getKey()331     public String getKey() {
332         return this.key;
333     }
334 
335     /**
336      * Returns the target objects for this relation
337      *
338      * @return an array containing the target objects for this relation
339      */
getTarget()340     public Object [] getTarget() {
341         if (target == null) {
342             target = new Object[0];
343         }
344         Object [] retval = new Object[target.length];
345         for (int i = 0; i < target.length; i++) {
346             retval[i] = target[i];
347         }
348         return retval;
349     }
350 
351     /**
352      * Sets the target object for this relation
353      *
354      * @param target the target object for this relation
355      */
setTarget(Object target)356     public void setTarget(Object target) {
357         this.target = new Object[1];
358         this.target[0] = target;
359     }
360 
361     /**
362      * Sets the target objects for this relation
363      *
364      * @param target an array containing the target objects for this relation
365      */
setTarget(Object [] target)366     public void setTarget(Object [] target) {
367         this.target = target;
368     }
369 }
370