Search in sources :

Example 1 with WidgetDialog

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

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

the class MuscleBundleEditor method addElementsNearFibres.

private void addElementsNearFibres(MuscleBundle bundle) {
    WidgetDialog dialog = WidgetDialog.createDialog(myMain.getFrame(), "Specify fibre distance", "Set");
    DoubleField widget = new DoubleField("distance:", myLastElementFibreDist);
    widget.setRange(0, Double.POSITIVE_INFINITY);
    dialog.addWidget(widget);
    GuiUtils.locateCenter(dialog, myMain.getFrame());
    dialog.setVisible(true);
    if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
        double dist = widget.getDoubleValue();
        LinkedList<MuscleElementDesc> list = bundle.getNewElementsNearFibres(dist);
        AddComponentsCommand cmd = new AddComponentsCommand("Add near elements", list, bundle.getElements());
        myMain.getUndoManager().saveStateAndExecute(cmd);
        myLastElementFibreDist = dist;
    }
}
Also used : WidgetDialog(maspack.widgets.WidgetDialog) DoubleField(maspack.widgets.DoubleField) MuscleElementDesc(artisynth.core.femmodels.MuscleElementDesc)

Example 3 with WidgetDialog

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

the class MenuBarHandler method selectClass.

private Class<?> selectClass(String existingClassName) {
    // ClassDialog dialog =
    // ClassDialog.createDialog (
    // myFrame, "Choose model class", "Load", "class", existingClassName);
    WidgetDialog dialog = WidgetDialog.createDialog(myFrame, "Choose model class", "Load");
    // find all instances of 'RootModel' and create an AutoComplete test field
    ArrayList<String> demoClassNames = ClassFinder.findClassNames("artisynth.models", RootModel.class);
    AutoCompleteStringField widget = new AutoCompleteStringField("class:", lastSelectedClassName, 30, demoClassNames);
    // widget.addValueCheckListener (
    // new ValueCheckListener() {
    // public Object validateValue(ValueChangeEvent e, StringHolder errMsg) {
    // String className = (String)e.getValue();
    // if (className != null || !className.equals("")) {
    // Class type = getClassFromName (className);
    // if (type == null) {
    // return PropertyUtils.illegalValue (
    // "class not found", errMsg);
    // }
    // if (!RootModel.class.isAssignableFrom (type)) {
    // return PropertyUtils.illegalValue (
    // "class not an instance of RootModel", errMsg);
    // }
    // }
    // return PropertyUtils.validValue (className, errMsg);
    // }
    // });
    dialog.setValidator(new WidgetDialog.Validator() {

        public String validateSettings(PropertyPanel panel) {
            StringField widget = (StringField) panel.getWidgets()[0];
            String className = widget.getStringValue();
            if (className != null) {
                Class<?> type = getClassFromName(className);
                if (type == null) {
                    return "class not found";
                }
                if (!RootModel.class.isAssignableFrom(type)) {
                    return "class not an instance of RootModel";
                }
            }
            return null;
        }
    });
    dialog.addWidget(widget);
    GuiUtils.locateCenter(dialog, myFrame);
    dialog.setVisible(true);
    if (dialog.getReturnValue() == OptionPanel.OK_OPTION) {
        String className = widget.getStringValue();
        if (className != null && !className.equals("")) {
            lastSelectedClassName = className;
            return getClassFromName(className);
        }
    }
    return null;
}
Also used : WidgetDialog(maspack.widgets.WidgetDialog) AutoCompleteStringField(maspack.widgets.AutoCompleteStringField) AutoCompleteStringField(maspack.widgets.AutoCompleteStringField) StringField(maspack.widgets.StringField) PropertyPanel(maspack.widgets.PropertyPanel)

Aggregations

WidgetDialog (maspack.widgets.WidgetDialog)3 StringField (maspack.widgets.StringField)2 Main (artisynth.core.driver.Main)1 MuscleElementDesc (artisynth.core.femmodels.MuscleElementDesc)1 RootModel (artisynth.core.workspace.RootModel)1 Point (java.awt.Point)1 File (java.io.File)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 AutoCompleteStringField (maspack.widgets.AutoCompleteStringField)1 DoubleField (maspack.widgets.DoubleField)1 PropertyPanel (maspack.widgets.PropertyPanel)1 ValueChangeEvent (maspack.widgets.ValueChangeEvent)1 ValueCheckListener (maspack.widgets.ValueCheckListener)1