NeatTools


PROPERTIES

Properties are user setable attributes of a module.

The "readContent" and "writeContent" are used for reading and writing properties associated with an object. Implementing these methods is all that is necessary for saving property settings for a module in a neattools application.

There "getProperties" and "updateProperty" methods are used to provide There "getProperties" and "updateProperty" methods are used to provide support for user editing of properties.

NOTE: in the examples below, I'm assuming JMyModuleObj is derived from JModuleObj. If your module is derived from some other module, for example, JAnotherModuleObj, then replace "JModuleObj" in the examples below with "JAnotherModuleObj".

READCONTENT and WRITECONTENT

The readContent and writeContent methods follow this pattern:

void JMyModuleObj::writeContent(JOutputStream& os) {
  JModuleObj::writeContent(os);
  // custom property writing of JMyModuleObj support goes here...
}
void JMyModuleObj::readContent(JDictionary& dict) {
  JModuleObj::readContent(dict);
  // custom property reading of JMyModuleObj support goes here...
}

Here is examples for four different data types:

Integer properties:

  //implementation in ".h" file:
  int myIntProperty;
  
  //implementation in "writeContent":
  putInteger( os, "myIntProperty", myIntProperty );
  
  //implementation in "readContent":
  myIntProperty = getInteger(dict, "myIntProperty");
  
  //implementation in "readContent":
  myIntProperty = getInteger(dict, "myIntProperty");

Double properties:

  //implementation in ".h" file:
  double myDoubleProperty;
  
  //implementation in "writeContent":
  putDouble(os, "myDoubleProperty", myDoubleProperty);
  
  //implementation in "readContent":
  myDoubleProperty = getDouble(dict, "myDoubleProperty");

Object properties, not clear how many are supported, looks like pretty much anything derived from JObject should work, so that would mean any data type in Yuh-Jye's "JAVA Like Cross Platform C+++ API".

Here is how it is coded for JColor and JString, but it looks the same for any JObject.

JColor property:

	//implementation in ".h" file:
	JColor myColor;
	
	//implementation in "writeContent":
	putObject(os, "myColor", myColor);
	
	//implementation in "readContent":
  	JObject* obj = getObject(dict, "myColor");
  	if (obj) myColor = *(JColor*)obj;

JString property:

  	//implementation in ".h" file:  
	JString myString;
  	
   //implementation in "writeContent":  
	putObject(os, "myString",  myString);
  	
	//implementation in "readContent":
  	JObject* obj = getObject(dict, "myString");
  	if (obj) myString = *(JString*)obj;
  	if (obj) myString = *(JString*)obj;

GETPROPERTIES and UPDATEPROPERTIES

The "getProperties" method follows this pattern:

  
  
 	JArray JMyModuleObj::getProperties() {
 	JArray properties = JModuleObj::getProperties();
  
  // custom property additions go here
  
  // must always have this...
  return properties;
  }
  

The "updateProperty" method follows this pattern:

  
  boolean JMyModuleObj::updateProperty(JProperty& prop) {
  
  boolean JMyModuleObj::updateProperty(JProperty& prop) {
  if (JModuleObj::updateProperty(prop)) return true;
  
  // custom property additions go here
  
  // must always have this...
  return false;
  }

The custom property additions are added based on type:

Integer properties:

  //implementation in ".h" file:
  int myIntProperty;
  
  //implementation in "getProperties", where "minValue" and "maxValue" are ints:
  properties.append(JIntegerProperty( "myIntProperty", myIntProperty, minValue, maxValue ))
  
  //implementation in "updateProperty":
  if (prop.getName() == JString("myIntProperty")){
  myIntProperty = ((JIntegerProperty*)&prop)->value;
  return true;
  }

Boolean properties (this looks a bit weird, so there might be a better way to do this, but this is how I did it...):

  //implementation in ".h" file:
  int myBoolProperty;
  
	//implementation in "getProperties":
  	properties.append(JIntegerListProperty( "myBoolProperty", myBoolProperty, JIntegerListProperty::booleanTag));
  
  //implementation in "updateProperty":
  if (prop.getName() == JString("myBoolProperty")) {
  myBoolProperty = ((JIntegerProperty*)&prop)->value;
  return true;
  }

JColor properties:

  //implementation in ".h" file:
  JColor myColorProperty;
    
  //implementation in "getProperties":
  properties.append(JColorProperty("myColorProperty", myColorProperty));
  
  //implementation in "updateProperty":
  if (prop.getName() == JString("myColorProperty")) {
  color = ((JColorProperty*)&prop)->value;
  return true;
  }
  

JString properties:

  //implemetation in ".h" file:
  JString myStringProperty;
  
  //implementation in "getProperties":
  properties.append(JStringProperty("myStringProperty", myStringProperty));
  
  //implementation in "updateProperty":
  if (prop.getName() == JString("myStringProperty")) {
  //implementation in "updateProperty":
  if (prop.getName() == JString("myStringProperty")) {
  myStringProperty = ((JStringProperty*)&prop)->value;
  return true;
  }

Additional technique which might come in handy: If you need to generate prompts or variable names on-the-fly for any of the methods above, the strings in double quotes are actually JString objects. So for example, if you need to have variables named xx0 through xx9 for saving an array "xx[]" of values in "writeContent", those names can be generated like this:

  for ( int i = 0; i < 10; i++ ) {
    putInteger(os, JString( "xx" ) + JInteger::toJString( xx[i] ), xx[i]
);
  }