< prev index next >

src/java.desktop/share/classes/java/awt/Component.java

Print this page




9722          * events from this component.
9723          *
9724          * @param l the focus listener
9725          */
9726         public void removeFocusListener(FocusListener l) {
9727             Component.this.removeFocusListener(l);
9728         }
9729 
9730     } // inner class AccessibleAWTComponent
9731 
9732 
9733     /**
9734      * Gets the index of this object in its accessible parent.
9735      * If this object does not have an accessible parent, returns
9736      * -1.
9737      *
9738      * @return the index of this object in its accessible parent
9739      */
9740     int getAccessibleIndexInParent() {
9741         synchronized (getTreeLock()) {
9742             int index = -1;
9743             Container parent = this.getParent();
9744             if (parent != null && parent instanceof Accessible) {
9745                 Component ca[] = parent.getComponents();
9746                 for (int i = 0; i < ca.length; i++) {
9747                     if (ca[i] instanceof Accessible) {
9748                         index++;
9749                     }
9750                     if (this.equals(ca[i])) {
9751                         return index;


9752                     }










9753                 }
9754             }

9755             return -1;
9756         }
9757     }
9758 
9759     /**
9760      * Gets the current state set of this object.
9761      *
9762      * @return an instance of {@code AccessibleStateSet}
9763      *    containing the current state set of the object
9764      * @see AccessibleState
9765      */
9766     AccessibleStateSet getAccessibleStateSet() {
9767         synchronized (getTreeLock()) {
9768             AccessibleStateSet states = new AccessibleStateSet();
9769             if (this.isEnabled()) {
9770                 states.add(AccessibleState.ENABLED);
9771             }
9772             if (this.isFocusTraversable()) {
9773                 states.add(AccessibleState.FOCUSABLE);
9774             }




9722          * events from this component.
9723          *
9724          * @param l the focus listener
9725          */
9726         public void removeFocusListener(FocusListener l) {
9727             Component.this.removeFocusListener(l);
9728         }
9729 
9730     } // inner class AccessibleAWTComponent
9731 
9732 
9733     /**
9734      * Gets the index of this object in its accessible parent.
9735      * If this object does not have an accessible parent, returns
9736      * -1.
9737      *
9738      * @return the index of this object in its accessible parent
9739      */
9740     int getAccessibleIndexInParent() {
9741         synchronized (getTreeLock()) {
9742             if (!(this instanceof Accessible)) {
9743                 return -1;





9744             }
9745 
9746             AccessibleContext accContext = getAccessibleContext();
9747             if (accContext == null) {
9748                 return -1;
9749             }
9750 
9751             Accessible parent = accContext.getAccessibleParent();
9752             if (parent == null) {
9753                 return -1;
9754             }
9755 
9756             accContext = parent.getAccessibleContext();
9757             for (int i = 0; i < accContext.getAccessibleChildrenCount(); i++) {
9758                 if (this.equals(accContext.getAccessibleChild(i))) {
9759                     return i;
9760                 }
9761             }
9762 
9763             return -1;
9764         }
9765     }
9766 
9767     /**
9768      * Gets the current state set of this object.
9769      *
9770      * @return an instance of {@code AccessibleStateSet}
9771      *    containing the current state set of the object
9772      * @see AccessibleState
9773      */
9774     AccessibleStateSet getAccessibleStateSet() {
9775         synchronized (getTreeLock()) {
9776             AccessibleStateSet states = new AccessibleStateSet();
9777             if (this.isEnabled()) {
9778                 states.add(AccessibleState.ENABLED);
9779             }
9780             if (this.isFocusTraversable()) {
9781                 states.add(AccessibleState.FOCUSABLE);
9782             }


< prev index next >