KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > actions > ToggleActionPropertyChangeListener


1 /*
2  * $Id: ToggleActionPropertyChangeListener.java,v 1.1.1.1 2004/06/16 01:43:39 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 /**
9  * @(#)ToggleActionPropertyChangeListener.java 1.5 02/10/07
10  *
11  * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
12  *
13  * Redistribution and use in source and binary forms, with or
14  * without modification, are permitted provided that the following
15  * conditions are met:
16  *
17  * - Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  *
20  * - Redistribution in binary form must reproduce the above
21  * copyright notice, this list of conditions and the following
22  * disclaimer in the documentation and/or other materials
23  * provided with the distribution.
24  *
25  * Neither the name of Sun Microsystems, Inc. or the names of
26  * contributors may be used to endorse or promote products derived
27  * from this software without specific prior written permission.
28  *
29  * This software is provided "AS IS," without a warranty of any
30  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
31  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
32  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
33  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
34  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
35  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
36  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
37  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
38  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
39  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
40  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
41  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42  *
43  * You acknowledge that this software is not designed, licensed or
44  * intended for use in the design, construction, operation or
45  * maintenance of any nuclear facility.
46  *
47  */

48
49 package org.jdesktop.swing.actions;
50
51 import java.beans.PropertyChangeListener JavaDoc;
52 import java.beans.PropertyChangeEvent JavaDoc;
53
54 import javax.swing.AbstractButton JavaDoc;
55
56 /**
57  * Added to the Toggle type buttons and menu items so that various components
58  * which have been created from a single StateChangeAction can be in synch
59  */

60 class ToggleActionPropertyChangeListener implements PropertyChangeListener JavaDoc {
61
62     // XXX - Should be a WeakRef since it's unreachable!
63
// this is a potential memory leak but we don't really have to
64
// worry about it since the most of the time the buttons will be
65
// loaded for the lifetime of the application. Should make it
66
// weak referenced for a general purpose toolkit.
67
private AbstractButton JavaDoc button;
68
69     public ToggleActionPropertyChangeListener(AbstractButton JavaDoc button) {
70     this.button = button;
71     }
72
73     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
74     String JavaDoc propertyName = evt.getPropertyName();
75
76     if (propertyName.equals("selected")) {
77         Boolean JavaDoc selected = (Boolean JavaDoc)evt.getNewValue();
78         button.setSelected(selected.booleanValue());
79     }
80     }
81 }
82
Popular Tags