001/* AccessibleRelation.java -- the relation between accessible objects
002   Copyright (C) 2002, 2005 Free Software Foundation
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038package javax.accessibility;
039
040import java.util.Locale;
041
042/**
043 * The relation between one accessible object and one or more other objects.
044 * For example, a button may control an action. An AccessibleRelationSet
045 * summarizes all relations of the object. This strongly typed "enumeration"
046 * supports localized strings. If the constants of this class are not
047 * adequate, new ones may be added in a similar matter.
048 * 
049 * @author Eric Blake (ebb9@email.byu.edu)
050 * @since 1.2
051 * @status updated to 1.4
052 */
053public class AccessibleRelation extends AccessibleBundle
054{
055  /**
056   * Indicates the object labels other objects.
057   *
058   * @see #getTarget()
059   * @see #CONTROLLER_FOR
060   * @see #CONTROLLED_BY
061   * @see #LABELED_BY
062   * @see #MEMBER_OF
063   */
064  public static final String LABEL_FOR;
065
066  /**
067   * Indicates the object is labeled by other objects.
068   *
069   * @see #getTarget()
070   * @see #CONTROLLER_FOR
071   * @see #CONTROLLED_BY
072   * @see #LABEL_FOR
073   * @see #MEMBER_OF
074   */
075  public static final String LABELED_BY;
076
077  /**
078   * Indicates an object is a member of a group of target objects.
079   *
080   * @see #getTarget()
081   * @see #CONTROLLER_FOR
082   * @see #CONTROLLED_BY
083   * @see #LABEL_FOR
084   * @see #LABELED_BY
085   */
086  public static final String MEMBER_OF;
087
088  /**
089   * Indicates an object is a controller for other objects.
090   *
091   * @see #getTarget()
092   * @see #CONTROLLED_BY
093   * @see #LABEL_FOR
094   * @see #LABELED_BY
095   * @see #MEMBER_OF
096   */
097  public static final String CONTROLLER_FOR;
098
099  /**
100   * Indicates an object is controlled by other objects.
101   *
102   * @see #getTarget()
103   * @see #CONTROLLER_FOR
104   * @see #LABEL_FOR
105   * @see #LABELED_BY
106   * @see #MEMBER_OF
107   */
108  public static final String CONTROLLED_BY;
109
110  /** Indicates that the label target group has changed. */
111  public static final String LABEL_FOR_PROPERTY = "labelForProperty";
112
113  /** Indicates that the labelling objects have changed. */
114  public static final String LABELED_BY_PROPERTY = "labeledByProperty";
115
116  /** Indicates that group membership has changed. */
117  public static final String MEMBER_OF_PROPERTY = "memberOfProperty";
118
119  /** Indicates that the controller target group has changed. */
120  public static final String CONTROLLER_FOR_PROPERTY = "controllerForProperty";
121
122  /** Indicates that the controlling objects have changed. */
123  public static final String CONTROLLED_BY_PROPERTY = "controlledByProperty";
124
125  /**
126   * Indicates that an object is a child of another object.
127   * @since 1.5
128   */
129  public static final String CHILD_NODE_OF = "childNodeOf";
130
131  /**
132   * Indicates that the ancestry relationship has changed.
133   * @since 1.5
134   */
135  public static final String CHILD_NODE_OF_PROPERTY = "childNodeOfProperty";
136
137  /**
138   * Indicates that an object is embedded by another object.
139   * @since 1.5
140   */
141  public static final String EMBEDDED_BY = "embeddedBy";
142
143  /**
144   * Indicates that the {@link #EMBEDDED_BY} property changed.
145   * @since 1.5
146   */
147  public static final String EMBEDDED_BY_PROPERTY = "embeddedByProperty";
148
149  /**
150   * Indicates that an object embeds another object.
151   * @since 1.5
152   */
153  public static final String EMBEDS = "embeds";
154
155  /**
156   * Indicates that the {@link #EMBEDS} property changed.
157   * @since 1.5
158   */
159  public static final String EMBEDS_PROPERTY = "embedsProperty";
160
161  /**
162   * Indicates that one object directly follows another object,
163   * as in a paragraph flow.
164   * @since 1.5
165   */
166  public static final String FLOWS_FROM = "flowsFrom";
167
168  /**
169   * Indicates that the {@link #FLOWS_FROM} property changed.
170   * @since 1.5
171   */
172  public static final String FLOWS_FROM_PROPERTY = "flowsFromProperty";
173
174  /**
175   * Indicates that one object comes directly before another object,
176   * as in a paragraph flow.
177   * @since 1.5
178   */
179  public static final String FLOWS_TO = "flowsTo";
180
181  /**
182   * Indicates that the {@link #FLOWS_TO} property changed.
183   * @since 1.5
184   */
185  public static final String FLOWS_TO_PROPERTY = "flowsToProperty";
186
187  /**
188   * Indicates that one object is a parent window of another object.
189   * @since 1.5
190   */
191  public static final String PARENT_WINDOW_OF = "parentWindowOf";
192
193  /**
194   * Indicates that the {@link #PARENT_WINDOW_OF} property changed.
195   * @since 1.5
196   */
197  public static final String PARENT_WINDOW_OF_PROPERTY = "parentWindowOfProperty";
198
199  /**
200   * Indicates that one object is a subwindow of another object.
201   * @since 1.5
202   */
203  public static final String SUBWINDOW_OF = "subwindowOf";
204
205  /**
206   * Indicates that the {@link #SUBWINDOW_OF} property changed.
207   * @since 1.5
208   */
209  public static final String SUBWINDOW_OF_PROPERTY = "subwindowOfProperty";
210
211  /** An empty set of targets. */
212  private static final Object[] EMPTY_TARGETS = { };
213  
214  static
215    {
216      // not constants in JDK
217      LABEL_FOR = "labelFor";
218      LABELED_BY = "labeledBy";
219      MEMBER_OF = "memberOf";
220      CONTROLLER_FOR = "controllerFor";
221      CONTROLLED_BY = "controlledBy";
222    }
223
224  /**
225   * The related objects.
226   *
227   * @see #getTarget()
228   * @see #setTarget(Object)
229   * @see #setTarget(Object[])
230   */
231  Object[] targets;
232
233  /**
234   * Create a new relation with a locale independent key, and no related
235   * objects.
236   *
237   * @param key the name of the role
238   * @see #toDisplayString(String, Locale)
239   */
240  public AccessibleRelation(String key)
241  {
242    this.key = key;
243    targets = EMPTY_TARGETS;
244  }
245
246  /**
247   * Create a new relation with a locale independent key, and a single related
248   * object.
249   *
250   * @param key the name of the role
251   * @param target the related object
252   * @see #toDisplayString(String, Locale)
253   */
254  public AccessibleRelation(String key, Object target)
255  {
256    this.key = key;
257    targets = new Object[] { target };
258  }
259
260  /**
261   * Create a new relation with a locale independent key, and the given
262   * related objects.
263   *
264   * @param key the name of the role
265   * @param targets the related objects
266   * @see #toDisplayString(String, Locale)
267   */
268  public AccessibleRelation(String key, Object[] targets)
269  {
270    this.key = key;
271    this.targets = targets == null ? EMPTY_TARGETS : targets;
272  }
273
274  /**
275   * Return the key for this relation.
276   *
277   * @return the key
278   * @see #CONTROLLER_FOR
279   * @see #CONTROLLED_BY
280   * @see #LABEL_FOR
281   * @see #LABELED_BY
282   * @see #MEMBER_OF
283   */
284  public String getKey()
285  {
286    return key;
287  }
288
289  /**
290   * Return the targets of this relation.
291   *
292   * @return the targets, may be empty, but never null
293   */
294  public Object[] getTarget()
295  {
296    return targets;
297  }
298
299  /**
300   * Set the target to a single object.
301   *
302   * @param target the new target
303   */
304  public void setTarget(Object target)
305  {
306    targets = new Object[] { target };
307  }
308
309  /**
310   * Set the target to an array of objects.
311   *
312   * @param targets the new targets
313   */
314  public void setTarget(Object[] targets)
315  {
316    this.targets = targets == null ? EMPTY_TARGETS : targets;
317  }
318} // class AccessibleRelation