Lines 51-61
Link Here
|
51 |
import org.openide.explorer.propertysheet.PropertyEnv; |
51 |
import org.openide.explorer.propertysheet.PropertyEnv; |
52 |
import java.beans.FeatureDescriptor; |
52 |
import java.beans.FeatureDescriptor; |
53 |
import org.openide.nodes.Node; |
53 |
import org.openide.nodes.Node; |
|
|
54 |
import org.openide.util.NbBundle; |
54 |
|
55 |
|
55 |
|
56 |
/** |
56 |
/** A property editor for String class. |
57 |
* A property editor for String class. |
57 |
* @author Ian Formanek |
58 |
* @author Ian Formanek |
58 |
* @version 1.00, 18 Sep, 1998 |
|
|
59 |
*/ |
59 |
*/ |
60 |
public class StringEditor extends PropertyEditorSupport implements ExPropertyEditor |
60 |
public class StringEditor extends PropertyEditorSupport implements ExPropertyEditor |
61 |
{ |
61 |
{ |
Lines 68-100
Link Here
|
68 |
return (editable); |
68 |
return (editable); |
69 |
} |
69 |
} |
70 |
|
70 |
|
|
|
71 |
@Override |
72 |
public String getAsText() { |
73 |
Object value = getValue(); |
74 |
if (value != null) { |
75 |
return value.toString(); |
76 |
} else { |
77 |
return nullValue != null ? nullValue : NbBundle.getMessage(StringEditor.class, "CTL_NullValue"); |
78 |
} |
79 |
} |
80 |
|
71 |
/** sets new value */ |
81 |
/** sets new value */ |
|
|
82 |
@Override |
72 |
public void setAsText(String s) { |
83 |
public void setAsText(String s) { |
73 |
if ( "null".equals( s ) && getValue() == null ) // NOI18N |
84 |
if ( "null".equals( s ) && getValue() == null ) // NOI18N |
74 |
return; |
85 |
return; |
|
|
86 |
if (nullValue != null && nullValue.equals (s)) { |
87 |
setValue (null); |
88 |
return; |
89 |
} |
90 |
|
75 |
setValue(s); |
91 |
setValue(s); |
76 |
} |
92 |
} |
77 |
|
93 |
|
|
|
94 |
@Override |
78 |
public String getJavaInitializationString () { |
95 |
public String getJavaInitializationString () { |
79 |
String s = (String) getValue (); |
96 |
String s = (String) getValue (); |
80 |
return "\"" + toAscii(s) + "\""; // NOI18N |
97 |
return "\"" + toAscii(s) + "\""; // NOI18N |
81 |
} |
98 |
} |
82 |
|
99 |
|
|
|
100 |
@Override |
83 |
public boolean supportsCustomEditor () { |
101 |
public boolean supportsCustomEditor () { |
84 |
return customEd; |
102 |
return customEd; |
85 |
} |
103 |
} |
86 |
|
104 |
|
|
|
105 |
@Override |
87 |
public java.awt.Component getCustomEditor () { |
106 |
public java.awt.Component getCustomEditor () { |
88 |
Object val = getValue(); |
107 |
Object val = getValue(); |
89 |
String s = ""; // NOI18N |
108 |
String s = ""; // NOI18N |
90 |
if (val != null) { |
109 |
if (val != null) { |
91 |
s = val instanceof String ? (String) val : val.toString(); |
110 |
s = val instanceof String ? (String) val : val.toString(); |
92 |
} |
111 |
} |
93 |
return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env); // NOI18N |
112 |
return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env); |
94 |
} |
113 |
} |
95 |
|
114 |
|
96 |
private static String toAscii(String str) { |
115 |
private static String toAscii(String str) { |
97 |
StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234 |
116 |
StringBuilder buf = new StringBuilder(str.length() * 6); // x -> \u1234 |
98 |
char[] chars = str.toCharArray(); |
117 |
char[] chars = str.toCharArray(); |
99 |
for (int i = 0; i < chars.length; i++) { |
118 |
for (int i = 0; i < chars.length; i++) { |
100 |
char c = chars[i]; |
119 |
char c = chars[i]; |
Lines 126-137
Link Here
|
126 |
private boolean oneline=false; |
145 |
private boolean oneline=false; |
127 |
private boolean customEd=true; |
146 |
private boolean customEd=true; |
128 |
private PropertyEnv env; |
147 |
private PropertyEnv env; |
|
|
148 |
/** null or name to use for null value */ |
149 |
private String nullValue; |
129 |
|
150 |
|
130 |
// bugfix# 9219 added attachEnv() method checking if the user canWrite in text box |
151 |
// bugfix# 9219 added attachEnv() method checking if the user canWrite in text box |
|
|
152 |
@Override |
131 |
public void attachEnv(PropertyEnv env) { |
153 |
public void attachEnv(PropertyEnv env) { |
132 |
this.env = env; |
154 |
this.env = env; |
133 |
|
155 |
|
134 |
FeatureDescriptor desc = env.getFeatureDescriptor(); |
156 |
readEnv(env.getFeatureDescriptor()); |
|
|
157 |
} |
158 |
|
159 |
/*@VisibleForTesting*/ void readEnv (FeatureDescriptor desc) { |
135 |
if (desc instanceof Node.Property){ |
160 |
if (desc instanceof Node.Property){ |
136 |
Node.Property prop = (Node.Property)desc; |
161 |
Node.Property prop = (Node.Property)desc; |
137 |
editable = prop.canWrite(); |
162 |
editable = prop.canWrite(); |
Lines 139-146
Link Here
|
139 |
//editor |
164 |
//editor |
140 |
instructions = (String) prop.getValue ("instructions"); //NOI18N |
165 |
instructions = (String) prop.getValue ("instructions"); //NOI18N |
141 |
oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N |
166 |
oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N |
142 |
customEd = !Boolean.TRUE.equals (prop.getValue |
167 |
customEd = !Boolean.TRUE.equals (prop.getValue |
143 |
("suppressCustomEditor")); //NOI18N |
168 |
("suppressCustomEditor")); //NOI18N |
144 |
} |
169 |
} |
|
|
170 |
Object obj = desc.getValue(ObjectEditor.PROP_NULL); |
171 |
if (Boolean.TRUE.equals(obj)) { |
172 |
nullValue = NbBundle.getMessage(StringEditor.class, "CTL_NullValue"); |
173 |
} else { |
174 |
if (obj instanceof String) { |
175 |
nullValue = (String)obj; |
176 |
} else { |
177 |
nullValue = null; |
178 |
} |
179 |
} |
145 |
} |
180 |
} |
146 |
} |
181 |
} |