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.");
}
}
}
});
}
Aggregations