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.property;
042:
043: import java.beans.PropertyEditorSupport;
044: import com.sun.rave.designtime.DesignProject;
045: import com.sun.rave.designtime.DesignProperty;
046: import com.sun.rave.designtime.PropertyEditor2;
047:
048: /**
049: * @author eric
050: *
051: * @deprecated
052: */
053: public abstract class AbstractPropertyEditor extends
054: PropertyEditorSupport implements PropertyEditor2 {
055: protected DesignProperty liveProperty;
056:
057: public static Class getClassNamed(String name) {
058: try {
059: return Class.forName(name);
060: } catch (ClassNotFoundException e) {
061: return null;
062: }
063: }
064:
065: /**
066: * Convert a string into a string that can be directly inserted into java source.
067: * @param str
068: * @return
069: */
070: public static String stringToJavaSourceString(String str) {
071: StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234
072: buf.append("\""); //NOI18N
073: char[] chars = str.toCharArray();
074: for (int i = 0; i < chars.length; i++) {
075: char c = chars[i];
076: switch (c) {
077: case '\b':
078: buf.append("\\b");
079: break; // NOI18N
080: case '\t':
081: buf.append("\\t");
082: break; // NOI18N
083: case '\n':
084: buf.append("\\n");
085: break; // NOI18N
086: case '\f':
087: buf.append("\\f");
088: break; // NOI18N
089: case '\r':
090: buf.append("\\r");
091: break; // NOI18N
092: case '\"':
093: buf.append("\\\"");
094: break; // NOI18N
095: // case '\'': buf.append("\\'"); break; // NOI18N
096: case '\\':
097: buf.append("\\\\");
098: break; // NOI18N
099: default:
100: if (c >= 0x0020 && c <= 0x007f) {
101: buf.append(c);
102: } else {
103: buf.append("\\u"); // NOI18N
104: String hex = Integer.toHexString(c);
105: for (int j = 0; j < 4 - hex.length(); j++) {
106: buf.append('0');
107: }
108: buf.append(hex);
109: }
110: }
111: }
112: buf.append("\""); // NOI18N
113: return buf.toString();
114: }
115:
116: public void attachToNewDesignProperty() {
117: }
118:
119: public DesignProperty getDesignProperty() {
120: return liveProperty;
121: }
122:
123: public DesignProject getProject() {
124: return getDesignProperty().getDesignBean().getDesignContext()
125: .getProject();
126: }
127:
128: /* (non-Javadoc)
129: * @see com.sun.rave.designtime.PropertyEditor2#setDesignProperty(com.sun.rave.designtime.DesignProperty)
130: */
131: public void setDesignProperty(DesignProperty prop) {
132: liveProperty = prop;
133: attachToNewDesignProperty();
134: }
135:
136: protected void unsetProperty() {
137: //!CQ AAAAKKK!!!! NEVER try to mutate the liveProperty!!!
138: //getDesignProperty().unset();
139: }
140: }
|