Search in sources :

Example 1 with HasCalculatorParams

use of edu.cmu.tetradapp.model.HasCalculatorParams in project tetrad by cmu-phil.

the class CalculatorAction method actionPerformed.

/**
 * Launches the calculator editoir.
 */
public void actionPerformed(ActionEvent e) {
    final CalculatorEditor editor = new CalculatorEditor();
    Parameters params = wrapper.getParams();
    if (params instanceof HasCalculatorParams) {
        params = ((HasCalculatorParams) params).getCalculatorParams();
    }
    editor.setParams(params);
    editor.setParentModels(new Object[] { wrapper });
    editor.setup();
    EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Save", true, dataEditor);
    DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
    editorWindow.pack();
    editorWindow.setVisible(true);
    editorWindow.addInternalFrameListener(new InternalFrameAdapter() {

        public void internalFrameClosed(InternalFrameEvent e) {
            EditorWindow window = (EditorWindow) e.getSource();
            if (window.isCanceled()) {
                return;
            }
            if (editor.finalizeEdit()) {
                List<String> equations = new ArrayList<>();
                String _displayEquations = Preferences.userRoot().get("calculator_equations", "");
                String[] displayEquations = _displayEquations.split("///");
                for (String equation : displayEquations) {
                    if (equation.contains("$")) {
                        for (Node node : editor.getDataSet().getVariables()) {
                            equations.add(equation.replace("$", node.getName()));
                        }
                    } else {
                        equations.add(equation);
                    }
                }
                String[] eqs = equations.toArray(new String[0]);
                try {
                    Transformation.transform(editor.getDataSet(), eqs);
                } catch (ParseException e1) {
                    throw new IllegalStateException("Parse error while applying equations to dataset.");
                }
            }
        }
    });
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Node(edu.cmu.tetrad.graph.Node) HasCalculatorParams(edu.cmu.tetradapp.model.HasCalculatorParams) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException)

Aggregations

Node (edu.cmu.tetrad.graph.Node)1 Parameters (edu.cmu.tetrad.util.Parameters)1 HasCalculatorParams (edu.cmu.tetradapp.model.HasCalculatorParams)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InternalFrameAdapter (javax.swing.event.InternalFrameAdapter)1 InternalFrameEvent (javax.swing.event.InternalFrameEvent)1