Search in sources :

Example 11 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class ControlPanel method setName.

public void setName(String name) {
    super.setName(name);
    if (myFrame != null) {
        myFrame.setTitle(name == null ? "panel " + getNumber() : name);
        RootModel root = Main.getMain().getRootModel();
        if (root != null) {
            JTabbedPane tabbedPane = root.getControlPanelTabs();
            if (tabbedPane != null) {
                int tabIdx = tabbedPane.indexOfComponent(myFrame.getContentPane());
                if (tabIdx > -1) {
                    tabbedPane.setTitleAt(tabIdx, myFrame.getTitle());
                }
            }
        }
    }
}
Also used : RootModel(artisynth.core.workspace.RootModel) JTabbedPane(javax.swing.JTabbedPane) Point(java.awt.Point)

Example 12 with RootModel

use of artisynth.core.workspace.RootModel 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 13 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class Fem3dMarkerAgent method getPrototypeMap.

protected HashMap<Class, ModelComponent> getPrototypeMap() {
    RootModel root = myMain.getRootModel();
    if (root != null && root != myLastRootModel) {
        myPrototypeMap = new HashMap<Class, ModelComponent>();
        myLastRootModel = root;
    }
    return myPrototypeMap;
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 14 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class MuscleElementDescListWidget method getPrototypeMap.

protected HashMap<Class, ModelComponent> getPrototypeMap() {
    RootModel root = myMain.getRootModel();
    if (root != null && root != myLastRootModel) {
        myPrototypeMap = new HashMap<Class, ModelComponent>();
        myLastRootModel = root;
    }
    return myPrototypeMap;
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 15 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class UndoManager method getModelState.

public CompositeState getModelState() {
    CompositeState state = null;
    RootModel rootModel = Main.getMain().getRootModel();
    if (rootModel != null) {
        state = (CompositeState) rootModel.createState(null);
        rootModel.getState(state);
    }
    return state;
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Aggregations

RootModel (artisynth.core.workspace.RootModel)44 ModelComponent (artisynth.core.modelbase.ModelComponent)10 InternalErrorException (maspack.util.InternalErrorException)7 IOException (java.io.IOException)6 WayPoint (artisynth.core.probes.WayPoint)4 FileNotFoundException (java.io.FileNotFoundException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Probe (artisynth.core.probes.Probe)3 WayPointProbe (artisynth.core.probes.WayPointProbe)3 File (java.io.File)3 Property (maspack.properties.Property)3 ControlPanel (artisynth.core.gui.ControlPanel)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)2 TracingProbe (artisynth.core.probes.TracingProbe)2 Point (java.awt.Point)2 JFileChooser (javax.swing.JFileChooser)2 JMenuItem (javax.swing.JMenuItem)2 JSeparator (javax.swing.JSeparator)2 CompositeProperty (maspack.properties.CompositeProperty)2 ArgParser (argparser.ArgParser)1