Index: core/src/org/netbeans/beaninfo/editors/IntEditor.java
===================================================================
RCS file: core/src/org/netbeans/beaninfo/editors/IntEditor.java
diff -N core/src/org/netbeans/beaninfo/editors/IntEditor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ core/src/org/netbeans/beaninfo/editors/IntEditor.java 28 Feb 2003 17:30:42 -0000
@@ -0,0 +1,95 @@
+/*
+ * IntEditor.java
+ *
+ * Created on February 28, 2003, 2:15 PM
+ */
+
+package org.netbeans.beaninfo.editors;
+import java.beans.*;
+import org.openide.explorer.propertysheet.ExPropertyEditor;
+import org.openide.util.NbBundle;
+import java.util.Arrays;
+/** An editor for primitive integer types which allows hinting of tag
+ * values and handles whitespace in setAsText better than the default
+ * one. Hints may be supplied by the standard method of returning them
+ * from getValue() on the feature descriptor supplied by the PropertyEnv.
+ * To use hinting, return a String[] from getValue ("stringKeys")
+ * and an int[] from getValue ("intKeyValues"). These two
+ * arrays must have the same number of entries and the number of entries
+ * must be at least 1. Key matching in setAsText is case sensitive.
+ *
+ * @author Tim Boudreau
+ */
+public class IntEditor extends PropertyEditorSupport implements
+ ExPropertyEditor {
+ String[] keys=null;
+ int[] values=null;
+ /** Creates a new instance of IntEditor */
+ public IntEditor() {
+ }
+
+ public void attachEnv(org.openide.explorer.propertysheet.PropertyEnv env) {
+ keys = (String[]) env.getFeatureDescriptor().getValue(
+ "stringKeys"); //NOI18N
+ values = (int[]) env.getFeatureDescriptor().getValue(
+ "intKeyValues"); //NOI18N
+ }
+
+ public String[] getKeys () {
+ return keys;
+ }
+
+ private String getStringRep (int i) {
+ if (keys != null) {
+ try {
+ return keys[i];
+ } catch (ArrayIndexOutOfBoundsException ae) {
+ throw new IllegalArgumentException (
+ "This property editor uses a set of keyed values, " + //NOI18N
+ "and the value " //NOI18N
+ + i + " is out of range."); //NOI18N
+ }
+ } else {
+ return Integer.toString(i);
+ }
+ }
+
+ public String getAsText() {
+ return getStringRep (((Integer) getValue()).intValue());
+ }
+
+ public void setAsText(String s) {
+ s = s.trim();
+ if (keys == null) {
+ //standard int handling
+ setValue (new Integer (Integer.parseInt (s)));
+ } else {
+ //use the keys
+ int idx = Arrays.asList (keys).indexOf(s);
+ if ((idx == -1) || (idx > values.length-1)) {
+ StringBuffer sb = new StringBuffer (40);
+ //if something goes wrong, give a clue what it was
+ sb.append ("Illegal value: \"" + s + "\" - valid values are: "); //NOI18N
+ for (int i=0; i < keys.length; i ++) {
+ sb.append (keys[i]);
+ if (i != keys.length - 1) {
+ sb.append (','); //NOI18N
+ }
+ }
+ throw new IllegalArgumentException
+ (sb.toString()); //NOI18N
+ } else {
+ setValue (new Integer (values[idx]));
+ }
+ }
+ }
+
+ public String[] getTags () {
+ return keys;
+ }
+
+ public String getJavaInitializationString() {
+ return getValue().toString();
+ }
+
+}
Index: core/src/org/netbeans/beaninfo/editors/BoolEditor.java
===================================================================
RCS file: core/src/org/netbeans/beaninfo/editors/BoolEditor.java
diff -N core/src/org/netbeans/beaninfo/editors/BoolEditor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ core/src/org/netbeans/beaninfo/editors/BoolEditor.java 28 Feb 2003 17:30:42 -0000
@@ -0,0 +1,95 @@
+/*
+ * BoolEditor.java
+ *
+ * Created on February 28, 2003, 1:13 PM
+ */
+
+package org.netbeans.beaninfo.editors;
+import java.beans.*;
+import org.openide.explorer.propertysheet.ExPropertyEditor;
+import org.openide.util.NbBundle;
+/** Replacement editor for boolean primitive values which supports
+ * internationalization and alternate string values that
+ * can be supplied to the property editor via adding an array
+ * returning an array of two Strings (false then true) from
+ * env.getFeatureDescriptor().getValue()
. These
+ * string values will then be used for getAsText, setAsText, and getTags.
+ * These strings should be correctly internationalized if supplied
+ * by a module. String value matching in setAsText is non-case-sensitive
+ * ("TRUE" and "tRue" are equivalent).
+ *
+ * @author Tim Boudreau
+ */
+public class BoolEditor extends PropertyEditorSupport implements ExPropertyEditor {
+ String[] stringValues = null;
+ /** Creates a new instance of BoolEditor */
+ public BoolEditor() {
+ }
+
+ public void attachEnv(org.openide.explorer.propertysheet.PropertyEnv env) {
+ stringValues = (String[]) env.getFeatureDescriptor().getValue(
+ "stringValues"); //NOI18N
+ }
+
+ private String getStringRep (boolean val) {
+ if (stringValues != null) {
+ return stringValues [val ? 0 : 1];
+ }
+ String result;
+ if (val) {
+ result = NbBundle.getMessage(BoolEditor.class, "TRUE"); //NOI18N
+ } else {
+ result = NbBundle.getMessage(BoolEditor.class, "FALSE"); //NOI18N
+ }
+ return result;
+ }
+
+ /** Returns Boolean.TRUE, Boolean.FALSE or null in the case of an
+ * unrecognized string. */
+ private Boolean stringVal (String val) {
+ String valToTest = val.trim().toUpperCase();
+ String test = getStringRep (true).toUpperCase();
+ if (test.equals(valToTest)) return Boolean.TRUE;
+ test = getStringRep (false).toUpperCase();
+ if (test.equals(valToTest)) return Boolean.FALSE;
+ return null;
+ }
+
+ public String getJavaInitializationString() {
+ Boolean val = (Boolean) getValue();
+ if (val == null) return "null"; //NOI18N
+ return Boolean.TRUE.equals (getValue()) ? "true" : "false"; //NOI18N
+ }
+
+ public String[] getTags () {
+ return new String[] {
+ getStringRep (true), getStringRep (false)
+ };
+ }
+
+ public String getAsText() {
+ Boolean val = (Boolean) getValue();
+ if (val == null) return NbBundle.getMessage (BoolEditor.class, "NULL");
+ return getStringRep (Boolean.TRUE.equals (getValue()));
+ }
+
+ public void setAsText(String txt) {
+ Boolean val = stringVal (txt);
+ boolean newVal = val == null ? false : val.booleanValue();
+ setValue (newVal ? Boolean.TRUE : Boolean.FALSE);
+ }
+
+ static BoolEditor ed = new BoolEditor();
+ public static void main (String[] args) {
+ Boolean val = Boolean.TRUE;
+ ed.setValue (val);
+ checkValue (val.booleanValue());
+ val = Boolean.FALSE;
+ ed.setValue (val);
+ checkValue (val.booleanValue());
+ }
+
+ public static boolean checkValue (boolean val) {
+ return val == ((Boolean) ed.getValue()).booleanValue();
+ }
+}
Index: core/src/org/netbeans/beaninfo/editors/WrappersEditor.java
===================================================================
RCS file: /cvs/core/src/org/netbeans/beaninfo/editors/WrappersEditor.java,v
retrieving revision 1.3
diff -u -r1.3 WrappersEditor.java
--- core/src/org/netbeans/beaninfo/editors/WrappersEditor.java 6 Feb 2002 10:07:38 -0000 1.3
+++ core/src/org/netbeans/beaninfo/editors/WrappersEditor.java 28 Feb 2003 17:30:42 -0000
@@ -14,14 +14,15 @@
package org.netbeans.beaninfo.editors;
import java.beans.*;
-
+import org.openide.explorer.propertysheet.ExPropertyEditor;
+import org.openide.explorer.propertysheet.PropertyEnv;
/**
* Abstract class represents Editor for Wrappers of 8 known primitive types
* (Byte, Short, Integer, Long, Boolean, Float, Double, Character)
*
* @author Josef Kozak
*/
-public abstract class WrappersEditor implements PropertyEditor {
+public abstract class WrappersEditor implements ExPropertyEditor {
private PropertyEditor pe = null;
@@ -189,5 +190,12 @@
* current value.
*/
public abstract String getJavaInitializationString();
-
+
+ public void attachEnv(PropertyEnv env) {
+ //Delegate if the primitive editor is an ExPropertyEditor -
+ //new boolean and int editors will be
+ if (pe instanceof ExPropertyEditor) {
+ ((ExPropertyEditor) pe).attachEnv (env);
+ }
+ }
}
Index: core/src/org/netbeans/core/NonGui.java
===================================================================
RCS file: /cvs/core/src/org/netbeans/core/NonGui.java,v
retrieving revision 1.95
diff -u -r1.95 NonGui.java
--- core/src/org/netbeans/core/NonGui.java 20 Feb 2003 04:53:36 -0000 1.95
+++ core/src/org/netbeans/core/NonGui.java 28 Feb 2003 17:30:42 -0000
@@ -356,6 +356,10 @@
PropertyEditorManager.registerEditor(getKlass("[Ljava.lang.String;"), getKlass("org.netbeans.beaninfo.editors.StringArrayEditor")); // NOI18N
// bugfix #28676, register editor for a property which type is array of data objects
PropertyEditorManager.registerEditor(getKlass("[Lorg.openide.loaders.DataObject;"), getKlass("org.netbeans.beaninfo.editors.DataObjectArrayEditor")); // NOI18N
+ PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
+ PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
+
+
StartLog.logProgress ("PropertyEditors registered"); // NOI18N
// -----------------------------------------------------------------------------------------------------
Index: openide/api/doc/org/openide/explorer/doc-files/api.html
===================================================================
RCS file: /cvs/openide/api/doc/org/openide/explorer/doc-files/api.html,v
retrieving revision 1.32
diff -u -r1.32 api.html
--- openide/api/doc/org/openide/explorer/doc-files/api.html 26 Feb 2003 06:09:40 -0000 1.32
+++ openide/api/doc/org/openide/explorer/doc-files/api.html 28 Feb 2003 17:30:42 -0000
@@ -742,6 +742,29 @@
intKeyValues
must also be supplied
+ new String[] {"off","on"}
.