samples/friendpackage/src/apipkg/Item.java
changeset 0 32b39aaa68f0
child 3 b44baa125b38
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/friendpackage/src/apipkg/Item.java	Sat Jun 14 09:50:27 2008 +0200
     1.3 @@ -0,0 +1,59 @@
     1.4 +/*
     1.5 + *                 Sun Public License Notice
     1.6 + * 
     1.7 + * The contents of this file are subject to the Sun Public License
     1.8 + * Version 1.0 (the "License"). You may not use this file except in
     1.9 + * compliance with the License. A copy of the License is available at
    1.10 + * http://www.sun.com/
    1.11 + * 
    1.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    1.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun
    1.14 + * Microsystems, Inc. All Rights Reserved.
    1.15 + */
    1.16 +
    1.17 +package apipkg;
    1.18 +
    1.19 +import implpkg.Accessor;
    1.20 +import javax.swing.event.ChangeEvent;
    1.21 +import javax.swing.event.ChangeListener;
    1.22 +
    1.23 +/** Class in API that everyone can use.
    1.24 + *
    1.25 + * @author Jaroslav Tulach
    1.26 + */
    1.27 +public final class Item {
    1.28 +    private int value;
    1.29 +    private ChangeListener listener;
    1.30 +    
    1.31 +    static {
    1.32 +        Accessor.DEFAULT = new AccessorImpl();
    1.33 +    }
    1.34 +    
    1.35 +    /** Contructor for friends */
    1.36 +    Item() {
    1.37 +    }
    1.38 +    
    1.39 +    /** Anyone can value of the item. At least if it can get a reference to it.
    1.40 +     */
    1.41 +    public void setValue(int x) {
    1.42 +        value = x;
    1.43 +        ChangeListener l = listener;
    1.44 +        if (l != null) {
    1.45 +            l.stateChanged(new ChangeEvent(this));
    1.46 +        }
    1.47 +    }
    1.48 +    
    1.49 +    /** Anyone can get the value of the item. 
    1.50 +     */
    1.51 +    public int getValue() {
    1.52 +        return value;
    1.53 +    }
    1.54 +    
    1.55 +    /** Only the impl package can listen.
    1.56 +     */
    1.57 +    void addChangeListener(ChangeListener l) {
    1.58 +        assert listener == null;
    1.59 +        listener = l;
    1.60 +    }
    1.61 +    
    1.62 +}