Search in sources :

Example 11 with EditingProperty

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

Example 12 with EditingProperty

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

Example 13 with EditingProperty

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

Example 14 with EditingProperty

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;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property)

Example 15 with EditingProperty

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;
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) LabeledComponentBase(maspack.widgets.LabeledComponentBase) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) Point(java.awt.Point)

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