Search in sources :

Example 1 with LabeledControl

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

the class MuscleElementDescListWidget method createControls.

// /**
// * Used to indicate that the muscle bundle was newly created and this agent
// * should provide widgets to set its name and render properties. bundleList
// * should be the component list to which the bundle was added. A null
// * bundleList will disable bundle initialization. Should be called before
// * show() in order to have any effect.
// */
// public void setInitializeBundle (
// ComponentList<MuscleBundle> bundleList) {
// myBundleList = bundleList;
// myInitializeBundle = (bundleList != null);
// }
// private void initializeBundle () {
// // find the most recently added bundle in the list and use
// // that as a reference
// for (int i=myBundleList.size()-1; i>=0; i--) {
// MuscleBundle b = myBundleList.get(i);
// if (b != myBundle) {
// myBundle.setRenderProps(b.getRenderProps());
// return;
// }
// }
// // otherwise, have to initialize in a more ad-hoc way
// RenderProps.setLineRadius (myBundle, getDefaultLineRadius());
// }
private void createControls() {
    Property prop = myFemModel.getProperty("elementWidgetSize");
    if (prop != null && prop instanceof InheritableProperty) {
        myModelWidgetSizeProp = (InheritableProperty) prop;
        mySavedModelWidgetSize = (Double) myModelWidgetSizeProp.get();
        mySavedModelWidgetMode = myModelWidgetSizeProp.getMode();
        myModelWidgetSizeProp.set(0.5);
        LabeledControl widget = (LabeledControl) myContentPane.addWidget(prop);
        widget.setLabelText("modelElementSize");
        widget.addValueChangeListener(myRerenderListener);
    } else {
        System.out.println("Warning: property 'elementWidgetSize' not found in FemModel3d");
    }
    prop = myBundle.getProperty("elementWidgetSize");
    if (prop != null && prop instanceof InheritableProperty) {
        myBundleWidgetSizeProp = (InheritableProperty) prop;
        mySavedBundleWidgetSize = (Double) myBundleWidgetSizeProp.get();
        mySavedBundleWidgetMode = myBundleWidgetSizeProp.getMode();
        myBundleWidgetSizeProp.set(0.6);
        LabeledControl widget = (LabeledControl) myContentPane.addWidget(prop);
        widget.setLabelText("bundleElementSize");
        widget.addValueChangeListener(myRerenderListener);
    } else {
        System.out.println("Warning: property 'elementWidgetSize' not found in MuscleBundle");
    }
}
Also used : LabeledControl(maspack.widgets.LabeledControl)

Example 2 with LabeledControl

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

the class GeometryInertiaPanel method rebuildGeometryWidgets.

/**
 * Called once at panel creation, and then whenever the geometry type is
 * changed (via the GeometrySelection widget). It rebuilds the panel to
 * include the widgets appropriate to the geometry.
 */
private void rebuildGeometryWidgets(GeometryType type) {
    for (LabeledControl w : myGeometryWidgets) {
        removeWidget(w);
    }
    myGeometryWidgets.clear();
    switch(type) {
        case Box:
            {
                myGeometryWidgets.add(myBoxWidthsField);
                break;
            }
        case Sphere:
            {
                myGeometryWidgets.add(myPointRadiusField);
                myGeometryWidgets.add(myPointSlicesField);
                break;
            }
        case Mesh:
            {
                myGeometryWidgets.add(myMeshFileField);
                myGeometryWidgets.add(myMeshXformWidget.getScaleField());
                myGeometryWidgets.add(myMeshXformWidget.getTranslationField());
                myGeometryWidgets.add(myMeshXformWidget.getRotationField());
                break;
            }
        default:
            {
                throw new InternalErrorException("unimplemented geometry type: " + type);
            }
    }
    int idx = GuiUtils.indexOfComponent(this, myGeometrySelector) + 1;
    for (LabeledControl w : myGeometryWidgets) {
        addWidget(w, idx++);
    }
}
Also used : LabeledControl(maspack.widgets.LabeledControl) InternalErrorException(maspack.util.InternalErrorException)

Example 3 with LabeledControl

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

the class FemModel3dAgent method updateMeshPanel.

