Source for javax.accessibility.AccessibleRelation

   1: /* AccessibleRelation.java -- the relation between accessible objects
   2:    Copyright (C) 2002, 2005 Free Software Foundation
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package javax.accessibility;
  39: 
  40: import java.util.Locale;
  41: 
  42: /**
  43:  * The relation between one accessible object and one or more other objects.
  44:  * For example, a button may control an action. An AccessibleRelationSet
  45:  * summarizes all relations of the object. This strongly typed "enumeration"
  46:  * supports localized strings. If the constants of this class are not
  47:  * adequate, new ones may be added in a similar matter.
  48:  * 
  49:  * @author Eric Blake (ebb9@email.byu.edu)
  50:  * @since 1.2
  51:  * @status updated to 1.4
  52:  */
  53: public class AccessibleRelation extends AccessibleBundle
  54: {
  55:   /**
  56:    * Indicates the object labels other objects.
  57:    *
  58:    * @see #getTarget()
  59:    * @see #CONTROLLER_FOR
  60:    * @see #CONTROLLED_BY
  61:    * @see #LABELED_BY
  62:    * @see #MEMBER_OF
  63:    */
  64:   public static final String LABEL_FOR = "labelFor";
  65: 
  66:   /**
  67:    * Indicates the object is labeled by other objects.
  68:    *
  69:    * @see #getTarget()
  70:    * @see #CONTROLLER_FOR
  71:    * @see #CONTROLLED_BY
  72:    * @see #LABEL_FOR
  73:    * @see #MEMBER_OF
  74:    */
  75:   public static final String LABELED_BY = "labeledBy";
  76: 
  77:   /**
  78:    * Indicates an object is a member of a group of target objects.
  79:    *
  80:    * @see #getTarget()
  81:    * @see #CONTROLLER_FOR
  82:    * @see #CONTROLLED_BY
  83:    * @see #LABEL_FOR
  84:    * @see #LABELED_BY
  85:    */
  86:   public static final String MEMBER_OF = "memberOf";
  87: 
  88:   /**
  89:    * Indicates an object is a controller for other objects.
  90:    *
  91:    * @see #getTarget()
  92:    * @see #CONTROLLED_BY
  93:    * @see #LABEL_FOR
  94:    * @see #LABELED_BY
  95:    * @see #MEMBER_OF
  96:    */
  97:   public static final String CONTROLLER_FOR = "controllerFor";
  98: 
  99:   /**
 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 = "controlledBy";
 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:   /** An empty set of targets. */
 126:   private static final Object[] EMPTY_TARGETS = { };
 127: 
 128:   /**
 129:    * The related objects.
 130:    *
 131:    * @see #getTarget()
 132:    * @see #setTarget(Object)
 133:    * @see #setTarget(Object[])
 134:    */
 135:   Object[] targets;
 136: 
 137:   /**
 138:    * Create a new relation with a locale independent key, and no related
 139:    * objects.
 140:    *
 141:    * @param key the name of the role
 142:    * @see #toDisplayString(String, Locale)
 143:    */
 144:   public AccessibleRelation(String key)
 145:   {
 146:     this.key = key;
 147:     targets = EMPTY_TARGETS;
 148:   }
 149: 
 150:   /**
 151:    * Create a new relation with a locale independent key, and a single related
 152:    * object.
 153:    *
 154:    * @param key the name of the role
 155:    * @param target the related object
 156:    * @see #toDisplayString(String, Locale)
 157:    */
 158:   public AccessibleRelation(String key, Object target)
 159:   {
 160:     this.key = key;
 161:     targets = new Object[] { target };
 162:   }
 163: 
 164:   /**
 165:    * Create a new relation with a locale independent key, and the given
 166:    * related objects.
 167:    *
 168:    * @param key the name of the role
 169:    * @param targets the related objects
 170:    * @see #toDisplayString(String, Locale)
 171:    */
 172:   public AccessibleRelation(String key, Object[] targets)
 173:   {
 174:     this.key = key;
 175:     this.targets = targets == null ? EMPTY_TARGETS : targets;
 176:   }
 177: 
 178:   /**
 179:    * Return the key for this relation.
 180:    *
 181:    * @return the key
 182:    * @see #CONTROLLER_FOR
 183:    * @see #CONTROLLED_BY
 184:    * @see #LABEL_FOR
 185:    * @see #LABELED_BY
 186:    * @see #MEMBER_OF
 187:    */
 188:   public String getKey()
 189:   {
 190:     return key;
 191:   }
 192: 
 193:   /**
 194:    * Return the targets of this relation.
 195:    *
 196:    * @return the targets, may be empty, but never null
 197:    */
 198:   public Object[] getTarget()
 199:   {
 200:     return targets;
 201:   }
 202: 
 203:   /**
 204:    * Set the target to a single object.
 205:    *
 206:    * @param target the new target
 207:    */
 208:   public void setTarget(Object target)
 209:   {
 210:     targets = new Object[] { target };
 211:   }
 212: 
 213:   /**
 214:    * Set the target to an array of objects.
 215:    *
 216:    * @param targets the new targets
 217:    */
 218:   public void setTarget(Object[] targets)
 219:   {
 220:     this.targets = targets == null ? EMPTY_TARGETS : targets;
 221:   }
 222: } // class AccessibleRelation