summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/accessibility/AccessibleContext.java
blob: ee3a5287b42678fcd65f3a24df2b6cfe91327e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/* AccessibleContext.java -- the context of an accessible object
   Copyright (C) 2002 Free Software Foundation

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package javax.accessibility;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Locale;

/**
 * The minimum information that all accessible objects return. This includes
 * name, description, role, and state of the object, parents and children,
 * and any other useful information. If a component supports further details,
 * it should implement one of the following:<ul>
 * <li>{@link AccessibleAction} - the object can perform actions</li>
 * <li>{@link AccessibleComponent} - the object has a graphical
 *     representation</li>
 * <li>{@link AccessibleSelection} - the object allows its children to be
 *     selected</li>
 * <li>{@link AccessibleText} - the object represents editable text</li>
 * <li>{@link AccessibleValue} - the object represents a numerical value</li>
 * </ul>
 *
 * @author Eric Blake (ebb9@email.byu.edu)
 * @since 1.2
 * @status updated to 1.4
 */
public abstract class AccessibleContext
{
  /**
   * Constant used when the accessible name has changed. Both the old and new
   * values are listed in the event.
   *
   * @see #getAccessibleName()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_NAME_PROPERTY
    = "AccessibleName";

  /**
   * Constant used when the accessible description has changed. Both the old
   * and new values are listed in the event.
   *
   * @see #getAccessibleDescription()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_DESCRIPTION_PROPERTY
    = "AccessibleDescription";

  /**
   * Constant used when the accessibleStateSet has changed. Both the old and
   * new values are listed in the event, although either may be null if a
   * state was disabled at that time.
   *
   * @see #getAccessibleStateSet()
   * @see AccessibleState
   * @see AccessibleStateSet
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_STATE_PROPERTY
    = "AccessibleState";

  /**
   * Constant used when the accessibleValue has changed. Both the old and new
   * values are listed in the event.
   *
   * @see #getAccessibleValue()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_VALUE_PROPERTY
    = "AccessibleValue";

  /**
   * Constant used when the accessibleSelection has changed. Both the old and
   * new values of the event are reserved for future use.
   *
   * @see #getAccessibleSelection()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_SELECTION_PROPERTY
    = "AccessibleSelection";

  /**
   * Constant used when the accessibleText has changed. Both the old and new
   * values of the event are reserved for future use.
   *
   * @see #getAccessibleText()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_TEXT_PROPERTY
    = "AccessibleText";

  /**
   * Constant used when the accessibleText caret has changed. Both the old and
   * new values are listed in the event.
   *
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_CARET_PROPERTY
    = "AccessibleCaret";

  /**
   * Constant used when the visible data has changed. Both the old and new
   * values of the event are reserved for future use.
   *
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_VISIBLE_DATA_PROPERTY
    = "AccessibleVisibleData";

  /**
   * Constant used when children are added or removed. On addition, the new
   * value of the event holds the new child; on removal, the old value holds
   * the removed child.
   *
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_CHILD_PROPERTY
    = "AccessibleChild";

  /**
   * Constant used when active descendent of a component has changed. Both
   * the old and new values are listed in the event.
   *
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public static final String ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY
    = "AccessibleActiveDescendant";

  /**
   * Constant used when the accessible table caption has changed. Both the
   * old and new values are listed in the event.
   *
   * @see Accessible
   * @see AccessibleTable
   */
  public static final String ACCESSIBLE_TABLE_CAPTION_CHANGED
    = "accessibleTableCaptionChanged";

  /**
   * Constant used when the accessible table summary has changed. Both the
   * old and new values are listed in the event.
   *
   * @see Accessible
   * @see AccessibleTable
   */
  public static final String ACCESSIBLE_TABLE_SUMMARY_CHANGED
    = "accessibleTableSummaryChanged";

