samples/friendpackage/src/apipkg/Item.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:27 +0200
changeset 0 32b39aaa68f0
child 3 b44baa125b38
permissions -rw-r--r--
Adding friend access example
     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 public final class Item {
    25     private int value;
    26     private ChangeListener listener;
    27     
    28     static {
    29         Accessor.DEFAULT = new AccessorImpl();
    30     }
    31     
    32     /** Contructor for friends */
    33     Item() {
    34     }
    35     
    36     /** Anyone can value of the item. At least if it can get a reference to it.
    37      */
    38     public void setValue(int x) {
    39         value = x;
    40         ChangeListener l = listener;
    41         if (l != null) {
    42             l.stateChanged(new ChangeEvent(this));
    43         }
    44     }
    45     
    46     /** Anyone can get the value of the item. 
    47      */
    48     public int getValue() {
    49         return value;
    50     }
    51     
    52     /** Only the impl package can listen.
    53      */
    54     void addChangeListener(ChangeListener l) {
    55         assert listener == null;
    56         listener = l;
    57     }
    58     
    59 }