Search in sources :

Example 1 with StringHolder

use of maspack.util.StringHolder in project artisynth_core by artisynth.

the class DistanceGrid method setRenderRanges.

/**
 * Sets the render ranges for this grid. The render ranges control the range
 * of vertices that are rendering along each axis when the grid
 * is being rendered.
 *
 * <p>The format
 * consists of three separate range descriptors, one for each axis.
 * A range descriptor may be '*' (all vertices), 'n:m' (vertices
 * in the index range n to m, inclusive), or 'n' (vertices only at index n).
 * For example:
 * <pre>
 *   "* * *"     - all vertices
 *   "* 7 *"     - all vertices along x and z, and those at index 7 along y
 *   "0 2 3"     - a single vertex at indices (0, 2, 3)
 *   "0:3 4:5 *" - all vertices between indices 0-3 along x, and 4-5 along y
 * </pre>
 * In addition, the single charater "*" also indicates all vertices.
 * @param str render range specification
 * @throws IllegalArgumentException if the range specification is not valid.
 */
public void setRenderRanges(String str) {
    StringHolder errMsg = new StringHolder();
    int[] ranges = parseRenderRanges(str, errMsg);
    if (ranges != null) {
        myRenderRanges = ranges;
        myRobValid = false;
    } else {
        throw new IllegalArgumentException("Error parsing string: " + errMsg.value);
    }
}
Also used : StringHolder(maspack.util.StringHolder)

Example 2 with StringHolder

use of maspack.util.StringHolder in project artisynth_core by artisynth.

the class MenuBarHandler method createStepDisplay.

private DoubleField createStepDisplay() {
    DoubleField display = new DoubleField("step:", 0, "%7.5f");
    display.setToolTipText("maximum step size");
    display.getTextField().setToolTipText("maximum step size");
    // display.setEnabledAll (false);
    display.setColumns(5);
    display.addValueChangeListener(this);
    display.addValueCheckListener(new ValueCheckListener() {

        public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
            double dval = ((Double) e.getValue()).doubleValue();
            if (dval <= 0) {
                return PropertyUtils.illegalValue("value must be positive", errMsg);
            } else {
                return PropertyUtils.validValue(e.getValue(), errMsg);
            }
        }
    });
    return display;
}
Also used : ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) StringHolder(maspack.util.StringHolder) DoubleField(maspack.widgets.DoubleField)

Example 3 with StringHolder

use of maspack.util.StringHolder in project artisynth_core by artisynth.

the class PropertyWidgetDialog method initialize.

private void initialize() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    Container pane = getContentPane();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    LabeledComponentPanel propPanel = new LabeledComponentPanel();
    propPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    // myChooser = new PropertyChooser ("component/property", 30, myMain);
    // myChooser.setAlignmentX (Component.CENTER_ALIGNMENT);
    // myChooser.addValueChangeListener (this);
    // pane.add (Box.createRigidArea (new Dimension (0, 4)));
    // propPanel.addWidget (myChooser);
    myPropField = new PropertyField("component/property", 30, myMain);
    myPropField.setAlignmentX(Component.CENTER_ALIGNMENT);
    myPropField.addValueChangeListener(this);
    propPanel.addWidget(myPropField);
    propPanel.addWidget(new JSeparator());
    mySliderSelector = new BooleanSelector("slider");
    mySliderSelector.addValueChangeListener(this);
    propPanel.addWidget(mySliderSelector);
    myRangeField = new DoubleIntervalField("range", new DoubleInterval(0, 1), "%.6g");
    // new VectorMultiField (
    // "range", new String[] { "min:", "max:" }, new Vector2d (0, 1),
    // "%.6f");
    // myRangeField.setAlignmentX (Component.CENTER_ALIGNMENT);
    propPanel.addWidget(myRangeField);
    myLabelTextField = new StringField("labelText", 20);
    myLabelTextField.setEnabledAll(false);
    myLabelTextField.addValueCheckListener(new ValueCheckListener() {

        public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
            String newName = (String) e.getValue();
            String err = ModelComponentBase.checkName(newName, null);
            if (err != null) {
                err = "Invalid name '" + newName + "': " + err;
                newName = null;
            }
            if (errMsg != null) {
                errMsg.value = err;
            }
            return newName;
        }
    });
    propPanel.addWidget(myLabelTextField);
    myLabelFontColorSelector = new ColorSelector("labelFontColor");
    myLabelFontColorSelector.enableNullColors();
    myLabelFontColorSelector.setValue(null);
    propPanel.addWidget(myLabelFontColorSelector);
    myBackgroundColorSelector = new ColorSelector("backgroundColor");
    myBackgroundColorSelector.enableNullColors();
    myBackgroundColorSelector.setValue(null);
    propPanel.addWidget(myBackgroundColorSelector);
    // sliderPanel.add (myRangeField);
    // pane.add (Box.createRigidArea (new Dimension (0, 4)));
    // pane.add (sliderPanel);
    pane.add(propPanel);
    pane.add(new JSeparator());
    // set slider value here because valueChanged needs some
    // other widgets instantiated.
    mySliderSelector.setValue(false);
    mySliderSelector.setEnabledAll(false);
    OptionPanel options = new OptionPanel("OK Cancel", this);
    myOKButton = options.getButton("OK");
    myOKButton.setEnabled(false);
    options.setAlignmentX(Component.CENTER_ALIGNMENT);
    pane.add(options);
    pack();
}
Also used : BoxLayout(javax.swing.BoxLayout) JSeparator(javax.swing.JSeparator) Container(java.awt.Container) PropertyField(artisynth.core.gui.widgets.PropertyField) ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) StringHolder(maspack.util.StringHolder) BooleanSelector(maspack.widgets.BooleanSelector) DoubleIntervalField(maspack.widgets.DoubleIntervalField) StringField(maspack.widgets.StringField) DoubleInterval(maspack.util.DoubleInterval) LabeledComponentPanel(maspack.widgets.LabeledComponentPanel) ColorSelector(maspack.widgets.ColorSelector) OptionPanel(maspack.widgets.OptionPanel)

