1. /*
  2. * @(#)AccessibleRelation.java 1.10 03/01/27
  3. *
  4. * Copyright 2003 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.6 @(#)AccessibleRelation.java 1.6
  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. * Identifies that the target group for a label has changed
  96. */
  97. public static final String LABEL_FOR_PROPERTY = "labelForProperty";
  98. /**
  99. * Identifies that the objects that are doing the labeling have changed
  100. */
  101. public static final String LABELED_BY_PROPERTY = "labeledByProperty";
  102. /**
  103. * Identifies that group membership has changed.
  104. */
  105. public static final String MEMBER_OF_PROPERTY = "memberOfProperty";
  106. /**
  107. * Identifies that the controller for the target object has changed
  108. */
  109. public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";
  110. /**
  111. * Identifies that the target object that is doing the controlling has
  112. * changed
  113. */
  114. public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";
  115. /**
  116. * Create a new AccessibleRelation using the given locale independent key.
  117. * The key String should be a locale independent key for the relation.
  118. * It is not intended to be used as the actual String to display
  119. * to the user. To get the localized string, use toDisplayString.
  120. *
  121. * @param key the locale independent name of the relation.
  122. * @see AccessibleBundle#toDisplayString
  123. */
  124. public AccessibleRelation(String key) {
  125. this.key = key;
  126. this.target = null;
  127. }
  128. /**
  129. * Creates a new AccessibleRelation using the given locale independent key.
  130. * The key String should be a locale independent key for the relation.
  131. * It is not intended to be used as the actual String to display
  132. * to the user. To get the localized string, use toDisplayString.
  133. *
  134. * @param key the locale independent name of the relation.
  135. * @param target the target object for this relation
  136. * @see AccessibleBundle#toDisplayString
  137. */
  138. public AccessibleRelation(String key, Object target) {
  139. this.key = key;
  140. this.target = new Object[1];
  141. this.target[0] = target;
  142. }
  143. /**
  144. * Creates a new AccessibleRelation using the given locale independent key.
  145. * The key String should be a locale independent key for the relation.
  146. * It is not intended to be used as the actual String to display
  147. * to the user. To get the localized string, use toDisplayString.
  148. *
  149. * @param key the locale independent name of the relation.
  150. * @param target the target object(s) for this relation
  151. * @see AccessibleBundle#toDisplayString
  152. */
  153. public AccessibleRelation(String key, Object [] target) {
  154. this.key = key;
  155. this.target = target;
  156. }
  157. /**
  158. * Returns the key for this relation
  159. *
  160. * @return the key for this relation
  161. *
  162. * @see #CONTROLLER_FOR
  163. * @see #CONTROLLED_BY
  164. * @see #LABEL_FOR
  165. * @see #LABELED_BY
  166. * @see #MEMBER_OF
  167. */
  168. public String getKey() {
  169. return this.key;
  170. }
  171. /**
  172. * Returns the target objects for this relation
  173. *
  174. * @return an array containing the target objects for this relation
  175. */
  176. public Object [] getTarget() {
  177. if (target == null) {
  178. target = new Object[0];
  179. }
  180. Object [] retval = new Object[target.length];
  181. for (int i = 0; i < target.length; i++) {
  182. retval[i] = target[i];
  183. }
  184. return retval;
  185. }
  186. /**
  187. * Sets the target object for this relation
  188. *
  189. * @param target the target object for this relation
  190. */
  191. public void setTarget(Object target) {
  192. this.target = new Object[1];
  193. this.target[0] = target;
  194. }
  195. /**
  196. * Sets the target objects for this relation
  197. *
  198. * @param target an array containing the target objects for this relation
  199. */
  200. public void setTarget(Object [] target) {
  201. this.target = target;
  202. }
  203. }