This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 20736
Collapse All | Expand All

(-)core/src/org/netbeans/beaninfo/editors/IntEditor.java (+95 lines)
Added Link Here
1
/*
2
 * IntEditor.java
3
 *
4
 * Created on February 28, 2003, 2:15 PM
5
 */
6
7
package org.netbeans.beaninfo.editors;
8
import java.beans.*;
9
import org.openide.explorer.propertysheet.ExPropertyEditor;
10
import org.openide.util.NbBundle;
11
import java.util.Arrays;
12
/** An editor for primitive integer types which allows hinting of tag
13
 *  values and handles whitespace in setAsText better than the default
14
 *  one.  Hints may be supplied by the standard method of returning them
15
 *  from getValue() on the feature descriptor supplied by the PropertyEnv.
16
 *  To use hinting, return a String[] from getValue ("stringKeys")
17
 *  and an int[] from getValue ("intKeyValues").  These two
18
 *  arrays must have the same number of entries and the number of entries
19
 *  must be at least 1.  Key matching in setAsText is case sensitive.
20
 *
21
 * @author  Tim Boudreau
22
 */
23
public class IntEditor extends PropertyEditorSupport implements 
24
    ExPropertyEditor {
25
    String[] keys=null;
26
    int[] values=null;
27
    /** Creates a new instance of IntEditor */
28
    public IntEditor() {
29
    }
30
    
31
    public void attachEnv(org.openide.explorer.propertysheet.PropertyEnv env) {
32
        keys = (String[]) env.getFeatureDescriptor().getValue(
33
            "stringKeys"); //NOI18N
34
        values = (int[]) env.getFeatureDescriptor().getValue(
35
            "intKeyValues"); //NOI18N
36
    }
37
    
38
    public String[] getKeys () {
39
        return keys;
40
    }
41
    
42
    private String getStringRep (int i) {
43
        if (keys != null) {
44
            try {
45
                return keys[i];
46
            } catch (ArrayIndexOutOfBoundsException ae) {
47
                throw new IllegalArgumentException (
48
                    "This property editor uses a set of keyed values, " +  //NOI18N
49
                    "and the value " //NOI18N
50
                    + i + " is out of range."); //NOI18N
51
            }
52
        } else {
53
            return Integer.toString(i);
54
        }
55
    }
56
    
57
    public String getAsText() {
58
        return getStringRep (((Integer) getValue()).intValue());
59
    }
60
    
61
    public void setAsText(String s) {
62
        s = s.trim();
63
        if (keys == null) {
64
            //standard int handling
65
            setValue (new Integer (Integer.parseInt (s)));
66
        } else {
67
            //use the keys
68
            int idx = Arrays.asList (keys).indexOf(s);
69
            if ((idx == -1) || (idx > values.length-1)) {
70
                StringBuffer sb = new StringBuffer (40);
71
                //if something goes wrong, give a clue what it was
72
                sb.append ("Illegal value: \"" + s + "\" - valid values are: "); //NOI18N
73
                for (int i=0; i < keys.length; i ++) {
74
                    sb.append (keys[i]);
75
                    if (i != keys.length - 1) {
76
                        sb.append (','); //NOI18N
77
                    }
78
                }
79
                throw new IllegalArgumentException 
80
                    (sb.toString()); //NOI18N
81
            } else {
82
                setValue (new Integer (values[idx]));
83
            }
84
        }
85
    }
86
    
87
    public String[] getTags () {
88
        return keys;
89
    }
90
    
91
    public String getJavaInitializationString() {
92
        return getValue().toString();
93
    }
94
    
95
}
(-)core/src/org/netbeans/beaninfo/editors/BoolEditor.java (+95 lines)
Added Link Here
1
/*
2
 * BoolEditor.java
3
 *
4
 * Created on February 28, 2003, 1:13 PM
5
 */
