samples/friendpackage/src/apipkg/Item.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:27 +0200
changeset 3 b44baa125b38
parent 0 32b39aaa68f0
child 6 b577ee7fcf67
permissions -rw-r--r--
Accessor example is taken from real source code
     1 /*
     2  *                 Sun Public License Notice
     3  * 
     4  * The contents of this file are subject to the Sun Public License
     5  * Version 1.0 (the "License"). You may not use this file except in
     6  * compliance with the License. A copy of the License is available at
     7  * http://www.sun.com/
     8  * 
     9  * The Original Code is NetBeans. The Initial Developer of the Original
    10  * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun
    11  * Microsystems, Inc. All Rights Reserved.
    12  */
    13 
    14 package apipkg;
    15 
    16 import implpkg.Accessor;
    17 import javax.swing.event.ChangeEvent;
    18 import javax.swing.event.ChangeListener;
    19 
    20 /** Class in API that everyone can use.
    21  *
    22  * @author Jaroslav Tulach
    23  */
    24 // BEGIN: design.less.friend.Item
    25 public final class Item {
    26     private int value;
    27     private ChangeListener listener;
    28 
    29     // BEGIN: design.less.friend.Item.static
    30     static {
    31         Accessor.DEFAULT = new AccessorImpl();
    32     }
    33     // END: design.less.friend.Item.static
    34     
    35     /** Contructor for friends */
    36     Item() {
    37     }
    38     
    39     /** Anyone can value of the item. At least if it can get a reference to it.
    40      */
    41     public void setValue(int x) {
    42         value = x;
    43         ChangeListener l = listener;
    44         if (l != null) {
    45             l.stateChanged(new ChangeEvent(this));
    46         }
    47     }
    48     
    49     /** Anyone can get the value of the item. 
    50      */
    51     public int getValue() {
    52         return value;
    53     }
    54     
    55     /** Only the impl package can listen.
    56      */
    57     void addChangeListener(ChangeListener l) {
    58         assert listener == null;
    59         listener = l;
    60     }
    61     
    62 }
    63 // END: design.less.friend.Item