Search in sources :

Example 26 with Property

use of maspack.properties.Property 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 27 with Property

use of maspack.properties.Property 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 28 with Property

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

the class AddPropertyPane method readComponentField.

/**
 * called when the component string field changes
 */
private void readComponentField() {
    isComplete = false;
    clearDimensionLabel();
    // System.out.println("SET FALSE");
    myParent.actionPerformed(new ActionEvent(this, 0, "Invalidate"));
    // System.out.println("new value "+compNameField.getText());
    Object compOrProp = myPropField.getValue();
    RootModel root = Main.getMain().getRootModel();
    if (compOrProp instanceof ModelComponent) {
        propertyPath = ComponentUtils.getPathName(root, (ModelComponent) compOrProp);
        myParent.actionPerformed(new ActionEvent(this, 0, "blank"));
    } else if (compOrProp instanceof Property) {
        Property prop = (Property) compOrProp;
        propertyPath = ComponentUtils.getPropertyPathName(prop, root, /*excludeLeaf=*/
        false);
        if (!HasProperties.class.isAssignableFrom(prop.get().getClass())) {
            isComplete = true;
            int dim = NumericProbeEditor.GetPropDim(propertyPath);
            setDimensionLabel(dim);
            myParent.actionPerformed(new ActionEvent(this, 0, "PropSelected"));
            normalColor = NumericProbeEditor.completedColor;
        } else {
            myParent.actionPerformed(new ActionEvent(this, 0, "blank"));
        }
    } else {
        propertyPath = "";
        myParent.actionPerformed(new ActionEvent(this, 0, "blank"));
    }
    updateAppearance();
// readFullPath(compNameField.getText());
}
Also used : RootModel(artisynth.core.workspace.RootModel) ModelComponent(artisynth.core.modelbase.ModelComponent) ActionEvent(java.awt.event.ActionEvent) Property(maspack.properties.Property)

Example 29 with Property

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

the class NumericProbeEditor method load.

public void load(NumericProbeBase probe) {
    // when opening a probe we create local copies of:
    // 
    // 1) the properties
    // 2) the drivers
    // 3) the variables
    // 4) the variable dimensions (for input probes)
    NumericProbeDriver[] drivers = probe.getDrivers();
    myDrivers = new ArrayList<NumericProbeDriver>();
    for (int i = 0; i < drivers.length; i++) {
        myDrivers.add(new NumericProbeDriver(drivers[i]));
    }
    myProperties = new ArrayList<Property>();
    Property[] props = probe.getAttachedProperties();
    for (int i = 0; i < props.length; i++) {
        myProperties.add(props[i]);
    }
    myVariables = new LinkedHashMap<String, NumericProbeVariable>();
    for (Map.Entry<String, NumericProbeVariable> entry : probe.getVariables().entrySet()) {
        myVariables.put(entry.getKey(), new NumericProbeVariable(entry.getValue()));
    }
}
Also used : NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) NumericProbeVariable(artisynth.core.probes.NumericProbeVariable) CompositeProperty(maspack.properties.CompositeProperty) Property(maspack.properties.Property) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with Property

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

