Search in sources :

Example 1 with EditingProperty

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);
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) InheritableProperty(maspack.properties.InheritableProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

Example 2 with EditingProperty

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);
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

Example 3 with EditingProperty

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());
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) HostList(maspack.properties.HostList)

Example 4 with EditingProperty

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);
                }
            }
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) HostList(maspack.properties.HostList)

Example 5 with EditingProperty

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;
}
Also used : EditingProperty(maspack.properties.EditingProperty) Clonable(maspack.util.Clonable) HostList(maspack.properties.HostList) CompositeProperty(maspack.properties.CompositeProperty) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

EditingProperty (maspack.properties.EditingProperty)15 CompositeProperty (maspack.properties.CompositeProperty)8 Property (maspack.properties.Property)8 HostList (maspack.properties.HostList)7 InheritableProperty (maspack.properties.InheritableProperty)6 InternalErrorException (maspack.util.InternalErrorException)5 PropTreeCell (maspack.properties.PropTreeCell)4 LabeledComponentBase (maspack.widgets.LabeledComponentBase)2 ModelComponent (artisynth.core.modelbase.ModelComponent)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 PropertyInfo (maspack.properties.PropertyInfo)1 Clonable (maspack.util.Clonable)1