6
7
package org.netbeans.beaninfo.editors;
8
import java.beans.*;
9
import org.openide.explorer.propertysheet.ExPropertyEditor;
10
import org.openide.util.NbBundle;
11
/** Replacement editor for boolean primitive values which supports 
12
 *  internationalization and alternate string values that
13
 *  can be supplied to the property editor via adding an array
14
 *  returning an array of two Strings (false then true) from
15
 *  <code>env.getFeatureDescriptor().getValue()</code>.  These
16
 *  string values will then be used for getAsText, setAsText, and getTags.
17
 *  These strings should be correctly internationalized if supplied
18
 *  by a module.  String value matching in setAsText is non-case-sensitive
19
 *  ("TRUE" and "tRue" are equivalent).
20
 *
21
 * @author  Tim Boudreau
22
 */
23
public class BoolEditor extends PropertyEditorSupport implements ExPropertyEditor {
24
    String[] stringValues = null;
25
    /** Creates a new instance of BoolEditor */
26
    public BoolEditor() {
27
    }
28
    
29
    public void attachEnv(org.openide.explorer.propertysheet.PropertyEnv env) {
30
        stringValues = (String[]) env.getFeatureDescriptor().getValue(
31
            "stringValues"); //NOI18N
32
    }
33
    
34
    private String getStringRep (boolean val) {
35
        if (stringValues != null) {
36
            return stringValues [val ? 0 : 1];
37
        }
38
        String result;
39
        if (val) {
40
            result = NbBundle.getMessage(BoolEditor.class, "TRUE"); //NOI18N
41
        } else {
42
            result = NbBundle.getMessage(BoolEditor.class, "FALSE"); //NOI18N
43
        }
44
        return result;
45
    }
46
    
47
    /** Returns Boolean.TRUE, Boolean.FALSE or null in the case of an
48
     *  unrecognized string. */
49
    private Boolean stringVal (String val) {
50
        String valToTest = val.trim().toUpperCase();
51
        String test = getStringRep (true).toUpperCase();
52
        if (test.equals(valToTest)) return Boolean.TRUE;
53
        test = getStringRep (false).toUpperCase();
54
        if (test.equals(valToTest)) return Boolean.FALSE;
55
        return null;
56
    }
57
58
    public String getJavaInitializationString() {
59
        Boolean val = (Boolean) getValue();
60
        if (val == null) return "null"; //NOI18N
61
        return Boolean.TRUE.equals (getValue()) ? "true" : "false"; //NOI18N
62
    }
63
    
64
    public String[] getTags () {
65
        return new String[] {
66
            getStringRep (true), getStringRep (false)
67
        };
68
    }
69
    
70
    public String getAsText() {
71
        Boolean val = (Boolean) getValue();
72
        if (val == null) return NbBundle.getMessage (BoolEditor.class, "NULL");
73
        return getStringRep (Boolean.TRUE.equals (getValue()));
74
    }
75
    
76
    public void setAsText(String txt) {
77
        Boolean val = stringVal (txt);
78
        boolean newVal = val == null ? false : val.booleanValue();
79
        setValue (newVal ? Boolean.TRUE : Boolean.FALSE);
80
    }
81
    
82
    static BoolEditor ed = new BoolEditor();
83
    public static void main (String[] args) {
84
        Boolean val = Boolean.TRUE;
85
        ed.setValue (val);
86
        checkValue (val.booleanValue());
87
        val = Boolean.FALSE;
88
        ed.setValue (val);
89
        checkValue (val.booleanValue());
90
    }
91
    
92
    public static boolean checkValue (boolean val) {
93
        return val == ((Boolean) ed.getValue()).booleanValue();
94
    }
95
}
(-)core/src/org/netbeans/beaninfo/editors/WrappersEditor.java (-3 / +11 lines)
Lines 14-27 Link Here
14
package org.netbeans.beaninfo.editors;
14
package org.netbeans.beaninfo.editors;
15
15
16
import java.beans.*;
16
import java.beans.*;
17
17
import org.openide.explorer.propertysheet.ExPropertyEditor;
18
import org.openide.explorer.propertysheet.PropertyEnv;
18
/**
19
/**
19
 * Abstract class represents Editor for Wrappers of 8 known primitive types
20
 * Abstract class represents Editor for Wrappers of 8 known primitive types
20
 * (Byte, Short, Integer, Long, Boolean, Float, Double, Character)
21
 * (Byte, Short, Integer, Long, Boolean, Float, Double, Character)
21
 *
22
 *
22
 * @author  Josef Kozak
23
 * @author  Josef Kozak
23
 */
