use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method getCurrentCprop.
/**
* Returns the current composite property.
*/
private Object getCurrentCprop() {
if (myCpropProperty instanceof EditingProperty) {
EditingProperty eprop = (EditingProperty) myCpropProperty;
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 values[0];
} else {
return myCpropProperty.get();
}
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class CompositePropertyPanel method attachPropsToWidgets.
/**
* Attaches a newly created set of properties to their associated
* widgets.
*
* @param widgets list of widgets
* @param props newly created properties
* @param setValuesFromWidgets if <code>true</code>, then the properties
* should be set to assume the values currently stored in the widgets.
*/
private void attachPropsToWidgets(LabeledComponentBase[] widgets, LinkedList<Property> props, boolean setValuesFromWidgets) {
if (widgets.length != props.size()) {
throw new InternalErrorException("Number of widgets (" + widgets.length + ") != number of properties (" + props.size() + ")");
}
int i = 0;
for (Property prop : props) {
LabeledComponentBase widget = widgets[i++];
if (!setValuesFromWidgets || !(widget instanceof CompositePropertyPanel)) {
PropertyWidget.initializeWidget(widget, prop);
}
if (setValuesFromWidgets) {
if (widget instanceof CompositePropertyPanel) {
CompositePropertyPanel cpanel = (CompositePropertyPanel) widget;
if (cpanel.myCpropType != Property.VoidValue) {
setCpropValueFromWidget(prop, (CompositePropertyPanel) widget);
} else {
cpanel.myCpropProperty = prop;
cpanel.updateWidgetValues(/*updateFromSource=*/
true);
}
} else if (widget instanceof LabeledControl) {
LabeledControl ctrl = (LabeledControl) widget;
if (ctrl.getValue() != Property.VoidValue) {
setValueFromWidget(prop, ctrl);
} else {
if (prop instanceof EditingProperty) {
EditingProperty eprop = (EditingProperty) prop;
eprop.updateValue();
}
PropertyWidget.updateValue(ctrl, prop);
}
}
}
// will set value
PropertyWidget.finishWidget(widget, prop);
if (prop instanceof InheritableProperty) {
PropertyModeButton button = PropertyWidget.getModeButton((LabeledComponentBase) widget);
if (button != null) {
button.setProperty((InheritableProperty) prop);
}
}
}
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class PropertyWidgetDialog method createEditingProperty.
private EditingProperty createEditingProperty(Property prop) {
if (prop.getHost() == null) {
throw new InternalErrorException("Property " + prop.getName() + " does not have host");
}
HostList hostList = new HostList(1);
hostList.addHost(prop.getHost());
// get single property from host list
String[] restricted = new String[] { prop.getName() };
String[] excluded = null;
PropTreeCell tree = hostList.commonProperties(null, /* allowReadonly= */
false, restricted, excluded);
if (tree.numChildren() == 0) {
throw new InternalErrorException("Property " + prop.getName() + " not found in host");
}
// expand save data in hostList down one level ...
hostList.saveBackupValues(tree);
return new EditingProperty(tree.getFirstChild(), hostList, /* live= */
true);
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class PropertyWidgetDialog method createWidget.
public LabeledComponentBase createWidget() {
if (getModelComponent() == null || getPropertyInfo() == null) {
throw new IllegalStateException("component and/or property not set");
}
LabeledComponentBase widget;
ModelComponent comp = getModelComponent();
String propPath = getPropertyPath();
Property prop = comp.getProperty(propPath);
if (prop == null) {
throw new InternalErrorException("property '" + propPath + "' not found for component " + comp.getClass());
}
if (CompositeProperty.class.isAssignableFrom(prop.getInfo().getValueClass())) {
// replace prop with an EditingProperty, since
// CompositePropertyWidgets only work properly with those
prop = createEditingProperty(prop);
}
if (isSliderSelected()) {
widget = PropertyWidget.create(prop, getSliderMinimum(), getSliderMaximum());
} else {
widget = PropertyWidget.create(prop);
}
String labelText = myLabelTextField.getStringValue();
widget.setLabelText(labelText);
if (!myLabelFontColorSelector.valueIsNull()) {
widget.setLabelFontColor(myLabelFontColorSelector.getColor());
}
if (!myBackgroundColorSelector.valueIsNull()) {
widget.setBackgroundColor(myBackgroundColorSelector.getColor());
}
return widget;
}
use of maspack.properties.EditingProperty in project artisynth_core by artisynth.
the class ControlPanel method removeStalePropertyWidgets.
public boolean removeStalePropertyWidgets() {
LinkedList<LabeledComponentBase> removeList = new LinkedList<LabeledComponentBase>();
for (int i = 0; i < myPanel.numWidgets(); i++) {
if (myPanel.getWidget(i) instanceof LabeledComponentBase) {
LabeledComponentBase widget = (LabeledComponentBase) myPanel.getWidget(i);
Property prop = myPanel.getWidgetProperty(widget);
if (prop != null && !(prop instanceof EditingProperty)) {
if (isStale(prop)) {
removeList.add(widget);
}
}
}
}
if (removeList.size() > 0) {
for (LabeledComponentBase widget : removeList) {
myPanel.removeWidget(widget);
// myWidgetPropMap.remove (widget);
}
if (myFrame != null) {
myFrame.pack();
}
return true;
} else {
return false;
}
}
Aggregations