KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > editors > WrappersEditor


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.beaninfo.editors;
21
22 import java.beans.*;
23 import java.text.MessageFormat JavaDoc;
24 import org.netbeans.core.UIExceptions;
25 import org.openide.explorer.propertysheet.ExPropertyEditor;
26 import org.openide.explorer.propertysheet.PropertyEnv;
27 import org.openide.util.NbBundle;
28
29 /**
30  * Abstract class represents Editor for Wrappers of 8 known primitive types
31  * (Byte, Short, Integer, Long, Boolean, Float, Double, Character)
32  *
33  * @author Josef Kozak
34  */

35 public abstract class WrappersEditor implements ExPropertyEditor {
36
37     protected PropertyEditor pe = null;
38     
39     public WrappersEditor(Class JavaDoc type) {
40         super();
41         pe = PropertyEditorManager.findEditor(type);
42     }
43     
44     public void setValue(Object JavaDoc newValue) throws IllegalArgumentException JavaDoc {
45         pe.setValue(newValue);
46     }
47     
48     public Object JavaDoc getValue() {
49     return pe.getValue();
50     }
51     
52     public boolean isPaintable() {
53     return pe.isPaintable();
54     }
55
56     public void paintValue(java.awt.Graphics JavaDoc gfx, java.awt.Rectangle JavaDoc box) {
57         pe.paintValue(gfx, box);
58     }
59     
60     public String JavaDoc getAsText () {
61         if ( pe.getValue() == null )
62             return "null"; // NOI18N
63
return pe.getAsText();
64     }
65
66     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
67         if ( "null".equals( text ) ) // NOI18N
68
return;
69         try {
70             pe.setAsText(text);
71         } catch (Exception JavaDoc e) {
72             //Reasonable to assume any exceptions from core/jdk editors are legit
73
IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc (e.getMessage());
74             String JavaDoc msg = e.getLocalizedMessage();
75             if (msg == null || e.getMessage().equals(msg)) {
76                 msg = MessageFormat.format(
77                 NbBundle.getMessage(
78                     WrappersEditor.class, "FMT_EXC_GENERIC_BAD_VALUE"), text); //NOI18N
79
}
80             UIExceptions.annotateUser(iae, iae.getMessage(), msg, e,
81                                      new java.util.Date JavaDoc());
82             throw iae;
83         }
84     }
85     
86     public String JavaDoc[] getTags() {
87     return pe.getTags();
88     }
89     
90     public java.awt.Component JavaDoc getCustomEditor() {
91     return pe.getCustomEditor();
92     }
93
94     public boolean supportsCustomEditor() {
95     return pe.supportsCustomEditor();
96     }
97   
98     public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
99         pe.addPropertyChangeListener(listener);
100     }
101
102     public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
103         pe.removePropertyChangeListener(listener);
104     }
105     
106     public void attachEnv(PropertyEnv env) {
107         //Delegate if the primitive editor is an ExPropertyEditor -
108
//boolean and int editors will be
109
if (pe instanceof ExPropertyEditor) {
110             ((ExPropertyEditor) pe).attachEnv (env);
111         }
112     }
113 }
114
Popular Tags