24
 */
24
public abstract class WrappersEditor implements PropertyEditor {
25
public abstract class WrappersEditor implements ExPropertyEditor {
25
    
26
    
26
    private PropertyEditor pe = null;
27
    private PropertyEditor pe = null;
27
    
28
    
Lines 189-193 Link Here
189
     *   	current value.
190
     *   	current value.
190
     */    
191
     */    
191
    public abstract String getJavaInitializationString();
192
    public abstract String getJavaInitializationString();
192
    
193
194
    public void attachEnv(PropertyEnv env) {
195
        //Delegate if the primitive editor is an ExPropertyEditor -
196
        //new boolean and int editors will be
197
        if (pe instanceof ExPropertyEditor) {
198
            ((ExPropertyEditor) pe).attachEnv (env);
199
        }
200
    }
193
}
201
}
(-)core/src/org/netbeans/core/NonGui.java (+4 lines)
Lines 356-361 Link Here
356
        PropertyEditorManager.registerEditor(getKlass("[Ljava.lang.String;"), getKlass("org.netbeans.beaninfo.editors.StringArrayEditor")); // NOI18N
356
        PropertyEditorManager.registerEditor(getKlass("[Ljava.lang.String;"), getKlass("org.netbeans.beaninfo.editors.StringArrayEditor")); // NOI18N
357
        // bugfix #28676, register editor for a property which type is array of data objects
357
        // bugfix #28676, register editor for a property which type is array of data objects
358
        PropertyEditorManager.registerEditor(getKlass("[Lorg.openide.loaders.DataObject;"), getKlass("org.netbeans.beaninfo.editors.DataObjectArrayEditor")); // NOI18N
358
        PropertyEditorManager.registerEditor(getKlass("[Lorg.openide.loaders.DataObject;"), getKlass("org.netbeans.beaninfo.editors.DataObjectArrayEditor")); // NOI18N
359
        PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
360
        PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
361
        
362
        
359
        StartLog.logProgress ("PropertyEditors registered"); // NOI18N
363
        StartLog.logProgress ("PropertyEditors registered"); // NOI18N
360
364
361
        // -----------------------------------------------------------------------------------------------------
365
        // -----------------------------------------------------------------------------------------------------
(-)openide/api/doc/org/openide/explorer/doc-files/api.html (+23 lines)
Lines 742-747 Link Here
742
            <TD> org.openide.util.Lookup </TD>
742
            <TD> org.openide.util.Lookup </TD>
743
            <TD> A lookup to use to query for results.</TD>
743
            <TD> A lookup to use to query for results.</TD>
744
        </TR>
744
        </TR>
745
	<TR>
746
	    <TD rowspan='2'> java.lang.Integer </TD>
747
            <TD>stringKeys</TD>
748
            <TD>String[]</TD>
749
            <TD> Should contain internationalized strings that should be used as tags in
750
                 a combo box.  Number of elements must be >= 1.  If this hint is 
751
                 supplied, the hint <code>intKeyValues</code> must also be supplied
752
            </TD>
753
        </TR>
754
        <TR>
755
            <TD>intKeyValues</TD>
756
            <TD> int[] </TD>
757
            <TD> The values the string keys correspond to. Must have the same number
758
                 of elements as the string array </TD>
759
        </TR>
760
        <TR>
761
           <TD> java.lang.Boolean </TD>
762
           <TD> stringvalues </TD>
763
           <TD> String[] </TD>
764
           <TD> Should contain an array of two strings to be used for user
765
                displayable text for the boolean values, in the order
766
                false, true - for example, <code>new String[] {"off","on"}</code>.</TD
767
        </TR>
745
    </TABLE>
768
    </TABLE>
746
769
747
<H4> Custom parameters that are not tied with particular editor </H4>
770
<H4> Custom parameters that are not tied with particular editor </H4>

Return to bug 20736