KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > beaninfo > awt > LabelBeanInfo


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
20 package org.netbeans.modules.form.beaninfo.awt;
21
22 import java.awt.Label JavaDoc;
23 import java.beans.*;
24
25 import org.openide.util.NbBundle;
26
27 /** A BeanInfo for java.awt.Label.
28 *
29 * @author Ales Novak
30
31 */

32 public class LabelBeanInfo extends ComponentBeanInfo.Support {
33
34     public LabelBeanInfo() {
35         super("label", java.awt.Label JavaDoc.class); // NOI18N
36
}
37
38     /** @return Propertydescriptors */
39     protected PropertyDescriptor[] createPDs() throws IntrospectionException {
40         PropertyDescriptor[] pds = new PropertyDescriptor[] {
41             new PropertyDescriptor("alignment", Label JavaDoc.class), // NOI18N
42
new PropertyDescriptor("text", Label JavaDoc.class), // NOI18N
43
};
44         pds[0].setPropertyEditorClass(LabelBeanInfo.AlignmentPropertyEditor.class);
45         return pds;
46     }
47
48     public static class AlignmentPropertyEditor extends PropertyEditorSupport {
49         String JavaDoc[] tags;
50
51         /** @return tags */
52         public synchronized String JavaDoc[] getTags() {
53             if (tags == null) {
54                 tags = new String JavaDoc[] {
55                     getString("LEFT"),
56                     getString("CENTER"),
57                     getString("RIGHT")
58                 };
59             }
60             return tags;
61         }
62
63         public void setAsText(String JavaDoc s) {
64             Integer JavaDoc i;
65             getTags();
66             if (s.equals(tags[0])) i = new Integer JavaDoc(java.awt.Label.LEFT);
67             else if (s.equals(tags[1])) i = new Integer JavaDoc(java.awt.Label.CENTER);
68             else i = new Integer JavaDoc(java.awt.Label.RIGHT);
69             setValue(i);
70         }
71
72         public String JavaDoc getAsText() {
73             int i = ((Integer JavaDoc) getValue()).intValue();
74             getTags();
75             return tags[i == java.awt.Label.CENTER ? 1 : (i == java.awt.Label.LEFT ? 0 : 2)];
76         }
77
78         public String JavaDoc getJavaInitializationString () {
79             int i = ((Integer JavaDoc) getValue()).intValue();
80             switch (i) {
81             case java.awt.Label.RIGHT : return "java.awt.Label.RIGHT"; // NOI18N
82
case java.awt.Label.LEFT : return "java.awt.Label.LEFT"; // NOI18N
83
default:
84             case java.awt.Label.CENTER : return "java.awt.Label.CENTER"; // NOI18N
85
}
86         }
87     }
88
89     /** i18n */
90     static String JavaDoc getString(String JavaDoc x) {
91         return NbBundle.getMessage(LabelBeanInfo.class, x);
92     }
93 }
94
Popular Tags