  /**
   * Constant used when the accessible table model has changed. Only the new
   * value of the event has meaning.
   *
   * @see AccessibleTable
   * @see AccessibleTableModelChange
   */
  public static final String ACCESSIBLE_TABLE_MODEL_CHANGED
    = "accessibleTableModelChanged";

  /**
   * Constant used when the accessible table row header has changed. Only the
   * new value of the event has meaning.
   *
   * @see AccessibleTable
   * @see AccessibleTableModelChange
   */
  public static final String ACCESSIBLE_TABLE_ROW_HEADER_CHANGED
    = "accessibleTableRowHeaderChanged";

  /**
   * Constant used when the accessible table row description has changed. Only
   * the new value of the event has meaning.
   *
   * @see AccessibleTable
   */
  public static final String ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED
    = "accessibleTableRowDescriptionChanged";

  /**
   * Constant used when the accessible table column header has changed. Only
   * the new value of the event has meaning.
   *
   * @see AccessibleTable
   * @see AccessibleTableModelChange
   */
  public static final String ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED
    = "accessibleTableColumnHeaderChanged";

  /**
   * Constant used when the accessible table column description has changed.
   * Only the new value of the event has meaning.
   *
   * @see AccessibleTable
   */
  public static final String ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED
    = "accessibleTableColumnDescriptionChanged";

  /**
   * Constant used when supported set of actions has changed. Both the old
   * and new values are listed in the event.
   *
   * @see AccessibleAction
   */
  public static final String ACCESSIBLE_ACTION_PROPERTY
    = "accessibleActionProperty";

  /**
   * Constant used when a hypertext element received focus. Both the old
   * and new values are listed in the event, with -1 indicating that no link
   * had focus.
   *
   * @see AccessibleHyperlink
   */
  public static final String ACCESSIBLE_HYPERTEXT_OFFSET
    = "AccessibleHypertextOffset";

  /**
   * Constant used when a component's bounds have changed.  The old and
   * new bounds are given in the event.
   * @since 1.5
   */
  public static final String ACCESSIBLE_COMPONENT_BOUNDS_CHANGED
    = "accessibleComponentBoundsChanged";

  /**
   * Constant used when the state of child objects changes.  The old
   * value in the event is always null, and the new value is the component
   * whose children have changed.
   * @since 1.5
   */
  public static final String ACCESSIBLE_INVALIDATE_CHILDREN
    = "accessibleInvalidateChildren";

  /**
   * Constant used when the attributes of some text have changed.
   * On insertion, the old value is null and the new value is an
   * {@link AccessibleAttributeSequence} describing the insertion.
   * On deletion, the old value is an {@link AccessibleAttributeSequence}
   * and the new value is null.  For replacement, both the old
   * and new values are {@link AccessibleAttributeSequence} objects.
   * @since 1.5
   */
  public static final String ACCESSIBLE_TEXT_ATTRIBUTES_CHANGED
    = "accessibleTextAttributesChanged";

  /**
   * The accessible parent of this object.
   *
   * @see #getAccessibleParent()
   * @see #setAccessibleParent(Accessible)
   */
  protected Accessible accessibleParent;

  /**
   * A localized string naming this object.
   *
   * @see #getAccessibleName()
   * @see #setAccessibleName(String)
   */
  protected String accessibleName;

  /**
   * A localized string describing this object.
   *
   * @see #getAccessibleDescription()
   * @see #setAccessibleDescription(String)
   */
  protected String accessibleDescription;

  /**
   * The listener tool.
   *
   * @see #addPropertyChangeListener(PropertyChangeListener)
   * @see #removePropertyChangeListener(PropertyChangeListener)
   * @see #firePropertyChange(String, Object, Object)
   */
  private final PropertyChangeSupport listeners
    = new PropertyChangeSupport(this);

  /**
   * Default constructor.
   */
  public AccessibleContext()
  {
  }