the class OutputNumericProbeEditor method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() == "Add") {
        addBlankOutputProbeVector();
        increaseFrameSize();
    } else if (e.getActionCommand() == "Add Property") {
        addBlankOutputProperty();
        increaseFrameSize();
    } else // }
    if (e.getActionCommand() == "PropSelected") {
        // same as input?
        AddPropertyPane propPane = (AddPropertyPane) e.getSource();
        propPane.setPropNameEnabled(true);
        int index = propList.indexOf(propPane);
        System.out.println("prop selected from prop pane #: " + index);
        String propPath = propPane.getPropPath();
        Property prop = getProp(propPath);
        if (updateProperty(index, prop)) {
            increaseFrameSize();
        }
        updateVariable(propPane.getPropNameFieldText(), prop);
    } else if (e.getActionCommand() == "blank") {
        // happens when we receive a non-selection from the prop select box
        // todo: decide if this method is better (leave prop in list as is)
        // or the one in input editor (where we null the property).
        AddPropertyPane propPane = (AddPropertyPane) e.getSource();
        int index = propList.indexOf(propPane);
        if (index < 0)
            return;
        for (NumericProbeDriver driver : myDrivers) {
            if (driver.usesVariable(propPane.getPropNameFieldText())) {
                int driverIndex = myDrivers.indexOf(driver);
                driver.setInvalid();
                AddEquationPane eqPane = eqList.get(driverIndex);
                eqPane.setEqText("");
                eqPane.clearDimensionLabel();
                // AddVectorPane vecPane = probeChannels.get(driverIndex);
                // vecPane.clearDimBox();
                System.out.println("invalidated driver with expr [" + driver.getExpression() + "]");
            }
        }
        myVariables.remove(propPane.getPropNameFieldText());
        myProperties.set(index, null);
        propPane.setPropNameEnabled(false);
    // AddEquationPane eqPane = getEqPane(index);
    // if (eqPane != null)
    // {
    // try
    // {
    // myProperties.set(index, null);
    // myDrivers.get(index).setInvalid();
    // }
    // catch (Exception exp)
    // {
    // System.out.println(exp.getMessage());
    // }
    // eqPane.setEnabled(false);
    // eqPane.setEqText("");
    // }
    } else if (// delete output
    e.getActionCommand() == "Expression Changed") {
        AddEquationPane eqPane = (AddEquationPane) e.getSource();
        System.out.println("new expression entered :" + eqPane.getEqText());
        String newExpr = eqPane.getEqText();
        if (// otherwise, do nothing and driver will
        !newExpr.equals("")) // remain invalid
        {
            changeExpression(eqList.indexOf(eqPane), newExpr);
        } else {
            invalidateDriverAndGUI(eqList.indexOf(eqPane));
            eqPane.clearDimensionLabel();
        }
    } else if (// delete output
    e.getActionCommand() == "Delete Channel") {
        System.out.println("Deleting channel and equation GUI...");
        AddEquationPane pane = (AddEquationPane) e.getSource();
        int index = eqList.indexOf(pane);
        removeEquationGUI(index);
        deleteOutput(index);
    } else if (// delete a property
    e.getActionCommand() == "Delete Property") {
        AddPropertyPane pane = (AddPropertyPane) e.getSource();
        int index = propList.indexOf(pane);
        String propname = pane.getPropNameFieldText();
        System.out.println("Deleting Property ID" + index);
        removePropertyGUI(index);
        deleteProperty(index);
        myVariables.remove(propname);
        revalidateDrivers(propname);
    } else if (// rename property
    e.getActionCommand() == "Property Renamed") {
        AddPropertyPane propPane = (AddPropertyPane) e.getSource();
        String newName = propPane.getPropNameFieldText();
        String oldName = propPane.getOldPropName();
        for (AddPropertyPane pane : propList) {
            if (!propPane.equals(pane)) {
                if (newName.compareTo(pane.getPropNameFieldText()) == 0) {
                    // check to make sure there are no duplicates
                    showErrorWindow("Name already exists!");
                    newName = oldName;
                // so in this case, the 'new' name is the same as old, so
                // effectively we don't make any changes
                // and when calling setChannelName a few lines later we
                // restore the old name into the GUI
                }
            }
        }
        // System.out.println("trying to set name");
        propPane.setPropNameField(newName);
        renameProperty(oldName, newName);
    } else if (e.getActionCommand() == "MouseEnteredEq") {
    // int index = eqList.indexOf(e.getSource());
    // AddVectorPane vec = probeChannels.get(index);
    // vec.setHighlight(true);
    } else if (e.getActionCommand() == "MouseExitedEq") {
    // int index = eqList.indexOf(e.getSource());
    // AddVectorPane vec = probeChannels.get(index);
    // vec.setHighlight(false);
    } else if (e.getActionCommand() == "MouseEnteredVec") {
    // int index = probeChannels.indexOf(e.getSource());
    // AddEquationPane eq = eqList.get(index);
    // eq.setHighlight(true);
    } else if (e.getActionCommand() == "MouseExitedVec") {
    // int index = probeChannels.indexOf(e.getSource());
    // AddEquationPane eq = eqList.get(index);
    // eq.setHighlight(false);
    } else if (// done. add the probe!
    e.getActionCommand() == "Done") {
        setOutputProbe();
        // if (myParent != null) {
        // myParent.actionPerformed (new ActionEvent (this, 0, "ProbeEdited"));
        // }
        Timeline timeline = myMain.getTimeline();
        if (timeline != null) {
            timeline.updateProbes(myMain.getRootModel());
        }
        dispose();
    } else {
        super.actionPerformed(e);
    }
    refreshAddBtn();
}
Also used : Timeline(artisynth.core.gui.Timeline) NumericProbeDriver(artisynth.core.probes.NumericProbeDriver) Property(maspack.properties.Property)

Aggregations

Property (maspack.properties.Property)44 CompositeProperty (maspack.properties.CompositeProperty)15 EditingProperty (maspack.properties.EditingProperty)15 InheritableProperty (maspack.properties.InheritableProperty)10 ModelComponent (artisynth.core.modelbase.ModelComponent)9 IOException (java.io.IOException)7 InternalErrorException (maspack.util.InternalErrorException)7 ArrayList (java.util.ArrayList)6 LabeledComponentBase (maspack.widgets.LabeledComponentBase)6 NumericInputProbe (artisynth.core.probes.NumericInputProbe)5 HasProperties (maspack.properties.HasProperties)5 NumericOutputProbe (artisynth.core.probes.NumericOutputProbe)4 NumericProbeVariable (artisynth.core.probes.NumericProbeVariable)4 RootModel (artisynth.core.workspace.RootModel)3 Component (java.awt.Component)3 Point (java.awt.Point)3 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Timeline (artisynth.core.gui.Timeline)2