use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class PropertyPanel method updateWidgetValues.
/**
* Update the widgets in this panel so that they reflect the values of the
* underlying properties.
*
* <p>Underlying properties which are instances of EditingProperty will
* first normally update their own values from their source component(s).
* In some cases it may be desirable to suppress this behavior, which can be
* done by setting <code>updateFromSource</code> to <code>false</code>.
*
* @param updateFromSource if <code>false</code>, do not update the values
* of EditingProperties from their underlying source component(s).
*/
public void updateWidgetValues(boolean updateFromSource) {
for (int i = 0; i < myWidgets.size(); i++) {
if (myWidgets.get(i) instanceof LabeledControl) {
LabeledControl widget = (LabeledControl) myWidgets.get(i);
Property prop = myWidgetPropMap.get(widget);
if (prop != null) {
// their values, which need to be updated from the source
if (prop instanceof EditingProperty && updateFromSource) {
((EditingProperty) prop).updateValue();
}
PropertyWidget.updateValue(widget, prop);
}
} else if (myWidgets.get(i) instanceof LabeledPanel) {
((LabeledPanel) myWidgets.get(i)).updateWidgetValues(updateFromSource);
}
}
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method doUpdateWidgets.
private void doUpdateWidgets(boolean updateFromSource) {
int i = 0;
for (Property prop : myWidgetProps) {
LabeledComponentBase widget = myWidgets[i++];
if (widget instanceof LabeledControl) {
LabeledControl ctrl = (LabeledControl) widget;
if (prop instanceof EditingProperty && updateFromSource) {
((EditingProperty) prop).updateValue();
}
PropertyWidget.updateValue(ctrl, prop);
} else if (widget instanceof CompositePropertyPanel) {
CompositePropertyPanel cpanel = (CompositePropertyPanel) widget;
cpanel.updateWidgetValues(updateFromSource);
}
}
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method getCpropTypeFromProperty.
/**
* Get the type of the current composite property from its property
* handle. If the property handle is an EditingProperty, then it may refer
* to several instances on several hosts, and if the type is not the same
* across those hosts, the type is considered to be Property.VoidValue.
*/
private Class<?> getCpropTypeFromProperty(Property cprop) {
if (cprop instanceof EditingProperty) {
EditingProperty eprop = (EditingProperty) cprop;
HostList hostList = eprop.getHostList();
Object[] values = hostList.getAllValues(eprop.getCell());
Class<?> cpropType = getCpropType(values[0]);
if (cpropType == Property.VoidValue) {
return Property.VoidValue;
}
for (int i = 1; i < values.length; i++) {
Class<?> nextType = getCpropType(values[i]);
if (nextType == Property.VoidValue || nextType != cpropType) {
return Property.VoidValue;
}
}
return cpropType;
} else {
return getCpropType(cprop.get());
}
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method updateWidgetValues.
/**
* Updates the current set of widgets in this panel so that their
* values reflect the underlying property values.
*
* @param updateFromSource if <code>false</code>, do not update the values
* of EditingProperties from their underlying source component(s).
*/
public void updateWidgetValues(boolean updateFromSource) {
Class<?> cpropType = getCpropTypeFromProperty(myCpropProperty);
if (myCpropType != cpropType) {
// composite property type has changed, and hence so have the widgets
myCpropType = cpropType;
rebuildPanel(/*setFromWidgets=*/
false);
GuiUtils.repackComponentWindow(this);
} else {
// widgets are the same but need to update their values
if (myWidgets != null && myWidgets.length > 0) {
if (myCpropProperty instanceof EditingProperty) {
if (updateFromSource) {
// reset source hosts in case those have been reset by
// another party
EditingProperty eprop = (EditingProperty) myCpropProperty;
HostList hostList = eprop.getHostList();
hostList.setSubHostsFromValue(eprop.getCell());
}
doUpdateWidgets(updateFromSource);
} else {
if (myCprop != getCurrentCprop()) {
myWidgetProps = createWidgetProps();
attachPropsToWidgets(myWidgets, myWidgetProps, /*setValuesFromWidgets=*/
false);
// widgets will be updated in the above code
} else {
doUpdateWidgets(updateFromSource);
}
}
}
}
}
use of maspack.properties.EditingProperty 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;
}
Aggregations