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
2873 * {@code JList} class. It provides an implementation of the
2874 * Java Accessibility API appropriate to list user-interface
2875 * elements.
2876 * <p>
2877 * <strong>Warning:</strong>
2878 * Serialized objects of this class will not be compatible with
2879 * future Swing releases. The current serialization support is
2880 * appropriate for short term storage or RMI between applications running
2881 * the same version of Swing. As of 1.4, support for long term storage
2882 * of all JavaBeans™
2883 * has been added to the <code>java.beans</code> package.
2884 * Please see {@link java.beans.XMLEncoder}.
2885 */
2886 @SuppressWarnings("serial") // Same-version serialization only
2887 protected class AccessibleJList extends AccessibleJComponent
2888 implements AccessibleSelection, PropertyChangeListener,
2889 ListSelectionListener, ListDataListener {
2890
2891 int leadSelectionIndex;
2892
2893 public AccessibleJList() {
2894 super();
2895 JList.this.addPropertyChangeListener(this);
2896 JList.this.getSelectionModel().addListSelectionListener(this);
2897 JList.this.getModel().addListDataListener(this);
2898 leadSelectionIndex = JList.this.getLeadSelectionIndex();
2899 }
2900
2901 /**
2902 * Property Change Listener change method. Used to track changes
2903 * to the DataModel and ListSelectionModel, in order to re-set
2904 * listeners to those for reporting changes there via the Accessibility
2905 * PropertyChange mechanism.
2906 *
2907 * @param e PropertyChangeEvent
2908 */
2909 public void propertyChange(PropertyChangeEvent e) {
2910 String name = e.getPropertyName();
2911 Object oldValue = e.getOldValue();
2912 Object newValue = e.getNewValue();
3176 * Causes every selected item in the object to be selected
3177 * if the object supports multiple selections.
3178 */
3179 public void selectAllAccessibleSelection() {
3180 JList.this.addSelectionInterval(0, getAccessibleChildrenCount() -1);
3181 }
3182
3183 /**
3184 * This class implements accessibility support appropriate
3185 * for list children.
3186 */
3187 protected class AccessibleJListChild extends AccessibleContext
3188 implements Accessible, AccessibleComponent {
3189 private JList<E> parent = null;
3190 private int indexInParent;
3191 private Component component = null;
3192 private AccessibleContext accessibleContext = null;
3193 private ListModel<E> listModel;
3194 private ListCellRenderer<? super E> cellRenderer = null;
3195
3196 public AccessibleJListChild(JList<E> parent, int indexInParent) {
3197 this.parent = parent;
3198 this.setAccessibleParent(parent);
3199 this.indexInParent = indexInParent;
3200 if (parent != null) {
3201 listModel = parent.getModel();
3202 cellRenderer = parent.getCellRenderer();
3203 }
3204 }
3205
3206 private Component getCurrentComponent() {
3207 return getComponentAtIndex(indexInParent);
3208 }
3209
3210 private AccessibleContext getCurrentAccessibleContext() {
3211 Component c = getComponentAtIndex(indexInParent);
3212 if (c instanceof Accessible) {
3213 return c.getAccessibleContext();
3214 } else {
3215 return null;
|
1 /*
2 * Copyright (c) 1997, 2015, 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
2873 * {@code JList} class. It provides an implementation of the
2874 * Java Accessibility API appropriate to list user-interface
2875 * elements.
2876 * <p>
2877 * <strong>Warning:</strong>
2878 * Serialized objects of this class will not be compatible with
2879 * future Swing releases. The current serialization support is
2880 * appropriate for short term storage or RMI between applications running
2881 * the same version of Swing. As of 1.4, support for long term storage
2882 * of all JavaBeans™
2883 * has been added to the <code>java.beans</code> package.
2884 * Please see {@link java.beans.XMLEncoder}.
2885 */
2886 @SuppressWarnings("serial") // Same-version serialization only
2887 protected class AccessibleJList extends AccessibleJComponent
2888 implements AccessibleSelection, PropertyChangeListener,
2889 ListSelectionListener, ListDataListener {
2890
2891 int leadSelectionIndex;
2892
2893 /**
2894 * Constructs an {@code AccessibleJList}.
2895 */
2896 public AccessibleJList() {
2897 super();
2898 JList.this.addPropertyChangeListener(this);
2899 JList.this.getSelectionModel().addListSelectionListener(this);
2900 JList.this.getModel().addListDataListener(this);
2901 leadSelectionIndex = JList.this.getLeadSelectionIndex();
2902 }
2903
2904 /**
2905 * Property Change Listener change method. Used to track changes
2906 * to the DataModel and ListSelectionModel, in order to re-set
2907 * listeners to those for reporting changes there via the Accessibility
2908 * PropertyChange mechanism.
2909 *
2910 * @param e PropertyChangeEvent
2911 */
2912 public void propertyChange(PropertyChangeEvent e) {
2913 String name = e.getPropertyName();
2914 Object oldValue = e.getOldValue();
2915 Object newValue = e.getNewValue();
3179 * Causes every selected item in the object to be selected
3180 * if the object supports multiple selections.
3181 */
3182 public void selectAllAccessibleSelection() {
3183 JList.this.addSelectionInterval(0, getAccessibleChildrenCount() -1);
3184 }
3185
3186 /**
3187 * This class implements accessibility support appropriate
3188 * for list children.
3189 */
3190 protected class AccessibleJListChild extends AccessibleContext
3191 implements Accessible, AccessibleComponent {
3192 private JList<E> parent = null;
3193 private int indexInParent;
3194 private Component component = null;
3195 private AccessibleContext accessibleContext = null;
3196 private ListModel<E> listModel;
3197 private ListCellRenderer<? super E> cellRenderer = null;
3198
3199 /**
3200 * Constructs an {@code AccessibleJListChild}.
3201 * @param parent the parent
3202 * @param indexInParent the index in the parent
3203 */
3204 public AccessibleJListChild(JList<E> parent, int indexInParent) {
3205 this.parent = parent;
3206 this.setAccessibleParent(parent);
3207 this.indexInParent = indexInParent;
3208 if (parent != null) {
3209 listModel = parent.getModel();
3210 cellRenderer = parent.getCellRenderer();
3211 }
3212 }
3213
3214 private Component getCurrentComponent() {
3215 return getComponentAtIndex(indexInParent);
3216 }
3217
3218 private AccessibleContext getCurrentAccessibleContext() {
3219 Component c = getComponentAtIndex(indexInParent);
3220 if (c instanceof Accessible) {
3221 return c.getAccessibleContext();
3222 } else {
3223 return null;
|