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