KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > BooleanStringItemListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * BooleanStringItemListener.java
26  *
27  * Created on March 18, 2001, 12:24 PM
28  */

29
30 package com.sun.enterprise.tools.common;
31
32 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
33 /**
34  *
35  * @author vkraemer
36  * @version
37  */

38 public class BooleanStringItemListener implements java.awt.event.ItemListener JavaDoc {
39     
40     Object JavaDoc target = null;
41     java.lang.reflect.Method JavaDoc writer = null;
42
43         private Object JavaDoc args[] = { target };
44     
45
46     /** Creates new BooleanStringItemListener */
47     public BooleanStringItemListener(Object JavaDoc target, String JavaDoc destName) throws java.beans.IntrospectionException JavaDoc {
48         this.target = target;
49         writer = PropertyUtils.getWriter(target,destName);
50     }
51     
52     public BooleanStringItemListener(Object JavaDoc target) {
53         this.target = target;
54     }
55
56     private static final String JavaDoc FALSE[] = {"false" };//NOI18N
57
private static final String JavaDoc TRUE[] = { "true" };//NOI18N
58

59     public void itemStateChanged(java.awt.event.ItemEvent JavaDoc itemEvent) {
60         try {
61             java.lang.reflect.Method JavaDoc lwriter = writer;
62             if (null == lwriter) {
63                 java.awt.Component JavaDoc src = (java.awt.Component JavaDoc) itemEvent.getSource();
64                 lwriter = PropertyUtils.getWriter(target, src.getName());
65             }
66             Object JavaDoc args[] = FALSE;
67             if (itemEvent.getStateChange() == java.awt.event.ItemEvent.SELECTED)
68                 args = TRUE;
69             lwriter.invoke(target, args);
70         }
71         catch (Throwable JavaDoc t) {
72             Reporter.critical(t); //NOI18N
73
}
74     }
75     
76 }
77
Popular Tags