Search in sources :

Example 1 with ValueChangeEvent

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

the class MeshCollisionViewer method createRenderPropsPanel.

private void createRenderPropsPanel(PolygonalMesh mesh) {
    PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(mesh.getRenderProps())), "OK Cancel");
    dialog.locateRight(this);
    dialog.addGlobalValueChangeListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent e) {
            viewer.rerender();
        }
    });
    dialog.setVisible(true);
}
Also used : ValueChangeEvent(maspack.widgets.ValueChangeEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) PropertyDialog(maspack.widgets.PropertyDialog) RenderPropsPanel(maspack.widgets.RenderPropsPanel)

Example 2 with ValueChangeEvent

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

the class MeshViewer method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.equals("Edit render props")) {
        PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(myRenderProps)), "OK Cancel");
        dialog.locateRight(this);
        dialog.addGlobalValueChangeListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent e) {
                for (MeshBase mesh : myMeshes) {
                    mesh.setRenderProps(myRenderProps);
                }
                viewer.rerender();
            }
        });
        myPopupManager.registerDialog(dialog);
        dialog.setVisible(true);
    } else if (cmd.equals("Edit viewer props")) {
        PropertyDialog dialog = myPopupManager.createPropertyDialog("OK Cancel");
        dialog.setVisible(true);
    } else if (cmd.equals("Quit")) {
        exit(0);
    } else if (cmd.equals("Load mesh ...")) {
        int retVal = myMeshChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myMeshChooser.getSelectedFile();
            loadMesh(file);
        }
    } else if (cmd.equals("Save mesh ...")) {
        int retVal = myMeshChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myMeshChooser.getSelectedFile();
            saveMesh(file);
        }
    } else if (cmd.equals("Show mesh selector")) {
        if (myMeshSelector == null) {
            createMeshSelector();
            myMeshSelector.setSelected(myMeshCursor);
        }
        myMeshSelector.setLocationRelativeTo(this);
        myMeshSelector.setVisible(true);
    } else if (cmd.equals("Hide mesh selector")) {
        myMeshSelector.setVisible(false);
    } else if (cmd.equals("Show property dialog ...")) {
        setPropertyDialogVisible(true);
    } else if (cmd.equals("Hide property dialog")) {
        setPropertyDialogVisible(false);
    } else if (cmd.equals("Background color")) {
        setBackgroundColor();
    } else if (cmd.equals("Perspective view")) {
        viewer.setOrthographicView(false);
    } else if (cmd.equals("Orthographic view")) {
        viewer.setOrthographicView(true);
    }
}
Also used : ValueChangeEvent(maspack.widgets.ValueChangeEvent) ValueChangeListener(maspack.widgets.ValueChangeListener) PropertyDialog(maspack.widgets.PropertyDialog) RenderPropsPanel(maspack.widgets.RenderPropsPanel) MeshBase(maspack.geometry.MeshBase) File(java.io.File) Point(java.awt.Point)

Example 3 with ValueChangeEvent

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

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

the class ControlPanel method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String actionCmd = e.getActionCommand();
    if (actionCmd.equals("add widget")) {
        myPanel.actionPerformed(e);
    } else if (actionCmd.equals("set name")) {
        WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "set name", "Set");
        StringField widget = new StringField("name:", getName(), 20);
        widget.addValueCheckListener(new ValueCheckListener() {

            public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
                String name = (String) e.getValue();
                if (name != null && name.length() == 0) {
                    return null;
                }
                errMsg.value = ModelComponentBase.checkName(name, null);
                if (errMsg.value != null) {
                    return Property.IllegalValue;
                } else {
                    return name;
                }
            }
        });
        dialog.addWidget(widget);
        GuiUtils.locateVertically(dialog, myFrame, GuiUtils.BELOW);
        GuiUtils.locateHorizontally(dialog, myFrame, GuiUtils.CENTER);
        dialog.setVisible(true);
        if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
            String name = (String) widget.getValue();
            setName(name);
        }
    } else if (actionCmd.equals("save as ...")) {
        Main main = Main.getMain();
        RootModel root = main.getRootModel();
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(main.getModelDirectory());
        int retVal = chooser.showSaveDialog(myFrame);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            try {
                ComponentUtils.saveComponent(file, this, new NumberFormat("%.6g"), root);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(myFrame, "Error saving file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
            main.setModelDirectory(chooser.getCurrentDirectory());
        }
    } else if (actionCmd.equals("merge panel")) {
        Main main = Main.getMain();
        main.getRootModel().mergeControlPanel(true, this);
    } else if (actionCmd.equals("separate panel")) {
        Main main = Main.getMain();
        main.getRootModel().mergeControlPanel(false, this);
    } else {
        throw new InternalErrorException("Unknown action: " + actionCmd);
    }
}
Also used : WidgetDialog(maspack.widgets.WidgetDialog) RootModel(artisynth.core.workspace.RootModel) Point(java.awt.Point) IOException(java.io.IOException) ValueCheckListener(maspack.widgets.ValueCheckListener) ValueChangeEvent(maspack.widgets.ValueChangeEvent) JFileChooser(javax.swing.JFileChooser) StringField(maspack.widgets.StringField) Main(artisynth.core.driver.Main) File(java.io.File)

Example 5 with ValueChangeEvent

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

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