KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > properties > StringEditor


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * StringEditor.java
22  *
23  * Created on January 23, 2006, 10:05 AM
24  *
25  */

26
27 package org.netbeans.modules.xml.schema.abe.nodes.properties;
28
29 import java.awt.FontMetrics JavaDoc;
30 import java.awt.Graphics JavaDoc;
31 import java.awt.Rectangle JavaDoc;
32 import java.beans.PropertyEditorSupport JavaDoc;
33 import org.openide.util.NbBundle;
34
35 /**
36  * A property editor for String class
37  * @author Ajit Bhate
38  */

39 public class StringEditor extends PropertyEditorSupport JavaDoc {
40
41     public final static String JavaDoc EMPTY = "";
42
43     /** Creates a new instance of StringEditor */
44     public StringEditor() {
45     }
46     
47     public String JavaDoc getAsText() {
48         Object JavaDoc value = super.getValue();
49         return value==null?EMPTY:super.getAsText();
50     }
51
52     /** sets new value */
53     public void setAsText(String JavaDoc s) {
54         if ( EMPTY.equals(s) && getValue() == null ) // NOI18N
55
return;
56         setValue(s);
57     }
58
59     public boolean isPaintable() {
60         return true;
61     }
62     
63     public void paintValue(Graphics JavaDoc g, Rectangle JavaDoc rectangle) {
64         String JavaDoc paintableString=getPaintableString();
65         
66         FontMetrics JavaDoc metrics=g.getFontMetrics();
67         g.drawString(paintableString,rectangle.x,
68                 rectangle.y+(rectangle.height-metrics.getHeight())/2+
69                 metrics.getAscent());
70     }
71     
72     protected String JavaDoc getPaintableString() {
73         String JavaDoc value=(String JavaDoc)getValue();
74         return value==null?NbBundle.getMessage(StringEditor.class,"LBL_Null"):value;
75     }
76 }
77
Popular Tags