Search in sources :

Example 6 with CompositeProperty

use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.

the class CompositePropertyPanel method valueChange.

/**
 * Called when the composite property type is changed via the composite
 * property type selector.
 */
public void valueChange(ValueChangeEvent e) {
    if (e.getSource() == myCpropSelector) {
        String newCpropName = (String) myCpropSelector.getValue();
        Class<?> newCpropType = myCpropTypes.get(newCpropName);
        CompositeProperty protoCprop = null;
        if (myCpropType == Property.VoidValue && newCpropType != null && myCpropProperty instanceof EditingProperty) {
            // if there is an existing composite property of this type among the
            // hosts, try to create the prototype by cloning it so
            // that we start with it's properties
            protoCprop = tryCreatingCpropFromPrototype(newCpropType);
        }
        if (protoCprop == null) {
            protoCprop = createCprop(newCpropType);
        }
        myCpropProperty.set(protoCprop);
        myCpropType = newCpropType;
        rebuildPanel(/*setValuesFromWidgets=*/
        true);
        GuiUtils.repackComponentWindow(this);
        fireGlobalValueChangeListeners(new ValueChangeEvent(this, e));
    } else if (e.getSource() == myExpandButton) {
        if (myExpandButton.getBooleanValue()) {
            setExpandState(ExpandState.Expanded);
        } else {
            setExpandState(ExpandState.Contracted);
        }
    } else {
        throw new InternalErrorException("Unexpected valueChange event: " + e);
    // fireGlobalValueChangeListeners(new ValueChangeEvent(this, e));
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty)

Example 7 with CompositeProperty

use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.

the class NumericProbeEditor method getFullPropPath.

/**
 * returns the full string path of a property by going up the hierachy and
 * finding all its parent properties (if any) and component path.
 */
protected String getFullPropPath(Property prop) {
    String compPath = prop.getName();
    ModelComponent root = myMain.getRootModel();
    Object host = prop.getHost();
    // System.out.println("Looking for parent path...");
    if (host instanceof CompositeProperty) {
        while (host instanceof CompositeProperty) {
            String name = ((CompositeProperty) host).getPropertyInfo().getName();
            // System.out.println(name);
            compPath = name + "." + compPath;
            host = ((CompositeProperty) host).getPropertyHost();
        }
        String baseComp = ComponentUtils.getPathName((CompositeComponent) root, (ModelComponent) host);
        compPath = baseComp + ComponentUtils.componentPropertySeparator + compPath;
    } else {
        compPath = ComponentUtils.getPathName((CompositeComponent) root, (ModelComponent) prop.getHost());
        compPath += ComponentUtils.componentPropertySeparator + prop.getName();
    }
    // System.out.println("found component base path: "+compPath);
    return compPath;
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent) CompositeProperty(maspack.properties.CompositeProperty)

Example 8 with CompositeProperty

use of maspack.properties.CompositeProperty in project artisynth_core by artisynth.

the class ComponentPropertyField method valueToText.

protected String valueToText(Object value) {
    ModelComponent comp = getComponent(value);
    RootModel root = myMain.getRootModel();
    if (root == null || comp == null) {
        return "";
    }
    if (value instanceof ModelComponent) {
        return 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);
        if (!path.contains(":")) {
            // root component + property
            path = "/:" + path;
        }
        return path;
    } else {
        throw new InternalErrorException("Unknown value type: " + value.getClass());
    }
// String text = ComponentUtils.getPathName(root, comp);
// if (value instanceof Property)
// { Property prop = (Property)value;
// String propPath = getPropertyPath (prop, myPropertySelector != null);
// if (propPath.length() > 0)
// { text += "/" + propPath;
// }
// }
// return text;
}
Also used : RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) InternalErrorException(maspack.util.InternalErrorException) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) CompositeProperty(maspack.properties.CompositeProperty)

Aggregations

CompositeProperty (maspack.properties.CompositeProperty)8 InternalErrorException (maspack.util.InternalErrorException)5 Property (maspack.properties.Property)4 ModelComponent (artisynth.core.modelbase.ModelComponent)3 EditingProperty (maspack.properties.EditingProperty)3 RootModel (artisynth.core.workspace.RootModel)2 HostList (maspack.properties.HostList)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)1 HasProperties (maspack.properties.HasProperties)1 InheritableProperty (maspack.properties.InheritableProperty)1 PropTreeCell (maspack.properties.PropTreeCell)1 PropertyInfo (maspack.properties.PropertyInfo)1 Clonable (maspack.util.Clonable)1