Search in sources :

Example 6 with ValueChangeEvent

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

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

the class FemMuscleDemo method createMusclePanel.

public void createMusclePanel() {
    ControlPanel myControlPanel = new ControlPanel("options", "LiveUpdate");
    FemControlPanel.addMuscleControls(myControlPanel, tissue, myModel);
    myControlPanel.addWidget(tissue, "profile");
    ComponentList<MuscleBundle> muscles = ((FemMuscleModel) tissue).getMuscleBundles();
    for (int i = 0; i < muscles.size(); ++i) {
        DoubleFieldSlider slider = (DoubleFieldSlider) myControlPanel.addWidget("activation [N per Muscle]", this, "models/FemBeam/models/fem/bundles/" + i + ":excitation", 0, 1);
        slider.setRoundingTolerance(0.00001);
        slider.getLabel().setForeground(getMuscleColor(i));
        BooleanSelector checkBox = (BooleanSelector) PropertyWidget.create("", muscles.get(i), "renderProps.visible");
        checkBox.addValueChangeListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent e) {
                rerender();
            }
        });
        slider.add(checkBox);
    }
    for (int i = 0; i < muscles.size(); ++i) {
        BooleanSelector selector = (BooleanSelector) myControlPanel.addWidget("fibres active", this, "models/FemBeam/models/fem/bundles/" + i + ":fibresActive");
        selector.getLabel().setForeground(getMuscleColor(i));
        BooleanSelector checkBox = (BooleanSelector) PropertyWidget.create("", muscles.get(i).getFibres(), "renderProps.visible");
        checkBox.addValueChangeListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent e) {
                rerender();
            }
        });
        selector.add(checkBox);
    }
    addControlPanel(myControlPanel);
}
Also used : MuscleBundle(artisynth.core.femmodels.MuscleBundle) ValueChangeEvent(maspack.widgets.ValueChangeEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) BooleanSelector(maspack.widgets.BooleanSelector) ControlPanel(artisynth.core.gui.ControlPanel) FemControlPanel(artisynth.core.gui.FemControlPanel) FemMuscleModel(artisynth.core.femmodels.FemMuscleModel) Point(artisynth.core.mechmodels.Point) DoubleFieldSlider(maspack.widgets.DoubleFieldSlider)

Example 8 with ValueChangeEvent

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

the class SelectComponentPanelHandler method createPanel.

public void createPanel() {
    myPanel = new JPanel();
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
    ImageIcon comboSelectIcon = GuiUtils.loadIcon(SelectableComponentPanel.class, "icon/downArrow.png");
    mySelectFilterButton = ButtonCreator.createIconicButton(comboSelectIcon, "Set Filter", "Set selection filter", true, false, null);
    componentFilter = new ClassField("", ClassField.All, 15);
    componentFilter.getTextField().setHorizontalAlignment(JTextField.RIGHT);
    componentFilter.setSpacing(0);
    componentFilter.getTextField().addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (e.getModifiersEx() == ButtonMasks.getContextMenuMask()) {
                showFilterPopup();
            }
        }
    });
    componentFilter.addValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent e) {
            doSetComponentFilter((Class) e.getValue());
        }
    });
    GuiUtils.setFixedSize(mySelectFilterButton, 18, 18);
    mySelectFilterButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                showFilterPopup();
            }
        }
    });
    myComponentField = new ComponentField("", 30, myMain);
    // GuiUtils.setFixedSize (parentBtn, 24, 24);
    myPanel.add(Box.createRigidArea(new Dimension(36, 20)));
    myPanel.add(mySelectFilterButton);
    myPanel.add(componentFilter);
    myPanel.add(myComponentField);
    // myPanel.add(componentName);
    // //myPanel.add(selectParent);
    // myPanel.add(parentBtn);
    myFrame.add(myPanel, BorderLayout.SOUTH);
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) ValueChangeEvent(maspack.widgets.ValueChangeEvent) MouseEvent(java.awt.event.MouseEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) ComponentField(artisynth.core.gui.widgets.ComponentField) BoxLayout(javax.swing.BoxLayout) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension) ClassField(artisynth.core.gui.widgets.ClassField)

Example 9 with ValueChangeEvent

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

the class ComponentPropertyField method addPropertySelector.

protected void addPropertySelector() {
    myPropertySelector = new StringSelector("", new String[] { nullString });
    myPropertySelector.setValue(nullString);
    myPropertySelector.addValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent e) {
            setValueFromPropertySelector();
        }
    });
    myPropertiesAllowed = true;
    addMajorComponent(myPropertySelector);
}
Also used : ValueChangeEvent(maspack.widgets.ValueChangeEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) StringSelector(maspack.widgets.StringSelector)

Aggregations

ValueChangeEvent (maspack.widgets.ValueChangeEvent)9 ValueChangeListener (maspack.widgets.ValueChangeListener)5 ValueCheckListener (maspack.widgets.ValueCheckListener)4 StringHolder (maspack.util.StringHolder)3 BooleanSelector (maspack.widgets.BooleanSelector)3 PropertyDialog (maspack.widgets.PropertyDialog)3 Point (java.awt.Point)2 File (java.io.File)2 BoxLayout (javax.swing.BoxLayout)2 DoubleField (maspack.widgets.DoubleField)2 RenderPropsPanel (maspack.widgets.RenderPropsPanel)2 StringField (maspack.widgets.StringField)2 Main (artisynth.core.driver.Main)1 FemMuscleModel (artisynth.core.femmodels.FemMuscleModel)1 MuscleBundle (artisynth.core.femmodels.MuscleBundle)1 ControlPanel (artisynth.core.gui.ControlPanel)1 FemControlPanel (artisynth.core.gui.FemControlPanel)1 ClassField (artisynth.core.gui.widgets.ClassField)1 ComponentField (artisynth.core.gui.widgets.ComponentField)1 PropertyField (artisynth.core.gui.widgets.PropertyField)1