Share via


PropertyInfo Class

Methods | This Package | All Packages

Defines a property of a component. 

MemberInfo
  |
  +--PropertyInfo

package com.ms.wfc.core

public class PropertyInfo
extends
MemberInfo****

Remarks

Properties allow you to set up the state of the component. The PropertyInfo class is used within the component's ClassInfo inner class. When you create a PropertyInfo object, you specify the component class, the name and type of the property, and the various attributes of the property. (Attributes can be specified using the classes that extend MemberAttribute.)

The following example shows a portion of the ClassInfo of the Control class:

public static class ClassInfo extends Component.ClassInfo {
   public static final PropertyInfo allowDrop = new PropertyInfo(
      Control.class, "allowDrop", boolean.class,
      CategoryAttribute.Behavior,
      DefaultValueAttribute.FALSE,
      new DescriptionAttribute(
    "Indicates whether the control receives drag drop notifications.")));

   public static final PropertyInfo anchor = new PropertyInfo(
      Control.class, "anchor", int.class,
      CategoryAttribute.Position,
      new ValueEditorAttribute(AnchorEditor.class),
      new DefaultValueAttribute(new Integer(ControlAnchor.TOP | ControlAnchor.LEFT)),
      new DescriptionAttribute("Specifies the anchor of the control."));

   public static final PropertyInfo backColor = new PropertyInfo(
      Control.class, "backColor", Color.class,
      CategoryAttribute.Appearance,
      new DescriptionAttribute("Specifies the background color."));

   public void getProperties(IProperties props) {
      super.getProperties(props);
      props.add(allowDrop);
      props.add(anchor);
      props.add(backColor);
   }
}

For a read-only property defined through PropertyInfo, the component class must implement the following method, which allows the property's value to be returned:

public <propertyType> get<PropertyName>()

For a read/write property, the component class must implement get<PropertyName> as well as the following method to set the property value:

public void set<PropertyName>( <propertyType>****value )

Note   A property name typically begins with a lowercase letter, while the case of the associated methods is mixed. For example, a read/write property named backColor is associated with getBackColor and setBackColor methods.

In addition to the get<PropertyName> and set<PropertyName> methods, the component class can optionally implement the following two methods:

public boolean shouldPersist<PropertyName>()

public void reset<PropertyName>()

These methods involve the property's default value, which is specified using DefaultValueAttribute. The shouldPersist<PropertyName> method returns true if the current value of the property is different than its default value, indicating that the value should be persisted. The reset<PropertyName> method resets the property to its default value.

If the PropertyInfo definition specifies a value editor (using ValueEditorAttribute), this value editor is used to edit the property. Otherwise, a system-provided value editor is used.

A PropertyInfo object can be obtained programmatically through the ComponentManager class.

See Also   EventInfo, ExtenderInfo, Attribute Classes