Source Code Cross Referenced for Checkbox.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025        package java.awt;
026
027        import java.awt.peer.CheckboxPeer;
028        import java.awt.event.*;
029        import java.util.EventListener;
030        import java.io.ObjectOutputStream;
031        import java.io.ObjectInputStream;
032        import java.io.IOException;
033        import javax.accessibility.*;
034
035        /**
036         * A check box is a graphical component that can be in either an
037         * "on" (<code>true</code>) or "off" (<code>false</code>) state.
038         * Clicking on a check box changes its state from
039         * "on" to "off," or from "off" to "on."
040         * <p>
041         * The following code example creates a set of check boxes in
042         * a grid layout:
043         * <p>
044         * <hr><blockquote><pre>
045         * setLayout(new GridLayout(3, 1));
046         * add(new Checkbox("one", null, true));
047         * add(new Checkbox("two"));
048         * add(new Checkbox("three"));
049         * </pre></blockquote><hr>
050         * <p>
051         * This image depicts the check boxes and grid layout
052         * created by this code example:
053         * <p>
054         * <img src="doc-files/Checkbox-1.gif" alt="The following context describes the graphic."
055         * ALIGN=center HSPACE=10 VSPACE=7>
056         * <p>
057         * The button labeled <code>one</code> is in the "on" state, and the
058         * other two are in the "off" state. In this example, which uses the
059         * <code>GridLayout</code> class, the states of the three check
060         * boxes are set independently.
061         * <p>
062         * Alternatively, several check boxes can be grouped together under
063         * the control of a single object, using the
064         * <code>CheckboxGroup</code> class.
065         * In a check box group, at most one button can be in the "on"
066         * state at any given time. Clicking on a check box to turn it on
067         * forces any other check box in the same group that is on
068         * into the "off" state.
069         *
070         * @version	1.95 05/05/07
071         * @author 	Sami Shaio
072         * @see         java.awt.GridLayout
073         * @see         java.awt.CheckboxGroup
074         * @since       JDK1.0
075         */
076        public class Checkbox extends Component implements  ItemSelectable,
077                Accessible {
078
079            static {
080                /* ensure that the necessary native libraries are loaded */
081                Toolkit.loadLibraries();
082                if (!GraphicsEnvironment.isHeadless()) {
083                    initIDs();
084                }
085            }
086
087            /**
088             * The label of the Checkbox.
089             * This field can be null.
090             * @serial
091             * @see #getLabel()
092             * @see #setLabel(String)
093             */
094            String label;
095
096            /**
097             * The state of the <code>Checkbox</code>.
098             * @serial
099             * @see #getState()
100             * @see #setState(boolean)
101             */
102            boolean state;
103
104            /**
105             * The check box group.
106             * This field can be null indicating that the checkbox
107             * is not a group checkbox.  
108             * @serial
109             * @see #getCheckboxGroup()
110             * @see #setCheckboxGroup(CheckboxGroup)
111             */
112            CheckboxGroup group;
113
114            transient ItemListener itemListener;
115
116            private static final String base = "checkbox";
117            private static int nameCounter = 0;
118
119            /*
120             * JDK 1.1 serialVersionUID
121             */
122            private static final long serialVersionUID = 7270714317450821763L;
123
124            /**
125             * Helper function for setState and CheckboxGroup.setSelectedCheckbox
126             * Should remain package-private.
127             */
128            void setStateInternal(boolean state) {
129                this .state = state;
130                CheckboxPeer peer = (CheckboxPeer) this .peer;
131                if (peer != null) {
132                    peer.setState(state);
133                }
134            }
135
136            /**
137             * Creates a check box with an empty string for its label. 
138             * The state of this check box is set to "off," and it is not 
139             * part of any check box group. 
140             * @exception HeadlessException if GraphicsEnvironment.isHeadless()
141             * returns true
142             * @see java.awt.GraphicsEnvironment#isHeadless
143             */
144            public Checkbox() throws HeadlessException {
145                this ("", false, null);
146            }
147
148            /**
149             * Creates a check box with the specified label.  The state
150             * of this check box is set to "off," and it is not part of
151             * any check box group.
152             *
153             * @param     label   a string label for this check box,
154             *                        or <code>null</code> for no label.
155             * @exception HeadlessException if
156             *      <code>GraphicsEnvironment.isHeadless</code>
157             *      returns <code>true</code>
158             * @see java.awt.GraphicsEnvironment#isHeadless
159             */
160            public Checkbox(String label) throws HeadlessException {
161                this (label, false, null);
162            }
163
164            /**
165             * Creates a check box with the specified label
166             * and sets the specified state.
167             * This check box is not part of any check box group.
168             *
169             * @param     label   a string label for this check box,
170             *                        or <code>null</code> for no label
171             * @param     state    the initial state of this check box
172             * @exception HeadlessException if
173             *     <code>GraphicsEnvironment.isHeadless</code>
174             *     returns <code>true</code>
175             * @see java.awt.GraphicsEnvironment#isHeadless
176             */
177            public Checkbox(String label, boolean state)
178                    throws HeadlessException {
179                this (label, state, null);
180            }
181
182            /**
183             * Constructs a Checkbox with the specified label, set to the
184             * specified state, and in the specified check box group.
185             * 
186             * @param     label   a string label for this check box,
187             *                        or <code>null</code> for no label.
188             * @param     state   the initial state of this check box.
189             * @param     group   a check box group for this check box,
190             *                           or <code>null</code> for no group.
191             * @exception HeadlessException if
192             *     <code>GraphicsEnvironment.isHeadless</code>
193             *     returns <code>true</code>
194             * @see java.awt.GraphicsEnvironment#isHeadless
195             * @since     JDK1.1
196             */
197            public Checkbox(String label, boolean state, CheckboxGroup group)
198                    throws HeadlessException {
199                GraphicsEnvironment.checkHeadless();
200                this .label = label;
201                this .state = state;
202                this .group = group;
203                if (state && (group != null)) {
204                    group.setSelectedCheckbox(this );
205                }
206            }
207
208            /**
209             * Creates a check box with the specified label, in the specified
210             * check box group, and set to the specified state.
211             *
212             * @param     label   a string label for this check box,
213             *                        or <code>null</code> for no label.
214             * @param     group   a check box group for this check box,
215             *                           or <code>null</code> for no group.
216             * @param     state   the initial state of this check box.
217             * @exception HeadlessException if
218             *    <code>GraphicsEnvironment.isHeadless</code>
219             *    returns <code>true</code>
220             * @see java.awt.GraphicsEnvironment#isHeadless
221             * @since     JDK1.1
222             */
223            public Checkbox(String label, CheckboxGroup group, boolean state)
224                    throws HeadlessException {
225                this (label, state, group);
226            }
227
228            /**
229             * Constructs a name for this component.  Called by
230             * <code>getName</code> when the name is <code>null</code>.
231             *
232             * @return a name for this component
233             */
234            String constructComponentName() {
235                synchronized (Checkbox.class) {
236                    return base + nameCounter++;
237                }
238            }
239
240            /**
241             * Creates the peer of the Checkbox. The peer allows you to change the
242             * look of the Checkbox without changing its functionality.
243             *
244             * @see     java.awt.Toolkit#createCheckbox(java.awt.Checkbox)
245             * @see     java.awt.Component#getToolkit()
246             */
247            public void addNotify() {
248                synchronized (getTreeLock()) {
249                    if (peer == null)
250                        peer = getToolkit().createCheckbox(this );
251                    super .addNotify();
252                }
253            }
254
255            /**
256             * Gets the label of this check box.
257             *
258             * @return   the label of this check box, or <code>null</code>
259             *                  if this check box has no label.
260             * @see      #setLabel(String)
261             */
262            public String getLabel() {
263                return label;
264            }
265
266            /**
267             * Sets this check box's label to be the string argument.
268             *
269             * @param    label   a string to set as the new label, or
270             *                        <code>null</code> for no label.
271             * @see      #getLabel
272             */
273            public void setLabel(String label) {
274                boolean testvalid = false;
275
276                synchronized (this ) {
277                    if (label != this .label
278                            && (this .label == null || !this .label.equals(label))) {
279                        this .label = label;
280                        CheckboxPeer peer = (CheckboxPeer) this .peer;
281                        if (peer != null) {
282                            peer.setLabel(label);
283                        }
284                        testvalid = true;
285                    }
286                }
287
288                // This could change the preferred size of the Component.
289                if (testvalid && valid) {
290                    invalidate();
291                }
292            }
293
294            /**
295             * Determines whether this check box is in the "on" or "off" state.
296             * The boolean value <code>true</code> indicates the "on" state,
297             * and <code>false</code> indicates the "off" state.
298             *
299             * @return    the state of this check box, as a boolean value
300             * @see       #setState
301             */
302            public boolean getState() {
303                return state;
304            }
305
306            /**
307             * Sets the state of this check box to the specified state.
308             * The boolean value <code>true</code> indicates the "on" state,
309             * and <code>false</code> indicates the "off" state.
310             *
311             * <p>Note that this method should be primarily used to
312             * initialize the state of the checkbox.  Programmatically
313             * setting the state of the checkbox will <i>not</i> trigger
314             * an <code>ItemEvent</code>.  The only way to trigger an
315             * <code>ItemEvent</code> is by user interaction.
316             *
317             * @param     state   the boolean state of the check box
318             * @see       #getState
319             */
320            public void setState(boolean state) {
321                /* Cannot hold check box lock when calling group.setSelectedCheckbox. */
322                CheckboxGroup group = this .group;
323                if (group != null) {
324                    if (state) {
325                        group.setSelectedCheckbox(this );
326                    } else if (group.getSelectedCheckbox() == this ) {
327                        state = true;
328                    }
329                }
330                setStateInternal(state);
331            }
332
333            /**
334             * Returns an array (length 1) containing the checkbox
335             * label or null if the checkbox is not selected.
336             * @see ItemSelectable
337             */
338            public Object[] getSelectedObjects() {
339                if (state) {
340                    Object[] items = new Object[1];
341                    items[0] = label;
342                    return items;
343                }
344                return null;
345            }
346
347            /**
348             * Determines this check box's group.
349             * @return     this check box's group, or <code>null</code>
350             *               if the check box is not part of a check box group.
351             * @see        #setCheckboxGroup(CheckboxGroup)
352             */
353            public CheckboxGroup getCheckboxGroup() {
354                return group;
355            }
356
357            /**
358             * Sets this check box's group to the specified check box group.
359             * If this check box is already in a different check box group,
360             * it is first taken out of that group.
361             * <p>
362             * If the state of this check box is <code>true</code> and the new
363             * group already has a check box selected, this check box's state
364             * is changed to <code>false</code>.  If the state of this check
365             * box is <code>true</code> and the new group has no check box
366             * selected, this check box becomes the selected checkbox for
367             * the new group and its state is <code>true</code>.
368             *
369             * @param     g   the new check box group, or <code>null</code>
370             *                to remove this check box from any check box group
371             * @see       #getCheckboxGroup
372             */
373            public void setCheckboxGroup(CheckboxGroup g) {
374                CheckboxGroup oldGroup;
375                boolean oldState;
376
377                /* Do nothing if this check box has already belonged
378                 * to the check box group g.
379                 */
380                if (this .group == g) {
381                    return;
382                }
383
384                synchronized (this ) {
385                    oldGroup = this .group;
386                    oldState = getState();
387
388                    this .group = g;
389                    CheckboxPeer peer = (CheckboxPeer) this .peer;
390                    if (peer != null) {
391                        peer.setCheckboxGroup(g);
392                    }
393                    if (this .group != null && getState()) {
394                        if (this .group.getSelectedCheckbox() != null) {
395                            setState(false);
396                        } else {
397                            this .group.setSelectedCheckbox(this );
398                        }
399                    }
400                }
401
402                /* Locking check box below could cause deadlock with
403                 * CheckboxGroup's setSelectedCheckbox method.
404                 *
405                 * Fix for 4726853 by kdm@sparc.spb.su
406                 * Here we should check if this check box was selected
407                 * in the previous group and set selected check box to
408                 * null for that group if so.
409                 */
410                if (oldGroup != null && oldState) {
411                    oldGroup.setSelectedCheckbox(null);
412                }
413            }
414
415            /**
416             * Adds the specified item listener to receive item events from
417             * this check box.  Item events are sent to listeners in response
418             * to user input, but not in response to calls to setState().
419             * If l is null, no exception is thrown and no action is performed.
420             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
421             * >AWT Threading Issues</a> for details on AWT's threading model.
422             *
423             * @param         l    the item listener
424             * @see           #removeItemListener
425             * @see           #getItemListeners
426             * @see           #setState
427             * @see           java.awt.event.ItemEvent
428             * @see           java.awt.event.ItemListener
429             * @since         JDK1.1
430             */
431            public synchronized void addItemListener(ItemListener l) {
432                if (l == null) {
433                    return;
434                }
435                itemListener = AWTEventMulticaster.add(itemListener, l);
436                newEventsOnly = true;
437            }
438
439            /**
440             * Removes the specified item listener so that the item listener
441             * no longer receives item events from this check box.
442             * If l is null, no exception is thrown and no action is performed.
443             * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
444             * >AWT Threading Issues</a> for details on AWT's threading model.
445             *
446             * @param         l    the item listener
447             * @see           #addItemListener
448             * @see           #getItemListeners
449             * @see           java.awt.event.ItemEvent
450             * @see           java.awt.event.ItemListener
451             * @since         JDK1.1
452             */
453            public synchronized void removeItemListener(ItemListener l) {
454                if (l == null) {
455                    return;
456                }
457                itemListener = AWTEventMulticaster.remove(itemListener, l);
458            }
459
460            /**
461             * Returns an array of all the item listeners
462             * registered on this checkbox.
463             *
464             * @return all of this checkbox's <code>ItemListener</code>s
465             *         or an empty array if no item 
466             *         listeners are currently registered
467             *
468             * @see           #addItemListener
469             * @see           #removeItemListener
470             * @see           java.awt.event.ItemEvent
471             * @see           java.awt.event.ItemListener
472             * @since 1.4
473             */
474            public synchronized ItemListener[] getItemListeners() {
475                return (ItemListener[]) (getListeners(ItemListener.class));
476            }
477
478            /**
479             * Returns an array of all the objects currently registered
480             * as <code><em>Foo</em>Listener</code>s
481             * upon this <code>Checkbox</code>.
482             * <code><em>Foo</em>Listener</code>s are registered using the
483             * <code>add<em>Foo</em>Listener</code> method.
484             *
485             * <p>
486             * You can specify the <code>listenerType</code> argument
487             * with a class literal, such as
488             * <code><em>Foo</em>Listener.class</code>.
489             * For example, you can query a
490             * <code>Checkbox</code> <code>c</code>
491             * for its item listeners with the following code:
492             *
493             * <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
494             *
495             * If no such listeners exist, this method returns an empty array.
496             *
497             * @param listenerType the type of listeners requested; this parameter
498             *          should specify an interface that descends from
499             *          <code>java.util.EventListener</code>
500             * @return an array of all objects registered as
501             *          <code><em>Foo</em>Listener</code>s on this checkbox,
502             *          or an empty array if no such
503             *          listeners have been added
504             * @exception ClassCastException if <code>listenerType</code>
505             *          doesn't specify a class or interface that implements
506             *          <code>java.util.EventListener</code>
507             *
508             * @see #getItemListeners
509             * @since 1.3
510             */
511            public <T extends EventListener> T[] getListeners(
512                    Class<T> listenerType) {
513                EventListener l = null;
514                if (listenerType == ItemListener.class) {
515                    l = itemListener;
516                } else {
517                    return super .getListeners(listenerType);
518                }
519                return AWTEventMulticaster.getListeners(l, listenerType);
520            }
521
522            // REMIND: remove when filtering is done at lower level
523            boolean eventEnabled(AWTEvent e) {
524                if (e.id == ItemEvent.ITEM_STATE_CHANGED) {
525                    if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0
526                            || itemListener != null) {
527                        return true;
528                    }
529                    return false;
530                }
531                return super .eventEnabled(e);
532            }
533
534            /**
535             * Processes events on this check box.
536             * If the event is an instance of <code>ItemEvent</code>,
537             * this method invokes the <code>processItemEvent</code> method.
538             * Otherwise, it calls its superclass's <code>processEvent</code> method.
539             * <p>Note that if the event parameter is <code>null</code>
540             * the behavior is unspecified and may result in an
541             * exception.
542             *
543             * @param         e the event
544             * @see           java.awt.event.ItemEvent
545             * @see           #processItemEvent
546             * @since         JDK1.1
547             */
548            protected void processEvent(AWTEvent e) {
549                if (e instanceof  ItemEvent) {
550                    processItemEvent((ItemEvent) e);
551                    return;
552                }
553                super .processEvent(e);
554            }
555
556            /**
557             * Processes item events occurring on this check box by
558             * dispatching them to any registered
559             * <code>ItemListener</code> objects.
560             * <p>
561             * This method is not called unless item events are
562             * enabled for this component. Item events are enabled
563             * when one of the following occurs:
564             * <p><ul>
565             * <li>An <code>ItemListener</code> object is registered
566             * via <code>addItemListener</code>.
567             * <li>Item events are enabled via <code>enableEvents</code>.
568             * </ul>
569             * <p>Note that if the event parameter is <code>null</code>
570             * the behavior is unspecified and may result in an
571             * exception.
572             *
573             * @param       e the item event
574             * @see         java.awt.event.ItemEvent
575             * @see         java.awt.event.ItemListener
576             * @see         #addItemListener
577             * @see         java.awt.Component#enableEvents
578             * @since       JDK1.1
579             */
580            protected void processItemEvent(ItemEvent e) {
581                ItemListener listener = itemListener;
582                if (listener != null) {
583                    listener.itemStateChanged(e);
584                }
585            }
586
587            /**
588             * Returns a string representing the state of this <code>Checkbox</code>.
589             * This method is intended to be used only for debugging purposes, and the 
590             * content and format of the returned string may vary between 
591             * implementations. The returned string may be empty but may not be 
592             * <code>null</code>.
593             *
594             * @return    the parameter string of this check box
595             */
596            protected String paramString() {
597                String str = super .paramString();
598                String label = this .label;
599                if (label != null) {
600                    str += ",label=" + label;
601                }
602                return str + ",state=" + state;
603            }
604
605            /* Serialization support.
606             */
607
608            /*
609             * Serialized data version
610             * @serial
611             */
612            private int checkboxSerializedDataVersion = 1;
613
614            /**
615             * Writes default serializable fields to stream.  Writes
616             * a list of serializable <code>ItemListeners</code>
617             * as optional data.  The non-serializable
618             * <code>ItemListeners</code> are detected and
619             * no attempt is made to serialize them.
620             *
621             * @param s the <code>ObjectOutputStream</code> to write
622             * @serialData <code>null</code> terminated sequence of 0 
623             *   or more pairs; the pair consists of a <code>String</code>
624             *   and an <code>Object</code>; the <code>String</code> indicates
625             *   the type of object and is one of the following:
626             *   <code>itemListenerK</code> indicating an
627             *     <code>ItemListener</code> object
628             *
629             * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
630             * @see java.awt.Component#itemListenerK
631             * @see #readObject(ObjectInputStream)
632             */
633            private void writeObject(ObjectOutputStream s)
634                    throws java.io.IOException {
635                s.defaultWriteObject();
636
637                AWTEventMulticaster.save(s, itemListenerK, itemListener);
638                s.writeObject(null);
639            }
640
641            /**
642             * Reads the <code>ObjectInputStream</code> and if it
643             * isn't <code>null</code> adds a listener to receive
644             * item events fired by the <code>Checkbox</code>.
645             * Unrecognized keys or values will be ignored.
646             *
647             * @param s the <code>ObjectInputStream</code> to read
648             * @exception HeadlessException if
649             *   <code>GraphicsEnvironment.isHeadless</code> returns
650             *   <code>true</code>
651             * @serial
652             * @see #removeItemListener(ItemListener)
653             * @see #addItemListener(ItemListener)
654             * @see java.awt.GraphicsEnvironment#isHeadless
655             * @see #writeObject(ObjectOutputStream)
656             */
657            private void readObject(ObjectInputStream s)
658                    throws ClassNotFoundException, IOException,
659                    HeadlessException {
660                GraphicsEnvironment.checkHeadless();
661                s.defaultReadObject();
662
663                Object keyOrNull;
664                while (null != (keyOrNull = s.readObject())) {
665                    String key = ((String) keyOrNull).intern();
666
667                    if (itemListenerK == key)
668                        addItemListener((ItemListener) (s.readObject()));
669
670                    else
671                        // skip value for unrecognized key
672                        s.readObject();
673                }
674            }
675
676            /**
677             * Initialize JNI field and method ids
678             */
679            private static native void initIDs();
680
681            /////////////////
682            // Accessibility support
683            ////////////////
684
685            /**
686             * Gets the AccessibleContext associated with this Checkbox. 
687             * For checkboxes, the AccessibleContext takes the form of an 
688             * AccessibleAWTCheckbox. 
689             * A new AccessibleAWTCheckbox is created if necessary.
690             *
691             * @return an AccessibleAWTCheckbox that serves as the 
692             *         AccessibleContext of this Checkbox
693             * @since 1.3
694             */
695            public AccessibleContext getAccessibleContext() {
696                if (accessibleContext == null) {
697                    accessibleContext = new AccessibleAWTCheckbox();
698                }
699                return accessibleContext;
700            }
701
702            /**
703             * This class implements accessibility support for the 
704             * <code>Checkbox</code> class.  It provides an implementation of the 
705             * Java Accessibility API appropriate to checkbox user-interface elements.
706             * @since 1.3
707             */
708            protected class AccessibleAWTCheckbox extends
709                    AccessibleAWTComponent implements  ItemListener,
710                    AccessibleAction, AccessibleValue {
711                /*
712                 * JDK 1.3 serialVersionUID
713                 */
714                private static final long serialVersionUID = 7881579233144754107L;
715
716                public AccessibleAWTCheckbox() {
717                    super ();
718                    Checkbox.this .addItemListener(this );
719                }
720
721                /**
722                 * Fire accessible property change events when the state of the
723                 * toggle button changes.
724                 */
725                public void itemStateChanged(ItemEvent e) {
726                    Checkbox cb = (Checkbox) e.getSource();
727                    if (Checkbox.this .accessibleContext != null) {
728                        if (cb.getState()) {
729                            Checkbox.this .accessibleContext
730                                    .firePropertyChange(
731                                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
732                                            null, AccessibleState.CHECKED);
733                        } else {
734                            Checkbox.this .accessibleContext
735                                    .firePropertyChange(
736                                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
737                                            AccessibleState.CHECKED, null);
738                        }
739                    }
740                }
741
742                /**
743                 * Get the AccessibleAction associated with this object.  In the
744                 * implementation of the Java Accessibility API for this class, 
745                 * return this object, which is responsible for implementing the
746                 * AccessibleAction interface on behalf of itself.
747                 * 
748                 * @return this object
749                 */
750                public AccessibleAction getAccessibleAction() {
751                    return this ;
752                }
753
754                /**
755                 * Get the AccessibleValue associated with this object.  In the
756                 * implementation of the Java Accessibility API for this class, 
757                 * return this object, which is responsible for implementing the
758                 * AccessibleValue interface on behalf of itself.
759                 * 
760                 * @return this object
761                 */
762                public AccessibleValue getAccessibleValue() {
763                    return this ;
764                }
765
766                /**
767                 * Returns the number of Actions available in this object.
768                 * If there is more than one, the first one is the "default"
769                 * action.
770                 *
771                 * @return the number of Actions in this object
772                 */
773                public int getAccessibleActionCount() {
774                    return 0; //  To be fully implemented in a future release
775                }
776
777                /**
778                 * Return a description of the specified action of the object.
779                 *
780                 * @param i zero-based index of the actions
781                 */
782                public String getAccessibleActionDescription(int i) {
783                    return null; //  To be fully implemented in a future release
784                }
785
786                /**
787                 * Perform the specified Action on the object
788                 *
789                 * @param i zero-based index of actions
790                 * @return true if the the action was performed; else false.
791                 */
792                public boolean doAccessibleAction(int i) {
793                    return false; //  To be fully implemented in a future release
794                }
795
796                /**
797                 * Get the value of this object as a Number.  If the value has not been
798                 * set, the return value will be null.
799                 *
800                 * @return value of the object
801                 * @see #setCurrentAccessibleValue
802                 */
803                public Number getCurrentAccessibleValue() {
804                    return null; //  To be fully implemented in a future release
805                }
806
807                /**
808                 * Set the value of this object as a Number.
809                 *
810                 * @return True if the value was set; else False
811                 * @see #getCurrentAccessibleValue
812                 */
813                public boolean setCurrentAccessibleValue(Number n) {
814                    return false; //  To be fully implemented in a future release
815                }
816
817                /**
818                 * Get the minimum value of this object as a Number.
819                 *
820                 * @return Minimum value of the object; null if this object does not
821                 * have a minimum value
822                 * @see #getMaximumAccessibleValue
823                 */
824                public Number getMinimumAccessibleValue() {
825                    return null; //  To be fully implemented in a future release
826                }
827
828                /**
829                 * Get the maximum value of this object as a Number.
830                 *
831                 * @return Maximum value of the object; null if this object does not
832                 * have a maximum value
833                 * @see #getMinimumAccessibleValue
834                 */
835                public Number getMaximumAccessibleValue() {
836                    return null; //  To be fully implemented in a future release
837                }
838
839                /**
840                 * Get the role of this object.
841                 *
842                 * @return an instance of AccessibleRole describing the role of 
843                 * the object
844                 * @see AccessibleRole
845                 */
846                public AccessibleRole getAccessibleRole() {
847                    return AccessibleRole.CHECK_BOX;
848                }
849
850                /**
851                 * Get the state set of this object.
852                 *
853                 * @return an instance of AccessibleState containing the current state
854                 * of the object
855                 * @see AccessibleState
856                 */
857                public AccessibleStateSet getAccessibleStateSet() {
858                    AccessibleStateSet states = super .getAccessibleStateSet();
859                    if (getState()) {
860                        states.add(AccessibleState.CHECKED);
861                    }
862                    return states;
863                }
864
865            } // inner class AccessibleAWTCheckbox
866
867        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.