  /**
   * Get the localized name of the object. For example, a label may just
   * return the text of the label, while an entry field for city may return
   * "city" in en_US.
   *
   * @return the accessible object's name, or null if it is unnamed
   * @see #setAccessibleName(String)
   */
  public String getAccessibleName()
  {
    return accessibleName;
  }

  /**
   * Set the localized name of the object. This will fire a
   * PropertyChangeEvent with ACCESSIBLE_NAME_PROPERTY.
   *
   * @param s the new name
   * @see #getAccessibleName()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public void setAccessibleName(String s)
  {
    listeners.firePropertyChange(ACCESSIBLE_NAME_PROPERTY, accessibleName, s);
    accessibleName = s;
  }

  /**
   * Get the localized description of the object. For example, a 'Cancel'
   * button may be described as "Ignore changes and close dialog box" in
   * en_US.
   *
   * @return the accessible object's description, or null if there is none
   * @see #setAccessibleDescription(String)
   */
  public String getAccessibleDescription()
  {
    return accessibleDescription;
  }

  /**
   * Set the localized name of the object. This will fire a
   * PropertyChangeEvent with ACCESSIBLE_DESCRIPTION_PROPERTY.
   *
   * @param s the new description
   * @see #getAccessibleDescription()
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public void setAccessibleDescription(String s)
  {
    listeners.firePropertyChange(ACCESSIBLE_DESCRIPTION_PROPERTY,
                                 accessibleDescription, s);
    accessibleDescription = s;
  }

  /**
   * Gets the role of this object. For example, a button serves the role of
   * AccessibleRole.PUSH_BUTTON. This allows assistive technologies to funnel
   * similar objects into the same assistance classes. Note that the class
   * is extensible, to define new roles if necessary.
   *
   * @return the role of the object
   * @see AccessibleRole
   */
  public abstract AccessibleRole getAccessibleRole();

  /**
   * Gets the state set of this object. A change in the state of the object
   * will fire a PropertyChangeEvent for ACCESSIBLE_STATE_PROPERTY.
   *
   * @return the current state of the object
   * @see AccessibleState
   * @see AccessibleStateSet
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public abstract AccessibleStateSet getAccessibleStateSet();

  /**
   * Return the accessible parent of this object.
   *
   * @return the accessible parent, or null if there is none
   */
  public Accessible getAccessibleParent()
  {
    return accessibleParent;
  }

  /**
   * Sets the accessible parent of this object. This should only be used when
   * the current parent object should not be the accessible parent; only the
   * parent of the accessible child should call this method.
   *
   * @param a the new parent
   */
  public void setAccessibleParent(Accessible a)
  {
    accessibleParent = a;
  }

  /**
   * Gets the index of this object within its accessible parent.
   *
   * @return the 0-based index, or -1 if there is no accessible parent
   * @see #getAccessibleParent()
   * @see #getAccessibleChildrenCount()
   * @see #getAccessibleChild(int)
   */
  public abstract int getAccessibleIndexInParent();

  /**
   * Returns the number of accessible children of this object.
   *
   * @return the number of accessible children
   * @see #getAccessibleChild(int)
   */
  public abstract int getAccessibleChildrenCount();

  /**
   * Returns the specified accessible chile.
   *
   * @param i the 0-based index to get
   * @return the child, or null if out of bounds
   * @see #getAccessibleChildrenCount()
   */
  public abstract Accessible getAccessibleChild(int i);

  /**
   * Gets the component locale, deferring to the parent if one is not declared.
   *
   * @return the locale
   * @throws java.awt.IllegalComponentStateException if there is no locale
   *         or parent
   */
  public abstract Locale getLocale();

