src/share/classes/java/awt/Choice.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2013, 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


 139         }
 140     }
 141 
 142     /**
 143      * Creates the <code>Choice</code>'s peer.  This peer allows us
 144      * to change the look
 145      * of the <code>Choice</code> without changing its functionality.
 146      * @see     java.awt.Toolkit#createChoice(java.awt.Choice)
 147      * @see     java.awt.Component#getToolkit()
 148      */
 149     public void addNotify() {
 150         synchronized (getTreeLock()) {
 151             if (peer == null)
 152                 peer = getToolkit().createChoice(this);
 153             super.addNotify();
 154         }
 155     }
 156 
 157     /**
 158      * Returns the number of items in this <code>Choice</code> menu.

 159      * @return the number of items in this <code>Choice</code> menu
 160      * @see     #getItem
 161      * @since   JDK1.1
 162      */
 163     public int getItemCount() {
 164         return countItems();
 165     }
 166 
 167     /**



 168      * @deprecated As of JDK version 1.1,
 169      * replaced by <code>getItemCount()</code>.
 170      */
 171     @Deprecated
 172     public int countItems() {
 173         return pItems.size();
 174     }
 175 
 176     /**
 177      * Gets the string at the specified index in this
 178      * <code>Choice</code> menu.

 179      * @param      index the index at which to begin

 180      * @see        #getItemCount
 181      */
 182     public String getItem(int index) {
 183         return getItemImpl(index);
 184     }
 185 
 186     /*
 187      * This is called by the native code, so client code can't
 188      * be called on the toolkit thread.
 189      */
 190     final String getItemImpl(int index) {
 191         return pItems.elementAt(index);
 192     }
 193 
 194     /**
 195      * Adds an item to this <code>Choice</code> menu.
 196      * @param      item    the item to be added
 197      * @exception  NullPointerException   if the item's value is
 198      *                  <code>null</code>
 199      * @since      JDK1.1


 742         if (accessibleContext == null) {
 743             accessibleContext = new AccessibleAWTChoice();
 744         }
 745         return accessibleContext;
 746     }
 747 
 748     /**
 749      * This class implements accessibility support for the
 750      * <code>Choice</code> class.  It provides an implementation of the
 751      * Java Accessibility API appropriate to choice user-interface elements.
 752      * @since 1.3
 753      */
 754     protected class AccessibleAWTChoice extends AccessibleAWTComponent
 755         implements AccessibleAction
 756     {
 757         /*
 758          * JDK 1.3 serialVersionUID
 759          */
 760         private static final long serialVersionUID = 7175603582428509322L;
 761 



 762         public AccessibleAWTChoice() {
 763             super();
 764         }
 765 
 766         /**
 767          * Get the AccessibleAction associated with this object.  In the
 768          * implementation of the Java Accessibility API for this class,
 769          * return this object, which is responsible for implementing the
 770          * AccessibleAction interface on behalf of itself.
 771          *
 772          * @return this object
 773          * @see AccessibleAction
 774          */
 775         public AccessibleAction getAccessibleAction() {
 776             return this;
 777         }
 778 
 779         /**
 780          * Get the role of this object.
 781          *


   1 /*
   2  * Copyright (c) 1995, 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


 139         }
 140     }
 141 
 142     /**
 143      * Creates the <code>Choice</code>'s peer.  This peer allows us
 144      * to change the look
 145      * of the <code>Choice</code> without changing its functionality.
 146      * @see     java.awt.Toolkit#createChoice(java.awt.Choice)
 147      * @see     java.awt.Component#getToolkit()
 148      */
 149     public void addNotify() {
 150         synchronized (getTreeLock()) {
 151             if (peer == null)
 152                 peer = getToolkit().createChoice(this);
 153             super.addNotify();
 154         }
 155     }
 156 
 157     /**
 158      * Returns the number of items in this <code>Choice</code> menu.
 159      *
 160      * @return the number of items in this <code>Choice</code> menu
 161      * @see     #getItem
 162      * @since   JDK1.1
 163      */
 164     public int getItemCount() {
 165         return countItems();
 166     }
 167 
 168     /**
 169      * Returns the number of items in this {@code Choice} menu.
 170      *
 171      * @return the number of items in this {@code Choice} menu
 172      * @deprecated As of JDK version 1.1,
 173      * replaced by <code>getItemCount()</code>.
 174      */
 175     @Deprecated
 176     public int countItems() {
 177         return pItems.size();
 178     }
 179 
 180     /**
 181      * Gets the string at the specified index in this
 182      * <code>Choice</code> menu.
 183      *
 184      * @param  index the index at which to begin
 185      * @return the item at the specified index
 186      * @see    #getItemCount
 187      */
 188     public String getItem(int index) {
 189         return getItemImpl(index);
 190     }
 191 
 192     /*
 193      * This is called by the native code, so client code can't
 194      * be called on the toolkit thread.
 195      */
 196     final String getItemImpl(int index) {
 197         return pItems.elementAt(index);
 198     }
 199 
 200     /**
 201      * Adds an item to this <code>Choice</code> menu.
 202      * @param      item    the item to be added
 203      * @exception  NullPointerException   if the item's value is
 204      *                  <code>null</code>
 205      * @since      JDK1.1


 748         if (accessibleContext == null) {
 749             accessibleContext = new AccessibleAWTChoice();
 750         }
 751         return accessibleContext;
 752     }
 753 
 754     /**
 755      * This class implements accessibility support for the
 756      * <code>Choice</code> class.  It provides an implementation of the
 757      * Java Accessibility API appropriate to choice user-interface elements.
 758      * @since 1.3
 759      */
 760     protected class AccessibleAWTChoice extends AccessibleAWTComponent
 761         implements AccessibleAction
 762     {
 763         /*
 764          * JDK 1.3 serialVersionUID
 765          */
 766         private static final long serialVersionUID = 7175603582428509322L;
 767 
 768         /**
 769          * Constructor for {@code AccessibleAWTChoice}
 770          */
 771         public AccessibleAWTChoice() {
 772             super();
 773         }
 774 
 775         /**
 776          * Get the AccessibleAction associated with this object.  In the
 777          * implementation of the Java Accessibility API for this class,
 778          * return this object, which is responsible for implementing the
 779          * AccessibleAction interface on behalf of itself.
 780          *
 781          * @return this object
 782          * @see AccessibleAction
 783          */
 784         public AccessibleAction getAccessibleAction() {
 785             return this;
 786         }
 787 
 788         /**
 789          * Get the role of this object.
 790          *