Search in sources :

Example 1 with GenericPropertyHandle

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

the class ControlPanel method updateReferences.

@Override
public void updateReferences(boolean undo, Deque<Object> undoInfo) {
    super.updateReferences(undo, undoInfo);
    boolean changed = false;
    if (undo) {
        Object obj;
        while ((obj = undoInfo.removeFirst()) != NULL_OBJ) {
            WidgetRemoveInfo info = (WidgetRemoveInfo) obj;
            myPanel.addPropertyWidget(info.myProp, info.myComp, info.myIdx);
            changed = true;
        }
    } else {
        // remove soft references which aren't in the hierarchy any more:
        ArrayList<WidgetRemoveInfo> removeList = new ArrayList<WidgetRemoveInfo>();
        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.isConnected(this, comp)) {
                        removeList.add(new WidgetRemoveInfo(prop, widget, i));
                        changed = true;
                    }
                } else {
                // TODO - handle other cases
                }
            }
        }
        for (WidgetRemoveInfo info : removeList) {
            myPanel.removeWidget(info.myComp);
        }
        undoInfo.addAll(removeList);
        undoInfo.addLast(NULL_OBJ);
    }
    if (changed && myFrame != null) {
        myFrame.pack();
    }
}
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 2 with GenericPropertyHandle

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

Aggregations

ModelComponent (artisynth.core.modelbase.ModelComponent)2 Point (java.awt.Point)2 EditingProperty (maspack.properties.EditingProperty)2 GenericPropertyHandle (maspack.properties.GenericPropertyHandle)2 Property (maspack.properties.Property)2 LabeledComponentBase (maspack.widgets.LabeledComponentBase)2