src/share/classes/javax/accessibility/AccessibleStateSet.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 154      * @return true if the state is in the state set; otherwise false
 155      */
 156     public boolean contains(AccessibleState state) {
 157         if (states == null) {
 158             return false;
 159         } else {
 160             return states.contains(state);
 161         }
 162     }
 163 
 164     /**
 165      * Returns the current state set as an array of AccessibleState
 166      * @return AccessibleState array containing the current state.
 167      */
 168     public AccessibleState[] toArray() {
 169         if (states == null) {
 170             return new AccessibleState[0];
 171         } else {
 172             AccessibleState[] stateArray = new AccessibleState[states.size()];
 173             for (int i = 0; i < stateArray.length; i++) {
 174                 stateArray[i] = (AccessibleState) states.elementAt(i);
 175             }
 176             return stateArray;
 177         }
 178     }
 179 
 180     /**
 181      * Creates a localized String representing all the states in the set
 182      * using the default locale.
 183      *
 184      * @return comma separated localized String
 185      * @see AccessibleBundle#toDisplayString
 186      */
 187     public String toString() {
 188         String ret = null;
 189         if ((states != null) && (states.size() > 0)) {
 190             ret = ((AccessibleState) (states.elementAt(0))).toDisplayString();
 191             for (int i = 1; i < states.size(); i++) {
 192                 ret = ret + ","
 193                         + ((AccessibleState) (states.elementAt(i))).
 194                                               toDisplayString();
 195             }
 196         }
 197         return ret;
 198     }
 199 }
   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 154      * @return true if the state is in the state set; otherwise false
 155      */
 156     public boolean contains(AccessibleState state) {
 157         if (states == null) {
 158             return false;
 159         } else {
 160             return states.contains(state);
 161         }
 162     }
 163 
 164     /**
 165      * Returns the current state set as an array of AccessibleState
 166      * @return AccessibleState array containing the current state.
 167      */
 168     public AccessibleState[] toArray() {
 169         if (states == null) {
 170             return new AccessibleState[0];
 171         } else {
 172             AccessibleState[] stateArray = new AccessibleState[states.size()];
 173             for (int i = 0; i < stateArray.length; i++) {
 174                 stateArray[i] = states.elementAt(i);
 175             }
 176             return stateArray;
 177         }
 178     }
 179 
 180     /**
 181      * Creates a localized String representing all the states in the set
 182      * using the default locale.
 183      *
 184      * @return comma separated localized String
 185      * @see AccessibleBundle#toDisplayString
 186      */
 187     public String toString() {
 188         String ret = null;
 189         if ((states != null) && (states.size() > 0)) {
 190             ret = states.elementAt(0).toDisplayString();
 191             for (int i = 1; i < states.size(); i++) {
 192                 ret = ret + ","
 193                         + states.elementAt(i).toDisplayString();

 194             }
 195         }
 196         return ret;
 197     }
 198 }