/** * Returns a fragment of Java code that can be used to set a property to match the editors current * state. This method is intended for use when generating Java code to reflect changes made * through the property editor. * * <p>The code fragment should be context free and must be a legal Java expression as specified by * the JLS. * * <p>Specifically, if the expression represents a computation then all classes and static members * should be fully qualified. This rule applies to constructors, static methods and non primitive * arguments. * * <p>Caution should be used when evaluating the expression as it may throw exceptions. In * particular, code generators must ensure that generated code will compile in the presence of an * expression that can throw checked exceptions. * * <p>Example results are: * * <ul> * <li>Primitive expresssion: <code>2</code> * <li>Class constructor: <code>new * java.awt.Color(127,127,34)</code> * <li>Static field: <code>java.awt.Color.orange</code> * <li>Static method: <code>javax.swing.Box.createRigidArea(new java.awt.Dimension(0, 5))</code> * </ul> * * @return a fragment of Java code representing an initializer for the current value. It should * not contain a semi-colon ('<code>;</code>') to end the expression. */ public String getJavaInitializationString() { if (BoxSizing.BORDER_BOX.equals(value)) { return BoxSizing.class.getName() + ".BORDER_BOX"; } else if (BoxSizing.CONTENT_BOX.equals(value)) { return BoxSizing.class.getName() + ".CONTENT_BOX"; } else { return "null"; } }
/** * Set (or change) the object that is to be edited. Primitive types such as "int" must be wrapped * as the corresponding object type such as "java.lang.Integer". * * @param value The new target object to be edited. Note that this object should not be modified * by the PropertyEditor, rather the PropertyEditor should create a new object to hold any * modified value. */ public void setValue(final Object value) { final Object oldValue = this.value; if (BoxSizing.BORDER_BOX.equals(value)) { this.value = BoxSizing.BORDER_BOX; } else if (BoxSizing.CONTENT_BOX.equals(value)) { this.value = BoxSizing.CONTENT_BOX; } else { this.value = null; } propertyChangeSupport.firePropertyChange(null, oldValue, this.value); }
/** * If the property value must be one of a set of known tagged values, then this method should * return an array of the tags. This can be used to represent (for example) enum values. If a * PropertyEditor supports tags, then it should support the use of setAsText with a tag value as a * way of setting the value and the use of getAsText to identify the current value. * * @return The tag values for this property. May be null if this property cannot be represented as * a tagged value. */ public String[] getTags() { return new String[] { BoxSizing.BORDER_BOX.toString(), BoxSizing.CONTENT_BOX.toString(), }; }