Search in sources :

Example 36 with Property

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

the class AddComponentAgent method setComponentType.

/**
 * Called whenever the specific class type of the components being added by
 * this agent is changed.
 */
public void setComponentType(Class type) {
    if (type == myComponentType) {
        return;
    }
    myComponentType = type;
    if (myPrototype != null) {
        setProperties(myPrototype, myPrototype);
    }
    myPrototype = getPrototypeComponent(type);
    if (myPrototype != null) {
        myHostList = new HostList(new HasProperties[] { myPrototype });
        myPropTree = myHostList.commonProperties(null, false);
        // remove properties which are to be excluded
        String[] excludedPropNames = getExcludedPropNames(type);
        for (int i = 0; i < excludedPropNames.length; i++) {
            myPropTree.removeDescendant(excludedPropNames[i]);
        }
        myHostList.saveBackupValues(myPropTree);
        myHostList.getCommonValues(myPropTree, /* live= */
        true);
        if (myPropertyPanelIdx != -1) {
            myDefaultProps = EditingProperty.createProperties(myPropTree, myHostList, /* isLive= */
            true);
            LinkedList<Property> basicProps = getBasicProps(type, myDefaultProps);
            if (basicProps.size() > 0) {
                LinkedList<Property> extraProps = new LinkedList<Property>();
                extraProps.addAll(myDefaultProps);
                extraProps.removeAll(basicProps);
                myPropertyPanel = new ExpandablePropertyPanel(basicProps, extraProps);
            } else {
                myPropertyPanel = new PropertyPanel(myDefaultProps);
            }
            if (myPropertyPanelBorderTitle != null) {
                String title = myPropertyPanelBorderTitle;
                if (title.indexOf("TYPE") != -1) {
                    title = title.replaceAll("TYPE", (String) myTypeSelector.getValue());
                }
                myPropertyPanel.setBorder(GuiUtils.createTitledPanelBorder(title));
            }
            resetDefaultProperties();
            myPropertyPanel.updateWidgetValues(/* updateFromSource= */
            false);
            myPropertyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            myContentPane.removeWidget(myPropertyPanelIdx);
            myContentPane.addWidget(myPropertyPanel, myPropertyPanelIdx);
            myContentPane.validate();
            // myContentPane.resetLabelAlignment();
            if (myDisplay.isVisible()) {
                myDisplay.pack();
            }
        }
    }
}
Also used : HasProperties(maspack.properties.HasProperties) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) HostList(maspack.properties.HostList) EditingProperty(maspack.properties.EditingProperty) Property(maspack.properties.Property) LinkedList(java.util.LinkedList) ExpandablePropertyPanel(maspack.widgets.ExpandablePropertyPanel) PropertyPanel(maspack.widgets.PropertyPanel)

Example 37 with Property

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

Example 38 with Property

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

the class ControlPanel method getSoftReferences.

@Override
public void getSoftReferences(List<ModelComponent> refs) {
    HashSet<ModelComponent> myrefs = new HashSet<ModelComponent>();
    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 instanceof GenericPropertyHandle) {
                ModelComponent comp = ComponentUtils.getPropertyComponent(prop);
                if (comp != null && !ComponentUtils.isAncestorOf(comp, this)) {
                    myrefs.add(comp);
                }
            } else {
            // TODO - handle other cases
            }
        }
    }
    refs.addAll(myrefs);
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) LabeledComponentBase(maspack.widgets.LabeledComponentBase) GenericPropertyHandle(maspack.properties.GenericPropertyHandle) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) Point(java.awt.Point)

Example 39 with Property

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

the class ControlPanel method postscanWidget.

public void postscanWidget(Deque<ScanToken> tokens, CompositeComponent ancestor) throws IOException {
    String propPath = null;
    if (tokens.peek() instanceof StringToken) {
        propPath = (String) tokens.poll().value();
    }
    if (!(tokens.peek() instanceof ObjectToken)) {
        throw new IOException("Expecting ObjectToken containing widget");
    }
    Component comp = (Component) tokens.poll().value();
    if (comp instanceof LabeledComponentBase) {
        Property property = null;
        LabeledComponentBase widget = (LabeledComponentBase) comp;
        // such as range could cause the property value itself to be reset
        if (widget instanceof LabeledControl) {
            ((LabeledControl) widget).maskValueChangeListeners(true);
        }
        if (propPath != null) {
            property = ancestor.getProperty(propPath);
            if (property == null) {
                System.out.println("Ignoring control panel widget for " + propPath);
                widget = null;
            } else {
                boolean widgetSet = false;
                try {
                    // initialize widget, but don't set properties because
                    // these will have already been set in the scan method
                    widgetSet = PropertyWidget.initializeWidget(widget, property);
                } catch (Exception e) {
                    e.printStackTrace();
                    widgetSet = false;
                }
                if (widgetSet == false) {
                    System.out.println("Warning: widget " + widget + " inappropriate for property " + propPath + "; ignoring");
                    widget = null;
                }
            }
        }
        if (widget instanceof LabeledControl) {
            ((LabeledControl) widget).maskValueChangeListeners(false);
        }
        // properties (such as the range) are initialized
        if (widget != null && property != null) {
            PropertyWidget.finishWidget(widget, property);
            myPanel.processPropertyWidget(property, widget);
        }
        if (widget != null) {
            addWidget(widget);
        }
    } else {
        addWidget(comp);
    }
}
Also used : LabeledControl(maspack.widgets.LabeledControl) LabeledComponentBase(maspack.widgets.LabeledComponentBase) IOException(java.io.IOException) MutableCompositeComponent(artisynth.core.modelbase.MutableCompositeComponent) Component(java.awt.Component) ModelComponent(artisynth.core.modelbase.ModelComponent) CompositeComponent(artisynth.core.modelbase.CompositeComponent) JComponent(javax.swing.JComponent) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty) IOException(java.io.IOException)

Example 40 with Property

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

the class ControlPanel method writeWidget.

public void writeWidget(PrintWriter pw, Component comp, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
    String aliasOrName = ClassAliases.getAliasOrName(comp.getClass());
    if (!(comp instanceof LabeledComponentBase)) {
        pw.println(aliasOrName + " [ ]");
    } else {
        LabeledComponentBase widget = (LabeledComponentBase) comp;
        pw.println(aliasOrName);
        pw.print("[ ");
        IndentingPrintWriter.addIndentation(pw, 2);
        Property prop = PropertyWidget.getProperty(widget);
        if (prop != null) {
            String propPath = ComponentUtils.getWritePropertyPathName(prop, ancestor);
            if (propPath != null) {
                pw.println("property=" + propPath);
            }
        }
        widget.getAllPropertyInfo().writeNonDefaultProps(widget, pw, fmt);
        IndentingPrintWriter.addIndentation(pw, -2);
        pw.println("]");
    }
}
Also used : LabeledComponentBase(maspack.widgets.LabeledComponentBase) Property(maspack.properties.Property) EditingProperty(maspack.properties.EditingProperty)

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