001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std;
042:
043: import java.beans.FeatureDescriptor;
044: import java.beans.PropertyEditorSupport; // bugfix# 9219 for attachEnv() method
045: import org.openide.explorer.propertysheet.ExPropertyEditor;
046: import org.openide.explorer.propertysheet.PropertyEnv;
047: import org.openide.nodes.Node;
048:
049: /**
050: *This is a clone of the code from org.netbeans.beaninfo.editors.StringCustomEditor. Its the cheezy
051: *way to do it, but since the class was not built to be subclasseable, I cloned it to get same behavior
052: *and hope it reduces risk of regressions.
053: *
054: * @author eric
055: */
056:
057: /** A property editor for String class.
058: * @author Ian Formanek
059: * @version 1.00, 18 Sep, 1998
060: * @deprecated
061: */
062: public class RaveStringEditor extends PropertyEditorSupport implements
063: ExPropertyEditor {
064: private static boolean useRaw = Boolean
065: .getBoolean("netbeans.stringEditor.useRawCharacters");
066:
067: // bugfix# 9219 added editable field and isEditable() "getter" to be used in StringCustomEditor
068: private boolean editable = true;
069:
070: /** gets information if the text in editor should be editable or not */
071: public boolean isEditable() {
072: return (editable);
073: }
074:
075: protected boolean forceOneline() {
076: return false;
077: }
078:
079: // <RAVE> String property editor should be changed to not use "null" to show null values,
080: // but instead show a blank "" string for this.
081: public String getAsText() {
082: if (getValue() == null) {
083: return "";
084: } else {
085: return super .getAsText();
086: }
087: }
088:
089: /** sets new value */
090: public void setAsText(String s) {
091: setValue(s);
092: }
093:
094: public void setValue(Object value) {
095: String s = (String) value;
096: if ("".equals(s) && getValue() == null) { // NOI18N
097: return;
098: }
099: super .setValue(s);
100: }
101:
102: protected void super SetValue(Object value) {
103: super .setValue(value);
104: }
105:
106: public String getJavaInitializationString() {
107: String s = (String) getValue();
108: if (s == null) {
109: return "\"\""; // NOI18N
110: } else {
111: return "\"" + toAscii(s) + "\""; // NOI18N
112: }
113: }
114:
115: // </RAVE>
116:
117: public boolean supportsCustomEditor() {
118: return customEd;
119: }
120:
121: public java.awt.Component getCustomEditor() {
122: return new RaveStringCustomEditor(getAsText(), isEditable(),
123: oneline, instructions, getIgnoreCrs(), this ); // NOI18N
124: }
125:
126: public Object getCustomEditorValue(String string) {
127: return string;
128: }
129:
130: private static String toAscii(String str) {
131: StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234
132: char[] chars = str.toCharArray();
133: for (int i = 0; i < chars.length; i++) {
134: char c = chars[i];
135: switch (c) {
136: case '\b':
137: buf.append("\\b");
138: break; // NOI18N
139: case '\t':
140: buf.append("\\t");
141: break; // NOI18N
142: case '\n':
143: buf.append("\\n");
144: break; // NOI18N
145: case '\f':
146: buf.append("\\f");
147: break; // NOI18N
148: case '\r':
149: buf.append("\\r");
150: break; // NOI18N
151: case '\"':
152: buf.append("\\\"");
153: break; // NOI18N
154: // case '\'': buf.append("\\'"); break; // NOI18N
155: case '\\':
156: buf.append("\\\\");
157: break; // NOI18N
158: default:
159: if (c >= 0x0020 && (useRaw || c <= 0x007f)) {
160: buf.append(c);
161: } else {
162: buf.append("\\u"); // NOI18N
163: String hex = Integer.toHexString(c);
164: for (int j = 0; j < 4 - hex.length(); j++) {
165: buf.append('0');
166: }
167: buf.append(hex);
168: }
169: }
170: }
171: return buf.toString();
172: }
173:
174: // EAT modified - made protected
175: protected String instructions = null;
176: private boolean oneline = false;
177: private boolean customEd = true;
178:
179: // bugfix# 9219 added attachEnv() method checking if the user canWrite in text box
180: public void attachEnv(PropertyEnv env) {
181: FeatureDescriptor desc = env.getFeatureDescriptor();
182: if (desc instanceof Node.Property) {
183: Node.Property prop = (Node.Property) desc;
184: editable = prop.canWrite();
185: //enh 29294 - support one-line editor & suppression of custom editor
186: if (useOriginalShortDescriptionForInstructions()) {
187: instructions = (String) prop
188: .getValue("originalShortDescription"); // NOI18N
189: if (instructions == null) {
190: instructions = prop.getShortDescription();
191: }
192: } else {
193: instructions = (String) prop.getValue("instructions"); //NOI18N
194: }
195: if (forceOneline()) {
196: oneline = true;
197: } else {
198: oneline = Boolean.TRUE.equals(prop.getValue("oneline")); //NOI18N
199: }
200: customEd = !Boolean.TRUE.equals(prop
201: .getValue("suppressCustomEditor")); //NOI18N
202: }
203: }
204:
205: protected boolean useOriginalShortDescriptionForInstructions() {
206: return false;
207: }
208:
209: protected boolean getIgnoreCrs() {
210:
211: return false;
212: }
213: }
|