use of javax.swing.event.InternalFrameEvent 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.");
}
}
}
});
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class GraphEditor method createGraphMenu.
private JMenu createGraphMenu() {
JMenu graph = new JMenu("Graph");
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
graph.addSeparator();
JMenuItem correlateExogenous = new JMenuItem("Correlate Exogenous Variables");
JMenuItem uncorrelateExogenous = new JMenuItem("Uncorrelate Exogenous Variables");
graph.add(correlateExogenous);
graph.add(uncorrelateExogenous);
graph.addSeparator();
correlateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
correlateExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
uncorrelateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
uncorrelationExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
JMenuItem randomGraph = new JMenuItem("Random Graph");
graph.add(randomGraph);
randomGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final GraphParamsEditor editor = new GraphParamsEditor();
editor.setParams(parameters);
EditorWindow editorWindow = new EditorWindow(editor, "Edit Random Graph Parameters", "Done", false, GraphEditor.this);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e1) {
EditorWindow window = (EditorWindow) e1.getSource();
if (window.isCanceled()) {
return;
}
RandomUtil.getInstance().setSeed(new Date().getTime());
Graph graph1 = edu.cmu.tetradapp.util.GraphUtils.makeRandomGraph(getGraph(), parameters);
boolean addCycles = parameters.getBoolean("randomAddCycles", false);
if (addCycles) {
int newGraphNumMeasuredNodes = parameters.getInt("newGraphNumMeasuredNodes", 10);
int newGraphNumEdges = parameters.getInt("newGraphNumEdges", 10);
graph1 = GraphUtils.cyclicGraph2(newGraphNumMeasuredNodes, newGraphNumEdges, 8);
}
getWorkbench().setGraph(graph1);
}
});
}
});
graph.addSeparator();
// JMenuItem meekOrient = new JMenuItem("Meek Orientation");
// graph.add(meekOrient);
// meekOrient.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// MeekRules rules = new MeekRules();
// rules.orientImplied(getGraph());
// getWorkbench().setGraph(getGraph());
// firePropertyChange("modelChanged", null, null);
// }
// }
// );
graph.addSeparator();
graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
graph.add(new JMenuItem(new SelectLatentsAction(getWorkbench())));
// graph.add(action);
return graph;
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class EditorWindow method doSetup.
/**
* Constructs the dialog.
*/
private void doSetup(JPanel editor, boolean cancellable) {
this.editor = editor;
addInternalFrameListener(new InternalFrameAdapter() {
public void InternalFrameClosing(InternalFrameEvent evt) {
canceled = true;
closeDialog();
}
});
okButton = null;
if (buttonName != null) {
okButton = new JButton(buttonName);
}
JButton cancelButton = new JButton("Cancel");
if (okButton != null) {
okButton.setPreferredSize(new Dimension(100, 50));
okButton.addActionListener(new OkListener());
}
cancelButton.setPreferredSize(new Dimension(80, 50));
cancelButton.addActionListener(new CancelListener());
Box b0 = Box.createVerticalBox();
Box b = Box.createHorizontalBox();
b.add(Box.createHorizontalGlue());
if (okButton != null) {
b.add(okButton);
}
b.add(Box.createHorizontalStrut(5));
if (cancellable) {
b.add(cancelButton);
}
b.add(Box.createHorizontalGlue());
b0.add(editor);
b0.add(b);
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int width = Math.min(b0.getPreferredSize().width + 50, screensize.width);
int height = Math.min(b0.getPreferredSize().height + 50, screensize.height - 100);
if (!(editor instanceof DoNotScroll) && (b0.getPreferredSize().width > width || b0.getPreferredSize().height > height)) {
JScrollPane scroll = new JScrollPane(b0);
scroll.setPreferredSize(new Dimension(width, height));
getContentPane().add(scroll);
} else {
getContentPane().add(b0);
}
// Set the ok button so that pressing enter activates it.
// jdramsey 5/5/02
JRootPane root = SwingUtilities.getRootPane(this);
if (root != null) {
root.setDefaultButton(okButton);
}
pack();
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class GeneralizedSemImGraphicalEditor method beginNodeEdit.
// ============================================PRIVATE=====================================================//
private void beginNodeEdit(final Node node) {
if (launchedEditors.keySet().contains(node)) {
launchedEditors.get(node).moveToFront();
return;
}
final GeneralizedExpressionParameterizer paramEditor = new GeneralizedExpressionParameterizer(semIm, node);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(paramEditor, BorderLayout.CENTER);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
final EditorWindow editorWindow = new EditorWindow(panel, "Parameter Properties", "OK", true, workbench());
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
launchedEditors.put(node, editorWindow);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
if (!editorWindow.isCanceled()) {
semIm.setSubstitutions(paramEditor.getParameterValues());
refreshLabels();
launchedEditors.remove(node);
firePropertyChange("modelChanged", null, null);
}
}
});
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class GeneralizedSemPmParamsEditor method beginParamEdit.
private void beginParamEdit(final String parameter, final JLabel label, JComponent centering) {
if (launchedEditors.keySet().contains(parameter)) {
launchedEditors.get(parameter).moveToFront();
return;
}
final GeneralizedExpressionEditor paramEditor = new GeneralizedExpressionEditor(semPm, parameter);
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(paramEditor, BorderLayout.CENTER);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
final EditorWindow editorWindow = new EditorWindow(panel, "Edit Expression", "OK", true, centering);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
launchedEditors.put(parameter, editorWindow);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
if (!editorWindow.isCanceled()) {
String expressionString = paramEditor.getExpressionString();
try {
semPm.setParameterExpression(parameter, expressionString);
// label.setText(parameter + " ~ " + semPm().getParameterExpressionString(parameter));
refreshLabels();
} catch (ParseException e) {
// This is an expression that's been vetted by the expression editor.
e.printStackTrace();
launchedEditors.remove(parameter);
throw new RuntimeException("The expression editor returned an unparseable string: " + expressionString, e);
} catch (IllegalArgumentException e) {
JOptionPane.showMessageDialog(panel, e.getMessage());
launchedEditors.remove(parameter);
}
firePropertyChange("modelChanged", null, null);
}
launchedEditors.remove(parameter);
}
});
}
Aggregations