1. /*
  2. * @(#)AccessibleRelation.java 1.14 04/04/15
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.accessibility;
  8. import java.util.Vector;
  9. import java.util.Locale;
  10. import java.util.MissingResourceException;
  11. import java.util.ResourceBundle;
  12. /**
  13. * <P>Class AccessibleRelation describes a relation between the
  14. * object that implements the AccessibleRelation and one or more other
  15. * objects. The actual relations that an object has with other
  16. * objects are defined as an AccessibleRelationSet, which is a composed
  17. * set of AccessibleRelations.
  18. * <p>The toDisplayString method allows you to obtain the localized string
  19. * for a locale independent key from a predefined ResourceBundle for the
  20. * keys defined in this class.
  21. * <p>The constants in this class present a strongly typed enumeration
  22. * of common object roles. If the constants in this class are not sufficient
  23. * to describe the role of an object, a subclass should be generated
  24. * from this class and it should provide constants in a similar manner.
  25. *
  26. * @version 1.14 04/15/04
  27. * @author Lynn Monsanto
  28. */
  29. public class AccessibleRelation extends AccessibleBundle {
  30. /*
  31. * The group of objects that participate in the relation.
  32. * The relation may be one-to-one or one-to-many. For
  33. * example, in the case of a LABEL_FOR relation, the target
  34. * vector would contain a list of objects labeled by the object
  35. * that implements this AccessibleRelation. In the case of a
  36. * MEMBER_OF relation, the target vector would contain all
  37. * of the components that are members of the same group as the
  38. * object that implements this AccessibleRelation.
  39. */
  40. private Object [] target = new Object[0];
  41. /**
  42. * Indicates an object is a label for one or more target objects.
  43. *
  44. * @see #getTarget
  45. * @see #CONTROLLER_FOR
  46. * @see #CONTROLLED_BY
  47. * @see #LABELED_BY
  48. * @see #MEMBER_OF
  49. */
  50. public static final String LABEL_FOR = new String("labelFor");
  51. /**
  52. * Indicates an object is labeled by one or more target objects.
  53. *
  54. * @see #getTarget
  55. * @see #CONTROLLER_FOR
  56. * @see #CONTROLLED_BY
  57. * @see #LABEL_FOR
  58. * @see #MEMBER_OF
  59. */
  60. public static final String LABELED_BY = new String("labeledBy");
  61. /**
  62. * Indicates an object is a member of a group of one or more
  63. * target objects.
  64. *
  65. * @see #getTarget
  66. * @see #CONTROLLER_FOR
  67. * @see #CONTROLLED_BY
  68. * @see #LABEL_FOR
  69. * @see #LABELED_BY
  70. */
  71. public static final String MEMBER_OF = new String("memberOf");
  72. /**
  73. * Indicates an object is a controller for one or more target
  74. * objects.
  75. *
  76. * @see #getTarget
  77. * @see #CONTROLLED_BY
  78. * @see #LABEL_FOR
  79. * @see #LABELED_BY
  80. * @see #MEMBER_OF
  81. */
  82. public static final String CONTROLLER_FOR = new String("controllerFor");
  83. /**
  84. * Indicates an object is controlled by one or more target
  85. * objects.
  86. *
  87. * @see #getTarget
  88. * @see #CONTROLLER_FOR
  89. * @see #LABEL_FOR
  90. * @see #LABELED_BY
  91. * @see #MEMBER_OF
  92. */
  93. public static final String CONTROLLED_BY = new String("controlledBy");
  94. /**
  95. * Indicates an object is logically contiguous with a second
  96. * object where the second object occurs after the object.
  97. * An example is a paragraph of text that runs to the end of
  98. * a page and continues on the next page with an intervening
  99. * text footer and/or text header. The two parts of
  100. * the paragraph are separate text elements but are related
  101. * in that the second element is a continuation
  102. * of the first
  103. * element. In other words, the first element "flows to"
  104. * the second element.
  105. *
  106. * @since 1.5
  107. */
  108. public static final String FLOWS_TO = "flowsTo";
  109. /**
  110. * Indicates an object is logically contiguous with a second
  111. * object where the second object occurs before the object.
  112. * An example is a paragraph of text that runs to the end of
  113. * a page and continues on the next page with an intervening
  114. * text footer and/or text header. The two parts of
  115. * the paragraph are separate text elements but are related
  116. * in that the second element is a continuation of the first
  117. * element. In other words, the second element "flows from"
  118. * the second element.
  119. *
  120. * @since 1.5
  121. */
  122. public static final String FLOWS_FROM = "flowsFrom";
  123. /**
  124. * Indicates that an object is a subwindow of one or more
  125. * objects.
  126. *
  127. * @since 1.5
  128. */
  129. public static final String SUBWINDOW_OF = "subwindowOf";
  130. /**
  131. * Indicates that an object is a parent window of one or more
  132. * objects.
  133. *
  134. * @since 1.5
  135. */
  136. public static final String PARENT_WINDOW_OF = "parentWindowOf";
  137. /**
  138. * Indicates that an object has one or more objects
  139. * embedded in it.
  140. *
  141. * @since 1.5
  142. */
  143. public static final String EMBEDS = "embeds";
  144. /**
  145. * Indicates that an object is embedded in one or more
  146. * objects.
  147. *
  148. * @since 1.5
  149. */
  150. public static final String EMBEDDED_BY = "embeddedBy";
  151. /**
  152. * Indicates that an object is a child node of one
  153. * or more objects.
  154. *
  155. * @since 1.5
  156. */
  157. public static final String CHILD_NODE_OF = "childNodeOf";
  158. /**
  159. * Identifies that the target group for a label has changed
  160. */
  161. public static final String LABEL_FOR_PROPERTY = "labelForProperty";
  162. /**
  163. * Identifies that the objects that are doing the labeling have changed
  164. */
  165. public static final String LABELED_BY_PROPERTY = "labeledByProperty";
  166. /**
  167. * Identifies that group membership has changed.
  168. */
  169. public static final String MEMBER_OF_PROPERTY = "memberOfProperty";
  170. /**
  171. * Identifies that the controller for the target object has changed
  172. */
  173. public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";
  174. /**
  175. * Identifies that the target object that is doing the controlling has
  176. * changed
  177. */
  178. public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";
  179. /**
  180. * Indicates the FLOWS_TO relation between two objects
  181. * has changed.
  182. *
  183. * @since 1.5
  184. */
  185. public static final String FLOWS_TO_PROPERTY = "flowsToProperty";
  186. /**
  187. * Indicates the FLOWS_FROM relation between two objects
  188. * has changed.
  189. *
  190. * @since 1.5
  191. */
  192. public static final String FLOWS_FROM_PROPERTY = "flowsFromProperty";
  193. /**
  194. * Indicates the SUBWINDOW_OF relation between two or more objects
  195. * has changed.
  196. *
  197. * @since 1.5
  198. */
  199. public static final String SUBWINDOW_OF_PROPERTY = "subwindowOfProperty";
  200. /**
  201. * Indicates the PARENT_WINDOW_OF relation between two or more objects
  202. * has changed.
  203. *
  204. * @since 1.5
  205. */
  206. public static final String PARENT_WINDOW_OF_PROPERTY = "parentWindowOfProperty";
  207. /**
  208. * Indicates the EMBEDS relation between two or more objects
  209. * has changed.
  210. *
  211. * @since 1.5
  212. */
  213. public static final String EMBEDS_PROPERTY = "embedsProperty";
  214. /**
  215. * Indicates the EMBEDDED_BY relation between two or more objects
  216. * has changed.
  217. *
  218. * @since 1.5
  219. */
  220. public static final String EMBEDDED_BY_PROPERTY = "embeddedByProperty";
  221. /**
  222. * Indicates the CHILD_NODE_OF relation between two or more objects
  223. * has changed.
  224. *
  225. * @since 1.5
  226. */
  227. public static final String CHILD_NODE_OF_PROPERTY = "childNodeOfProperty";
  228. /**
  229. * Create a new AccessibleRelation using the given locale independent key.
  230. * The key String should be a locale independent key for the relation.
  231. * It is not intended to be used as the actual String to display
  232. * to the user. To get the localized string, use toDisplayString.
  233. *
  234. * @param key the locale independent name of the relation.
  235. * @see AccessibleBundle#toDisplayString
  236. */
  237. public AccessibleRelation(String key) {
  238. this.key = key;
  239. this.target = null;
  240. }
  241. /**
  242. * Creates a new AccessibleRelation using the given locale independent key.
  243. * The key String should be a locale independent key for the relation.
  244. * It is not intended to be used as the actual String to display
  245. * to the user. To get the localized string, use toDisplayString.
  246. *
  247. * @param key the locale independent name of the relation.
  248. * @param target the target object for this relation
  249. * @see AccessibleBundle#toDisplayString
  250. */
  251. public AccessibleRelation(String key, Object target) {
  252. this.key = key;
  253. this.target = new Object[1];
  254. this.target[0] = target;
  255. }
  256. /**
  257. * Creates a new AccessibleRelation using the given locale independent key.
  258. * The key String should be a locale independent key for the relation.
  259. * It is not intended to be used as the actual String to display
  260. * to the user. To get the localized string, use toDisplayString.
  261. *
  262. * @param key the locale independent name of the relation.
  263. * @param target the target object(s) for this relation
  264. * @see AccessibleBundle#toDisplayString
  265. */
  266. public AccessibleRelation(String key, Object [] target) {
  267. this.key = key;
  268. this.target = target;
  269. }
  270. /**
  271. * Returns the key for this relation
  272. *
  273. * @return the key for this relation
  274. *
  275. * @see #CONTROLLER_FOR
  276. * @see #CONTROLLED_BY
  277. * @see #LABEL_FOR
  278. * @see #LABELED_BY
  279. * @see #MEMBER_OF
  280. */
  281. public String getKey() {
  282. return this.key;
  283. }
  284. /**
  285. * Returns the target objects for this relation
  286. *
  287. * @return an array containing the target objects for this relation
  288. */
  289. public Object [] getTarget() {
  290. if (target == null) {
  291. target = new Object[0];
  292. }
  293. Object [] retval = new Object[target.length];
  294. for (int i = 0; i < target.length; i++) {
  295. retval[i] = target[i];
  296. }
  297. return retval;
  298. }
  299. /**
  300. * Sets the target object for this relation
  301. *
  302. * @param target the target object for this relation
  303. */
  304. public void setTarget(Object target) {
  305. this.target = new Object[1];
  306. this.target[0] = target;
  307. }
  308. /**
  309. * Sets the target objects for this relation
  310. *
  311. * @param target an array containing the target objects for this relation
  312. */
  313. public void setTarget(Object [] target) {
  314. this.target = target;
  315. }
  316. }