  /**
   * Add a PropertyChangeListener to the listener list. This listener will
   * be notified of all property changes to the accessible object.
   *
   * @param l the listener to add
   * @see #ACCESSIBLE_NAME_PROPERTY
   * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
   * @see #ACCESSIBLE_STATE_PROPERTY
   * @see #ACCESSIBLE_VALUE_PROPERTY
   * @see #ACCESSIBLE_SELECTION_PROPERTY
   * @see #ACCESSIBLE_TEXT_PROPERTY
   * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
   * @see #removePropertyChangeListener(PropertyChangeListener)
   */
  public void addPropertyChangeListener(PropertyChangeListener l)
  {
    listeners.addPropertyChangeListener(l);
  }

  /**
   * Remove a PropertyChangeListener from the listener list.
   *
   * @param l the listener to remove
   * @see #addPropertyChangeListener(PropertyChangeListener)
   */
  public void removePropertyChangeListener(PropertyChangeListener l)
  {
    listeners.removePropertyChangeListener(l);
  }

  /**
   * Get any supported accessible actions. The default implementation returns
   * null.
   *
   * @return the supported action, or null
   * @see AccessibleAction
   */
  public AccessibleAction getAccessibleAction()
  {
    return null;
  }

  /**
   * Get any supported accessible component. The default implementation returns
   * null.
   *
   * @return the supported component, or null
   * @see AccessibleComponent
   */
  public AccessibleComponent getAccessibleComponent()
  {
    return null;
  }

  /**
   * Get any supported accessible selection. The default implementation returns
   * null.
   *
   * @return the supported selection, or null
   * @see AccessibleSelection
   */
  public AccessibleSelection getAccessibleSelection()
  {
    return null;
  }

  /**
   * Get any supported accessible text. The default implementation returns
   * null.
   *
   * @return the supported text, or null
   * @see AccessibleText
   */
  public AccessibleText getAccessibleText()
  {
    return null;
  }

  /**
   * Get any supported accessible editable text. The default implementation
   * returns null.
   *
   * @return the supported editable text, or null
   * @see AccessibleEditableText
   */
  public AccessibleEditableText getAccessibleEditableText()
  {
    return null;
  }

  /**
   * Get any supported accessible value. The default implementation returns
   * null.
   *
   * @return the supported value, or null
   * @see AccessibleValue
   */
  public AccessibleValue getAccessibleValue()
  {
    return null;
  }

  /**
   * Get all supported accessible icons. The default implementation returns
   * null.
   *
   * @return the supported icons, or null
   * @see AccessibleIcon
   */
  public AccessibleIcon[] getAccessibleIcon()
  {
    return null;
  }

  /**
   * Get any supported accessible relation set. The default implementation
   * returns an empty AccessibleRelationSet.
   *
   * @return the supported relation set, or <code>null</code>
   *
   * @see AccessibleRelationSet
   */
  public AccessibleRelationSet getAccessibleRelationSet()
  {
    return new AccessibleRelationSet();
  }

  /**
   * Get any supported accessible table. The default implementation returns
   * null.
   *
   * @return the supported table, or null
   * @see AccessibleTable
   */
  public AccessibleTable getAccessibleTable()
  {
    return null;
  }

  /**
   * Fire an event to report property changes. This is intended for use by
   * the accessible objects, not general application programs. If oldValue and
   * newValue differ, and the listenter list is not empty, a PropertyChange
   * event is fired to each listener.
   *
   * @param name the property name
   * @param oldValue the prior value
   * @param newValue the updated value
   * @see PropertyChangeSupport
   * @see #addPropertyChangeListener(PropertyChangeListener)
   * @see #removePropertyChangeListener(PropertyChangeListener)
   * @see #ACCESSIBLE_NAME_PROPERTY
   * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
   * @see #ACCESSIBLE_STATE_PROPERTY
   * @see #ACCESSIBLE_VALUE_PROPERTY
   * @see #ACCESSIBLE_SELECTION_PROPERTY
   * @see #ACCESSIBLE_TEXT_PROPERTY
   * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
   */
  public void firePropertyChange(String name, Object oldValue, Object newValue)
  {
    listeners.firePropertyChange(name, oldValue, newValue);
  }
} // class AccessibleContext