Search in sources :

Example 6 with EditingProperty

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

the class CompositePropertyPanel method createWidgetProps.

/**
 * Create properties for the widgets controlling the property values of the
 * current composite property.
 */
private LinkedList<Property> createWidgetProps() {
    if (myCpropProperty instanceof EditingProperty) {
        EditingProperty eprop = (EditingProperty) myCpropProperty;
        HostList hostList = eprop.getHostList();
        PropTreeCell cell = eprop.getCell();
        cell.removeAllChildren();
        CompositeProperty cprop = createCprop(myCpropType);
        LinkedList<Property> props = PropertyUtils.createProperties(cprop);
        for (Property prop : props) {
            cell.addChild(new PropTreeCell(prop.getInfo(), prop.get()));
        }
        hostList.setSubHostsFromValue(cell);
        hostList.saveBackupValues(cell);
        hostList.getCommonValues(cell, /*live=*/
        true);
        cell.setValue(CompositeProperty.class);
        return EditingProperty.createProperties(cell, hostList, /*live=*/
        true);
    } else {
        myCprop = (CompositeProperty) myCpropProperty.get();
        return PropertyUtils.createProperties(myCprop);
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) CompositeProperty(maspack.properties.CompositeProperty)

Example 7 with EditingProperty

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

the class CompositePropertyPanel method isNullAllowed.

private boolean isNullAllowed(Property prop) {
    if (prop instanceof EditingProperty) {
        // then null values are allowed only if they are permitted
        // on all the hosts
        EditingProperty eprop = (EditingProperty) prop;
        HostList hostList = eprop.getHostList();
        PropTreeCell cell = eprop.getCell();
        PropertyInfo[] infos = hostList.getAllInfos(cell);
        boolean nullAllowed = true;
        for (PropertyInfo info : infos) {
            if (!info.getNullValueOK()) {
                nullAllowed = false;
            }
        }
        return nullAllowed;
    } else {
        return prop.getInfo().getNullValueOK();
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) HostList(maspack.properties.HostList) PropertyInfo(maspack.properties.PropertyInfo)

Example 8 with EditingProperty

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

the class CompositePropertyPanel method printWidgetProps.

// For debugging only ...
void printWidgetProps(LinkedList<Property> props) {
    if (myCpropProperty instanceof EditingProperty) {
        EditingProperty eprop = (EditingProperty) myCpropProperty;
        // HostList hostList = eprop.getHostList();
        PropTreeCell cell = eprop.getCell();
        System.out.println("parent cell=@" + cell.hashCode());
        for (Property p : props) {
            EditingProperty ep = (EditingProperty) p;
            ep.getCell().getIndex();
            System.out.println(" " + ep.getName() + "=@" + ep.getCell().hashCode());
            if (ep.getCell().getParent() != cell) {
                System.out.println("BAD");
            }
        }
        System.out.println("OK");
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) PropTreeCell(maspack.properties.PropTreeCell) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

Example 9 with EditingProperty

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

the class CompositePropertyPanel method rebuildPanel.

/**
 * Rebuilds the panel. This is called when the panel is first created,
 * or when the set of widgets changes (due to a change in the composite
 * property type).
 */
private void rebuildPanel(boolean setValuesFromWidgets) {
    myPanel.removeAllWidgets();
    myPanel.addWidget(getMainWidget());
    myWidgetProps = null;
    myWidgets = null;
    if (myCpropType == Property.VoidValue) {
        if (myCpropSelector.getValue() != Property.VoidValue) {
            setSelectorValue(Property.VoidValue);
        }
    } else {
        String matName = getCpropName(myCpropType);
        if (!PropertyUtils.equalValues(matName, myCpropSelector.getValue())) {
            setSelectorValue(matName);
        }
        if (myCpropType != null) {
            if (myExpandState == ExpandState.Contracted) {
                myPanel.addWidget(myExpandButton);
            }
            myWidgets = myWidgetSets.get(matName);
            if (myWidgets == null) {
                myWidgetProps = createWidgetProps();
                ArrayList<LabeledComponentBase> widgets = new ArrayList<LabeledComponentBase>();
                for (Property prop : myWidgetProps) {
                    LabeledComponentBase w = PropertyWidget.create(prop);
                    if (w != null) {
                        widgets.add(w);
                        myPanel.processPropertyWidget(prop, w);
                        if (w instanceof LabeledControl) {
                            LabeledControl ctrl = (LabeledControl) w;
                            // pass on global value change listeners
                            for (ValueChangeListener l : myGlobalValueChangeListeners) {
                                ctrl.addValueChangeListener(l);
                            }
                        // notify this panel of a change
                        // ctrl.addValueChangeListener(this);
                        }
                    }
                }
                myWidgets = widgets.toArray(new LabeledComponentBase[0]);
                myWidgetSets.put(matName, myWidgets);
            } else {
                myWidgetProps = createWidgetProps();
                attachPropsToWidgets(myWidgets, myWidgetProps, setValuesFromWidgets);
            }
            for (LabeledComponentBase widget : myWidgets) {
                if (myExpandState != ExpandState.Contracted) {
                    myPanel.addWidget(widget);
                } else {
                    myPanel.doAddWidget(widget, myPanel.numWidgets());
                }
            }
            if (myExpandState == ExpandState.Expanded) {
                myPanel.addWidget(myExpandButton);
            }
        } else {
            if (myCpropProperty instanceof EditingProperty) {
                updateEditingPropertyForNullCprop((EditingProperty) myCpropProperty);
            }
        }
    }
}
Also used : EditingProperty(maspack.properties.EditingProperty) ArrayList(java.util.ArrayList) InheritableProperty(maspack.properties.InheritableProperty) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

Example 10 with EditingProperty

use of maspack.properties.EditingProperty 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)

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