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.

Bug 40321 - ??? in the generated code setText
Summary: ??? in the generated code setText
Status: RESOLVED WORKSFORME
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 3.x
Hardware: PC Windows ME/2000
: P1 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-20 13:09 UTC by anshu23
Modified: 2004-02-24 13:52 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description anshu23 2004-02-20 13:09:32 UTC
The generated code in the blocked area is 
incorrect

jLabel1.setText(???);

This happens for all setText, even in OK Cancek 
Dialog template.

This cannot be removed also as its uneditable
Comment 1 Tomas Pavek 2004-02-20 13:14:11 UTC
Is it really a sttring-type property? The genrated "???" means that
given property editor does not provide the code (from method
getJavaInitializationString). But StringPropertyEditor certainly does
it. Any more deatils about how to reproduce it?
Comment 2 anshu23 2004-02-20 13:23:01 UTC
just try to set any value for the label text in the property editor 
of the form. you will get this. Only way to remove it seems to be by 
removing any text in the setText propert panel which removes that 
line from the code.
Comment 3 Tomas Pavek 2004-02-20 13:39:30 UTC
No, I get the text normally generated.
What build do you use exactly? And JDK?
Comment 4 Tomas Pavek 2004-02-24 08:55:22 UTC
Cannot reproduce the problem. Not having enough information. Also
nobody else reported similar problem.
Comment 5 anshu23 2004-02-24 13:52:08 UTC
Sorry the problem occured because my module was installing a new 
StringEditorSupport
I was using this in ModuleInstall class restored() method

PropertyEditorManager.registerEditor(String.class, 
StringEditorSupport.class);

This editor support gave an empty string instead of null and the rest 
was same.

Odd that such a thing should affect the Form Editor !?

I am sending you the code:


import java.beans.FeatureDescriptor;
import java.beans.PropertyEditorSupport;

import javax.swing.JPanel;
import javax.swing.JTextField;

import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
import 
org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEdito
r;
import org.openide.nodes.Node;

public class StringEditorSupport
     extends PropertyEditorSupport
     implements ExPropertyEditor
{

    private boolean editable = true;

    private boolean customEd = false;


    /**
     *  Gets the editable attribute of the StringEditorSupport object
     *
     *@return    The editable value
     */
    public boolean isEditable()
    {
        return (editable);
    }


    /**
     *  Gets the asText attribute of the StringEditorSupport object
     *
     *@return    The asText value
     */
    public String getAsText()
    {
        if(getValue() == null)
            return "";
        else
            return escapeString((String) getValue());
    }


    /**
     *  Gets the customEditor attribute of the StringEditorSupport 
object
     *
     *@return    The customEditor value
     */
    public java.awt.Component getCustomEditor()
    {
        Object val = getValue();
        String s = "";
        // NOI18N

        if(val != null)
            s = val.toString();

        return new StringCustomEditor(s, isEditable());
        // NOI18N
    }


    /**
     *  Sets the asText attribute of the StringEditorSupport object
     *
     *@param  text  The new asText value
     */
    public void setAsText(String text)
    {
        if(text == null)
            setValue(null);

        else
            setValue(unescapeString(text));

    }


    /**
     *  Description of the Method
     *
     *@return    Description of the Return Value
     */
    public boolean supportsCustomEditor()
    {
        return customEd;
    }

    // bugfix# 9219 added attachEnv() method checking if the user 
canWrite in text box

    /**
     *  Description of the Method
     *
     *@param  env  Description of the Parameter
     */
    public void attachEnv(PropertyEnv env)
    {
        FeatureDescriptor desc = env.getFeatureDescriptor();

        if(desc instanceof Node.Property)
        {
            Node.Property prop = (Node.Property) desc;

            editable = prop.canWrite();
            //enh 29294 - support one-line editor & suppression of 
custom
            //editor
            customEd = Boolean.FALSE.equals(prop.getValue
                ("suppressCustomEditor"));
            //NOI18N
        }
    }


    //  Escapes the specified string.
    /**
     *  Description of the Method
     *
     *@param  str  Description of the Parameter
     *@return      Description of the Return Value
     */
    public static String escapeString(String str)
    {
        StringBuffer buf = new StringBuffer();

        for(int i = 0; i < str.length(); i++)
        {
            char c = str.charAt(i);

            switch (c)
            {
                case '\n':
                    buf.append("\\n");
                    break;
                case '\t':
                    buf.append("\\t");
                    break;
                case '\r':
                    buf.append("\\r");
                    break;
                case '\\':
                    buf.append("\\\\");
                    break;
                default:
                    buf.append(c);
            }
        }
        return buf.toString();
    }


    /**
     *  Description of the Method
     *
     *@param  str  Description of the Parameter
     *@return      Description of the Return Value
     */
    public static String unescapeString(String str)
    {
        StringBuffer buf = new StringBuffer();

        for(int i = 0; i < str.length(); i++)
        {
            char c = str.charAt(i);

            switch (c)
            {
                case '\\':
                    if(i == str.length() - 1)
                    {
                        buf.append('\\');
                        break;
                    }
                    c = str.charAt(++i);
                    switch (c)
                    {
                        case 'n':
                            buf.append('\n');
                            break;
                        case 't':
                            buf.append('\t');
                            break;
                        case 'r':
                            buf.append('\r');
                            break;
                        default:
                            buf.append(c);
                            break;
                    }
                    break;
                default:
                    buf.append(c);
            }
        }
        return buf.toString();
    }
}

/**
 *  Description of the Class
 *
 *@author     Anshuman Das
 *@created    February 9, 2004
 */
class StringCustomEditor
     extends javax.swing.JPanel
     implements EnhancedCustomPropertyEditor
{


    // Variables declaration - do not modify
    private javax.swing.JScrollPane textAreaScroll;
    private javax.swing.JTextArea textArea;


    /**
     *  Initializes the Form
     *
     *@param  s         Description of the Parameter
     *@param  editable  Description of the Parameter
     */
    public StringCustomEditor(String s, boolean editable)
    {
        initComponents();

        textArea.setEditable(editable);
        textArea.setText(s);
        textArea.setWrapStyleWord(true);
        textArea.setLineWrap(true);
        setBorder(new javax.swing.border.EmptyBorder(new 
java.awt.Insets(12, 12, 0, 11)));
        setPreferredSize(new java.awt.Dimension(500, 300));

        if(!editable)
        {
            // hack to fix #9219
            JTextField hack = new JTextField();

            hack.setEditable(false);
            textArea.setBackground(hack.getBackground());
            textArea.setForeground(hack.getForeground());
        }
    }


    /**
     *@return                            Returns the property value 
that is
     *      result of the CustomPropertyEditor.
     *@exception  IllegalStateException  Description of the Exception
     */
    public Object getPropertyValue()
         throws IllegalStateException
    {
        return textArea.getText();
    }


    /**
     *  This method is called from within the constructor to 
initialize the
     *  form. WARNING: Do NOT modify this code. The content of this 
method is
     *  always regenerated by the FormEditor.
     */
    private void initComponents()
    {
        setLayout(new java.awt.BorderLayout());

        textAreaScroll = new javax.swing.JScrollPane();

        textArea = new javax.swing.JTextArea();

        textAreaScroll.setViewportView(textArea);

        add(textAreaScroll, "Center");
        // NOI18N

    }


    final static long serialVersionUID = 7348579663907322425L;
    // End of variables declaration

}