Example 4 with StringHolder

use of maspack.util.StringHolder in project artisynth_core by artisynth.

the class TimelineController method getWayPointFromUser.

/**
 * Gets waypoint information from the user and adds the waypoint to
 * the waypoint probe.
 */
public void getWayPointFromUser() {
    DoubleField myTimeField = new DoubleField("Time");
    myTimeField.addValueCheckListener(new ValueCheckListener() {

        public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
            Object val = e.getValue();
            if (val instanceof Double && ((Double) val).doubleValue() <= 0) {
                if (errMsg != null) {
                    errMsg.value = "Time value must be positive";
                }
                return Property.IllegalValue;
            } else {
                if (errMsg != null) {
                    errMsg.value = null;
                }
                return val;
            }
        }
    });
    myTimeField.setVoidValueEnabled(true);
    myTimeField.setValue(Property.VoidValue);
    IntegerField myRepeatField = new IntegerField("Repeat", 1);
    myRepeatField.setRange(1, Integer.MAX_VALUE);
    BooleanSelector myBreakpointSelector = new BooleanSelector("Breakpoint", false);
    PropertyPanel addPanel = new PropertyPanel();
    addPanel.addWidget(myTimeField);
    addPanel.addWidget(myRepeatField);
    addPanel.addWidget(myBreakpointSelector);
    PropertyDialog addDialog = new PropertyDialog(this, "Add Waypoints", addPanel, "OK Cancel");
    addDialog.setModal(true);
    GuiUtils.locateCenter(addDialog, this);
    addDialog.setVisible(true);
    if (addDialog.getReturnValue() == OptionPanel.OK_OPTION && !myTimeField.valueIsVoid()) {
        double t = myTimeField.getDoubleValue();
        for (int i = 1; i <= myRepeatField.getIntValue(); i++) {
            addWayPoint(t * i, myBreakpointSelector.getBooleanValue());
        }
        myToolBar.validateFastForward(myMain.getRootModel());
    }
}
Also used : ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) StringHolder(maspack.util.StringHolder) BooleanSelector(maspack.widgets.BooleanSelector) PropertyDialog(maspack.widgets.PropertyDialog) IntegerField(maspack.widgets.IntegerField) DoubleField(maspack.widgets.DoubleField) WayPoint(artisynth.core.probes.WayPoint) PropertyPanel(maspack.widgets.PropertyPanel)

Example 5 with StringHolder

use of maspack.util.StringHolder in project artisynth_core by artisynth.

the class RigidBody method setDistanceGridRenderRanges.

/**
 * {@inheritDoc}
 */
public void setDistanceGridRenderRanges(String ranges) {
    if (ranges.matches("\\s*\\*\\s*") || ranges.matches("\\s*\\*\\s+\\*\\s+\\*\\s*")) {
        myDistanceGridRenderRanges = "* * *";
        if (mySDGrid != null) {
            mySDGrid.setRenderRanges(ranges);
        }
    } else {
        DistanceGrid grid = getDistanceGrid();
        StringHolder errMsg = new StringHolder();
        if (grid.parseRenderRanges(ranges, errMsg) == null) {
            throw new IllegalArgumentException("Illegal range spec: " + errMsg.value);
        } else {
            grid.setRenderRanges(ranges);
            myDistanceGridRenderRanges = grid.getRenderRanges();
        }
    }
}
Also used : StringHolder(maspack.util.StringHolder) DistanceGrid(maspack.geometry.DistanceGrid)

Aggregations

StringHolder (maspack.util.StringHolder)6 ValueChangeEvent (maspack.widgets.ValueChangeEvent)3 ValueCheckListener (maspack.widgets.ValueCheckListener)3 BooleanSelector (maspack.widgets.BooleanSelector)2 DoubleField (maspack.widgets.DoubleField)2 PropertyField (artisynth.core.gui.widgets.PropertyField)1 WayPoint (artisynth.core.probes.WayPoint)1 Container (java.awt.Container)1 BoxLayout (javax.swing.BoxLayout)1 JSeparator (javax.swing.JSeparator)1 DistanceGrid (maspack.geometry.DistanceGrid)1 BooleanHolder (maspack.util.BooleanHolder)1 DoubleInterval (maspack.util.DoubleInterval)1 ColorSelector (maspack.widgets.ColorSelector)1 DoubleIntervalField (maspack.widgets.DoubleIntervalField)1 IntegerField (maspack.widgets.IntegerField)1 LabeledComponentPanel (maspack.widgets.LabeledComponentPanel)1 OptionPanel (maspack.widgets.OptionPanel)1 PropertyDialog (maspack.widgets.PropertyDialog)1 PropertyPanel (maspack.widgets.PropertyPanel)1