1. /*
  2. * @(#)AccessibleRelation.java 1.6 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.accessibility;
  11. import java.util.Vector;
  12. import java.util.Locale;
  13. import java.util.MissingResourceException;
  14. import java.util.ResourceBundle;
  15. /**
  16. * <P>Class AccessibleRelation describes a relation between the
  17. * object that implements the AccessibleRelation and one or more other
  18. * objects. The actual relations that an object has with other
  19. * objects are defined as an AccessibleRelationSet, which is a composed
  20. * set of AccessibleRelations.
  21. * <p>The toDisplayString method allows you to obtain the localized string
  22. * for a locale independent key from a predefined ResourceBundle for the
  23. * keys defined in this class.
  24. * <p>The constants in this class present a strongly typed enumeration
  25. * of common object roles. A public constructor for this class has been
  26. * purposely omitted and applications should use one of the constants
  27. * from this class. If the constants in this class are not sufficient
  28. * to describe the role of an object, a subclass should be generated
  29. * from this class and it should provide constants in a similar manner.
  30. *
  31. * @version 1.6 @(#)AccessibleRelation.java 1.6
  32. * @author Lynn Monsanto
  33. */
  34. public class AccessibleRelation extends AccessibleBundle {
  35. /*
  36. * The group of objects that participate in the relation.
  37. * The relation may be one-to-one or one-to-many. For
  38. * example, in the case of a LABEL_FOR relation, the target
  39. * vector would contain a list of objects labeled by the object
  40. * that implements this AccessibleRelation. In the case of a
  41. * MEMBER_OF relation, the target vector would contain all
  42. * of the components that are members of the same group as the
  43. * object that implements this AccessibleRelation.
  44. */
  45. private Object [] target = new Object[0];
  46. /**
  47. * Indicates an object is a label for one or more target objects.
  48. *
  49. * @see #getTarget
  50. * @see #CONTROLLER_FOR
  51. * @see #CONTROLLED_BY
  52. * @see #LABELED_BY
  53. * @see #MEMBER_OF
  54. */
  55. public static final String LABEL_FOR = new String("labelFor");
  56. /**
  57. * Indicates an object is labeled by one or more target objects.
  58. *
  59. * @see #getTarget
  60. * @see #CONTROLLER_FOR
  61. * @see #CONTROLLED_BY
  62. * @see #LABEL_FOR
  63. * @see #MEMBER_OF
  64. */
  65. public static final String LABELED_BY = new String("labeledBy");
  66. /**
  67. * Indicates an object is a member of a group of one or more
  68. * target objects.
  69. *
  70. * @see #getTarget
  71. * @see #CONTROLLER_FOR
  72. * @see #CONTROLLED_BY
  73. * @see #LABEL_FOR
  74. * @see #LABELED_BY
  75. */
  76. public static final String MEMBER_OF = new String("memberOf");
  77. /**
  78. * Indicates an object is a controller for one or more target
  79. * objects.
  80. *
  81. * @see #getTarget
  82. * @see #CONTROLLED_BY
  83. * @see #LABEL_FOR
  84. * @see #LABELED_BY
  85. * @see #MEMBER_OF
  86. */
  87. public static final String CONTROLLER_FOR = new String("controllerFor");
  88. /**
  89. * Indicates an object is controlled by one or more target
  90. * objects.
  91. *
  92. * @see #getTarget
  93. * @see #CONTROLLER_FOR
  94. * @see #LABEL_FOR
  95. * @see #LABELED_BY
  96. * @see #MEMBER_OF
  97. */
  98. public static final String CONTROLLED_BY = new String("controlledBy");
  99. /**
  100. * Identifies that the target group for a label has changed
  101. */
  102. public static final String LABEL_FOR_PROPERTY = "labelForProperty";
  103. /**
  104. * Identifies that the objects that are doing the labeling have changed
  105. */
  106. public static final String LABELED_BY_PROPERTY = "labeledByProperty";
  107. /**
  108. * Identifies that group membership has changed.
  109. */
  110. public static final String MEMBER_OF_PROPERTY = "memberOfProperty";
  111. /**
  112. * Identifies that the controller for the target object has changed
  113. */
  114. public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";
  115. /**
  116. * Identifies that the target object that is doing the controlling has
  117. * changed
  118. */
  119. public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";
  120. /**
  121. * Create a new AccessibleRelation using the given locale independent key.
  122. * @param key the locale independent name of the relation.
  123. * @note The String should be a locale independent key for the relation.
  124. * It is not intended to be used as the actual String to display
  125. * to the user. To get the localized string, use toDisplayString.
  126. * @see AccessibleBundle#toDisplayString
  127. */
  128. public AccessibleRelation(String key) {
  129. this.key = key;
  130. this.target = null;
  131. }
  132. /**
  133. * Creates a new AccessibleRelation using the given locale independent key.
  134. * @param key the locale independent name of the relation.
  135. * @note The String should be a locale independent key for the relation.
  136. * It is not intended to be used as the actual String to display
  137. * to the user. To get the localized string, use toDisplayString.
  138. * @param target the target object for this relation
  139. * @see AccessibleBundle#toDisplayString
  140. */
  141. public AccessibleRelation(String key, Object target) {
  142. this.key = key;
  143. this.target = new Object[1];
  144. this.target[0] = target;
  145. }
  146. /**
  147. * Creates a new AccessibleRelation using the given locale independent key.
  148. * @param key the locale independent name of the relation.
  149. * @note The String should be a locale independent key for the relation.
  150. * It is not intended to be used as the actual String to display
  151. * to the user. To get the localized string, use toDisplayString.
  152. * @param target the target object(s) for this relation
  153. * @see AccessibleBundle#toDisplayString
  154. */
  155. public AccessibleRelation(String key, Object [] target) {
  156. this.key = key;
  157. this.target = target;
  158. }
  159. /**
  160. * Returns the key for this relation
  161. *
  162. * @return the key for this relation
  163. *
  164. * @see #CONTROLLER_FOR
  165. * @see #CONTROLLED_BY
  166. * @see #LABEL_FOR
  167. * @see #LABELED_BY
  168. * @see #MEMBER_OF
  169. */
  170. public String getKey() {
  171. return this.key;
  172. }
  173. /**
  174. * Returns the target objects for this relation
  175. *
  176. * @return an array containing the target objects for this relation
  177. */
  178. public Object [] getTarget() {
  179. if (target == null) {
  180. target = new Object[0];
  181. }
  182. Object [] retval = new Object[target.length];
  183. for (int i = 0; i < target.length; i++) {
  184. retval[i] = target[i];
  185. }
  186. return retval;
  187. }
  188. /**
  189. * Sets the target object for this relation
  190. *
  191. * @param target the target object for this relation
  192. */
  193. public void setTarget(Object target) {
  194. this.target = new Object[1];
  195. this.target[0] = target;
  196. }
  197. /**
  198. * Sets the target objects for this relation
  199. *
  200. * @param target an array containing the target objects for this relation
  201. */
  202. public void setTarget(Object [] target) {
  203. this.target = target;
  204. }
  205. }