KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > options > VetoSystemOption


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.options;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyVetoException JavaDoc;
23 import java.beans.VetoableChangeListener JavaDoc;
24
25 import java.util.*;
26
27
28 /** Extends the functionality of <CODE>SystemOption</CODE>
29 * by providing support for veto listeners.
30 *
31 * @author Jaroslav Tulach
32 * @version 0.11 Dec 6, 1997
33 */

34 public abstract class VetoSystemOption extends SystemOption {
35     /** generated Serialized Version UID */
36     static final long serialVersionUID = -614731095908156413L;
37
38     /** vetoable listener property */
39     private static final String JavaDoc PROP_VETO_SUPPORT = "vetoSupport"; // NOI18N
40

41     /** Default constructor. */
42     public VetoSystemOption() {
43     }
44
45     /** Lazy getter for veto hashtable.
46     * @return the hashtable
47     */

48     private HashSet getVeto() {
49         HashSet set = (HashSet) getProperty(PROP_VETO_SUPPORT);
50
51         if (set == null) {
52             set = new HashSet();
53             putProperty(PROP_VETO_SUPPORT, set);
54         }
55
56         return set;
57     }
58
59     /** Add a new veto listener to all instances of this exact class.
60     * @param list the listener to add
61     */

62     public final void addVetoableChangeListener(VetoableChangeListener JavaDoc list) {
63         synchronized (getLock()) {
64             getVeto().add(list);
65         }
66     }
67
68     /** Remove a veto listener from all instances of this exact class.
69     * @param list the listener to remove
70     */

71     public final void removeVetoableChangeListener(VetoableChangeListener JavaDoc list) {
72         synchronized (getLock()) {
73             getVeto().remove(list);
74         }
75     }
76
77     /** Fire a property change event.
78     * @param name the name of the property
79     * @param oldValue the old value
80     * @param newValue the new value
81     * @exception PropertyVetoException if the change is vetoed
82     */

83     public final void fireVetoableChange(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
84     throws PropertyVetoException JavaDoc {
85         PropertyChangeEvent JavaDoc ev = new PropertyChangeEvent JavaDoc(this, name, oldValue, newValue);
86
87         Iterator en;
88
89         synchronized (getLock()) {
90             en = ((HashSet) getVeto().clone()).iterator();
91         }
92
93         while (en.hasNext()) {
94             ((VetoableChangeListener JavaDoc) en.next()).vetoableChange(ev);
95         }
96     }
97 }
98
Popular Tags