private void updateMeshPanel() {
    for (Component comp : meshPropPanel.getWidgets()) {
        if (comp instanceof LabeledControl) {
            ((LabeledControl) comp).removeValueChangeListener(this);
        }
    }
    meshPropPanel.removeAllWidgets();
    scaleField.setValue(1);
    FemMeshType value = (FemMeshType) meshSelector.getValue();
    if (value == FemMeshType.Grid) {
        meshPropPanel.addWidget(gridDimField);
        meshPropPanel.addWidget(gridDivField);
        gridDimField.addValueChangeListener(this);
        gridDivField.addValueChangeListener(this);
        fileCheck = true;
    } else if (value == FemMeshType.Tube) {
        meshPropPanel.addWidget(tubeDimField);
        meshPropPanel.addWidget(tubeDivField);
        tubeDimField.addValueChangeListener(this);
        tubeDivField.addValueChangeListener(this);
        fileCheck = true;
    } else if (value == FemMeshType.Torus) {
        meshPropPanel.addWidget(torusDimField);
        meshPropPanel.addWidget(torusDivField);
        torusDimField.addValueChangeListener(this);
        torusDivField.addValueChangeListener(this);
        fileCheck = true;
    } else if (value == FemMeshType.Sphere) {
        meshPropPanel.addWidget(sphereNodesField);
        meshPropPanel.addWidget(scaleField);
        sphereNodesField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        fileCheck = true;
    } else if (value == FemMeshType.Extrusion) {
        meshPropPanel.addWidget(extrusDepthField);
        meshPropPanel.addWidget(extrusLayersField);
        meshPropPanel.addWidget(extrusFileField);
        meshPropPanel.addWidget(scaleField);
        extrusDepthField.addValueChangeListener(this);
        extrusLayersField.addValueChangeListener(this);
        extrusFileField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        File file = new File(extrusFileField.getStringValue());
        fileCheck = file.isFile();
    } else if (value == FemMeshType.AnsysMesh) {
        meshPropPanel.addWidget(ansysNodeFileField);
        meshPropPanel.addWidget(ansysElemFileField);
        meshPropPanel.addWidget(scaleField);
        ansysNodeFileField.addValueChangeListener(this);
        ansysElemFileField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        File nodeFile = new File(ansysNodeFileField.getStringValue());
        File elemFile = new File(ansysElemFileField.getStringValue());
        fileCheck = nodeFile.isFile() && elemFile.isFile();
    } else if (value == FemMeshType.TetgenMesh) {
        meshPropPanel.addWidget(tetgenNodeFileField);
        meshPropPanel.addWidget(tetgenEleFileField);
        meshPropPanel.addWidget(scaleField);
        tetgenNodeFileField.addValueChangeListener(this);
        tetgenEleFileField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        File nodeFile = new File(tetgenNodeFileField.getStringValue());
        File eleFile = new File(tetgenEleFileField.getStringValue());
        fileCheck = nodeFile.isFile() && eleFile.isFile();
    } else if (value == FemMeshType.UCDMesh) {
        meshPropPanel.addWidget(ucdMeshFileField);
        meshPropPanel.addWidget(scaleField);
        ucdMeshFileField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        File file = new File(ucdMeshFileField.getStringValue());
        fileCheck = file.isFile();
    } else if (value == FemMeshType.SurfaceMesh) {
        meshPropPanel.addWidget(surfaceMeshFileField);
        meshPropPanel.addWidget(scaleField);
        surfaceMeshFileField.addValueChangeListener(this);
        scaleField.addValueChangeListener(this);
        File file = new File(surfaceMeshFileField.getStringValue());
        fileCheck = file.isFile();
    }
    meshPropPanel.repaint();
    myContentPane.repackContainingWindow();
}
Also used : LabeledControl(maspack.widgets.LabeledControl) Component(java.awt.Component) File(java.io.File)

Example 4 with LabeledControl

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

Aggregations

LabeledControl (maspack.widgets.LabeledControl)4 Component (java.awt.Component)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 File (java.io.File)1 IOException (java.io.IOException)1 JComponent (javax.swing.JComponent)1 EditingProperty (maspack.properties.EditingProperty)1 Property (maspack.properties.Property)1 InternalErrorException (maspack.util.InternalErrorException)1 LabeledComponentBase (maspack.widgets.LabeledComponentBase)1