Search in sources :

Example 6 with LabeledComponentBase

use of maspack.widgets.LabeledComponentBase 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 7 with LabeledComponentBase

use of maspack.widgets.LabeledComponentBase 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 8 with LabeledComponentBase

use of maspack.widgets.LabeledComponentBase 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 9 with LabeledComponentBase

use of maspack.widgets.LabeledComponentBase 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)

Example 10 with LabeledComponentBase

use of maspack.widgets.LabeledComponentBase in project artisynth_core by artisynth.

the class ControlPanel method scanWidget.

public void scanWidget(String classNameOrAlias, ReaderTokenizer rtok, Deque<ScanToken> tokens) throws IOException {
    Component comp;
    try {
        comp = (Component) ClassAliases.newInstance(classNameOrAlias, Component.class);
    } catch (Exception e) {
        throw new IOException("Could not instantiate widget " + classNameOrAlias + ", line " + rtok.lineno() + ":\n" + e.getMessage());
    }
    if (!(comp instanceof LabeledComponentBase)) {
        rtok.scanToken('[');
        rtok.scanToken(']');
        tokens.offer(new StringToken("widget", rtok.lineno()));
        tokens.offer(new ObjectToken(comp));
        return;
    }
    LabeledComponentBase widget = (LabeledComponentBase) comp;
    rtok.scanToken('[');
    String propPath = null;
    while (rtok.nextToken() != ']') {
        if (scanAttributeName(rtok, "property")) {
            propPath = rtok.scanQuotedString('"');
        } else if (rtok.tokenIsWord()) {
            String fieldName = rtok.sval;
            if (!ScanWriteUtils.scanProperty(rtok, widget)) {
                System.out.println("Warning: internal widget property '" + fieldName + "' not found for " + widget + "; ignoring");
                widget = null;
                break;
            }
        } else {
            throw new IOException("Unexpected token: " + rtok);
        }
    }
    if (widget != null) {
        tokens.offer(new StringToken("widget", rtok.lineno()));
        if (propPath != null) {
            tokens.offer(new StringToken(propPath, rtok.lineno()));
        }
        tokens.offer(new ObjectToken(widget, rtok.lineno()));
    }
}
Also used : 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) IOException(java.io.IOException)

Aggregations

LabeledComponentBase (maspack.widgets.LabeledComponentBase)12 EditingProperty (maspack.properties.EditingProperty)6 Property (maspack.properties.Property)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 ControlPanel (artisynth.core.gui.ControlPanel)3 Point (java.awt.Point)3 IOException (java.io.IOException)3 Point (artisynth.core.mechmodels.Point)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)2 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)2 Color (java.awt.Color)2 Component (java.awt.Component)2 JComponent (javax.swing.JComponent)2 JFrame (javax.swing.JFrame)2 JPanel (javax.swing.JPanel)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 GenericPropertyHandle (maspack.properties.GenericPropertyHandle)2 RenderProps (maspack.render.RenderProps)2 File (java.io.File)1 JSeparator (javax.swing.JSeparator)1