use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method setCpropValueFromWidget.
// /**
// * Gets all the property widgets used by this widget.
// */
// private LabeledComponentBase[] collectWidgets() {
// LabeledComponentBase[] widgets;
// Component[] allWidgets = myPanel.getWidgets();
// if (allWidgets.length > 1) {
// // return all widgets except for the first, which is
// // the composite property type selector
// widgets = new LabeledComponentBase[allWidgets.length-1];
// for (int i=0; i<widgets.length; i++) {
// widgets[i] = (LabeledComponentBase)allWidgets[i+1];
// }
// }
// else {
// widgets = new LabeledComponentBase[0];
// }
// return widgets;
// }
/**
* Sets the current composite property for a CompositePropertyPanel to the
* type currently stored by that panel.
*/
private void setCpropValueFromWidget(Property cprop, CompositePropertyPanel cpanel) {
cpanel.myCpropProperty = cprop;
if (getCpropTypeFromProperty(cprop) != cpanel.myCpropType) {
if (cpanel.myCpropType == Property.VoidValue) {
System.out.println("Warning: void widget value for " + cprop.getName() + ", ignoring");
} else {
CompositeProperty protoCprop = createCprop(cpanel.myCpropType);
// PropertyInfo info = cpanel.myCpropProperty.getInfo();
cpanel.myCpropProperty.set(protoCprop);
}
}
cpanel.rebuildPanel(/*setValuesFromWidgets=*/
true);
}
use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method tryCreatingCpropFromPrototype.
/**
* Try to create a prototype for a particular type of composite property by
* cloning an instance (if there is one) in a host list.
*/
private CompositeProperty tryCreatingCpropFromPrototype(Class<?> type) {
CompositeProperty protoCprop = null;
EditingProperty eprop = (EditingProperty) myCpropProperty;
HostList hostList = eprop.getHostList();
Object[] values = hostList.getAllValues(eprop.getCell());
for (int i = 0; i < values.length; i++) {
if (type.isInstance(values[i]) && values[i] instanceof Clonable) {
try {
protoCprop = (CompositeProperty) ((Clonable) values[i]).clone();
} catch (Exception e) {
System.out.println("Warning: clone failed for " + values[i].getClass());
}
if (protoCprop != null) {
break;
}
}
}
return protoCprop;
}
use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.
the class ComponentPropertyField method valueToTextArray.
protected String[] valueToTextArray(Object value) {
ModelComponent comp = getComponent(value);
RootModel root = myMain.getRootModel();
String compStr = "/";
String propStr = "";
if (root == null || comp == null) {
return new String[] { "", "" };
}
if (value instanceof ModelComponent) {
compStr = ComponentUtils.getPathName(root, comp);
} else if (value instanceof Property) {
Property prop = (Property) value;
boolean excludeLeaf = (myPropertySelector != null && !(prop.get() instanceof CompositeProperty));
String path = ComponentUtils.getPropertyPathName(prop, root, false);
int idx = path.indexOf(':');
// default to root
propStr = path;
if (idx >= 0) {
compStr = path.substring(0, idx);
if (idx < path.length() - 1) {
propStr = path.substring(idx + 1);
}
}
} else {
throw new InternalErrorException("Unknown value type: " + value.getClass());
}
return new String[] { compStr, propStr };
}
use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.
the class ComponentPropertyField method getPropertyForComposite.
private Property getPropertyForComposite(CompositeProperty cprop) {
PropertyInfo info = cprop.getPropertyInfo();
HasProperties host = cprop.getPropertyHost();
Property prop = host.getProperty(info.getName());
if (prop == null) {
throw new InternalErrorException("Property not found in composite property host");
}
return prop;
}
use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method createWidgetProps.
/**
* Create properties for the widgets controlling the property values of the
* current composite property.
*/
private LinkedList<Property> createWidgetProps() {
if (myCpropProperty instanceof EditingProperty) {
EditingProperty eprop = (EditingProperty) myCpropProperty;
HostList hostList = eprop.getHostList();
PropTreeCell cell = eprop.getCell();
cell.removeAllChildren();
CompositeProperty cprop = createCprop(myCpropType);
LinkedList<Property> props = PropertyUtils.createProperties(cprop);
for (Property prop : props) {
cell.addChild(new PropTreeCell(prop.getInfo(), prop.get()));
}
hostList.setSubHostsFromValue(cell);
hostList.saveBackupValues(cell);
hostList.getCommonValues(cell, /*live=*/
true);
cell.setValue(CompositeProperty.class);
return EditingProperty.createProperties(cell, hostList, /*live=*/
true);
} else {
myCprop = (CompositeProperty) myCpropProperty.get();
return PropertyUtils.createProperties(myCprop);
}
}
Aggregations