Search in sources :

Example 6 with SessionNodeWrapper

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

the class SessionWrappers method getNewModelNode.

private static SessionNodeWrapper getNewModelNode(String nextButtonType, String name) {
    if (nextButtonType == null) {
        throw new NullPointerException("Next button type must be a " + "non-null string.");
    }
    Class[] modelClasses = getModelClasses(nextButtonType);
    SessionNode newNode = new SessionNode(nextButtonType, name, modelClasses);
    SessionNodeWrapper nodeWrapper = new SessionNodeWrapper(newNode);
    nodeWrapper.setButtonType(nextButtonType);
    return nodeWrapper;
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 7 with SessionNodeWrapper

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

the class ConstructTemplateAction method addNode.

private Node addNode(String nodeType, String nodeName, int centerX, int centerY) {
    SessionNodeWrapper node = getNewModelNode(nodeType, nodeName);
    node.setCenter(centerX, centerY);
    getSessionWrapper().addNode(node);
    return node;
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper)

Example 8 with SessionNodeWrapper

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

the class ConstructTemplateAction method addEdge.

public void addEdge(String nodeName1, String nodeName2) {
    // Retrieve the nodes from the session wrapper.
    Node node1 = getSessionWrapper().getNode(nodeName1);
    Node node2 = getSessionWrapper().getNode(nodeName2);
    // Make sure nodes existed in the session wrapper by these names.
    if (node1 == null) {
        throw new RuntimeException("There was no node by name nodeName1 in " + "the session wrapper: " + nodeName1);
    }
    if (node2 == null) {
        throw new RuntimeException("There was no node by name nodeName2 in " + "the session wrapper: " + nodeName2);
    }
    // Construct an edge.
    SessionNodeWrapper nodeWrapper1 = (SessionNodeWrapper) node1;
    SessionNodeWrapper nodeWrapper2 = (SessionNodeWrapper) node2;
    Edge edge = new Edge(nodeWrapper1, nodeWrapper2, Endpoint.TAIL, Endpoint.ARROW);
    // Add the edge.
    getSessionWrapper().addEdge(edge);
    getSessionWorkbench().revalidate();
    getSessionWorkbench().repaint();
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) Node(edu.cmu.tetrad.graph.Node) SessionNode(edu.cmu.tetrad.session.SessionNode) Edge(edu.cmu.tetrad.graph.Edge)

Example 9 with SessionNodeWrapper

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

the class SessionEditorNode method getPopup.

/**
 * Creates the popup for the node.
 */
private JPopupMenu getPopup() {
    if (popup != null && popup.isShowing()) {
        return popup;
    }
    popup = new JPopupMenu();
    JMenuItem createModel = new JMenuItem("Create Model");
    createModel.setToolTipText("<html>Creates a new model for this node" + "<br>of the type selected.</html>");
    createModel.addActionListener((e) -> {
        try {
            if (getSessionNode().getModel() == null) {
                createModel(false);
            } else {
                Component centeringComp = SessionEditorNode.this;
                JOptionPane.showMessageDialog(centeringComp, "Please destroy the model model first.");
            }
        } catch (Exception e1) {
            Component centeringComp = SessionEditorNode.this;
            JOptionPane.showMessageDialog(centeringComp, "Could not create a model for this box.");
            e1.printStackTrace();
        }
    });
    JMenuItem editModel = new JMenuItem("Edit Model");
    editModel.setToolTipText("<html>Edits the model in this node.</html>");
    editModel.addActionListener((e) -> {
        try {
            if (getSessionNode().getModel() == null) {
                Component centeringComp = SessionEditorNode.this;
                JOptionPane.showMessageDialog(centeringComp, "Sorry, no model has been created yet; there's nothing to edit.");
            } else {
                doDoubleClickAction();
            }
        } catch (Exception e1) {
            Component centeringComp = SessionEditorNode.this;
            JOptionPane.showMessageDialog(centeringComp, "Double click failed. See console for exception.");
            e1.printStackTrace();
        }
    });
    JMenuItem destroyModel = new JMenuItem("Destroy Model");
    destroyModel.setToolTipText("<html>Destroys the model for this node, " + "<br>if it has one, destroying any " + "<br>downstream models as well.</html>");
    destroyModel.addActionListener((e) -> {
        Component centeringComp = SessionEditorNode.this;
        if (getSessionNode().getModel() == null) {
            JOptionPane.showMessageDialog(centeringComp, "Sorry, this box does not contain a model to destroy.");
            return;
        }
        Set<SessionNode> children = getSessionNode().getChildren();
        boolean found = false;
        for (SessionNode child : children) {
            if (child.getModel() != null) {
                found = true;
            }
        }
        if (found) {
            int ret = JOptionPane.showConfirmDialog(centeringComp, "Destroying the model in this box will also destroy models in any boxes\n" + "downstream. Is that OK?", null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (ret != JOptionPane.YES_OPTION) {
                return;
            }
        }
        destroyModel();
    });
    JMenuItem propagateDownstream = new JMenuItem("Propagate changes downstream");
    propagateDownstream.setToolTipText("<html>" + "Fills in this box and downstream boxes with models," + "<br>overwriting any models that already exist.</html>");
    propagateDownstream.addActionListener((e) -> {
        Component centeringComp = SessionEditorNode.this;
        if (getSessionNode().getModel() != null && !getSessionNode().getChildren().isEmpty()) {
            int ret = JOptionPane.showConfirmDialog(centeringComp, "You will be rewriting all downstream models. Is that OK?", "Confirm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (ret != JOptionPane.YES_OPTION) {
                return;
            }
        }
        try {
            createDescendantModels(true);
        } catch (RuntimeException e1) {
            JOptionPane.showMessageDialog(centeringComp, "Could not complete the creation of descendant models.");
            e1.printStackTrace();
        }
    });
    JMenuItem renameBox = new JMenuItem("Rename Box");
    renameBox.setToolTipText("<html>Renames this session box.</html>");
    renameBox.addActionListener((e) -> {
        Component centeringComp = SessionEditorNode.this;
        String name = JOptionPane.showInputDialog(centeringComp, "New name:");
        if (!NamingProtocol.isLegalName(name)) {
            JOptionPane.showMessageDialog(centeringComp, NamingProtocol.getProtocolDescription());
            return;
        }
        SessionNodeWrapper wrapper = (SessionNodeWrapper) getModelNode();
        wrapper.setSessionName(name);
        getSessionDisplayComp().setName(name);
        adjustToModel();
    });
    JMenuItem cloneBox = new JMenuItem("Clone Box");
    cloneBox.setToolTipText("<html>" + "Makes a copy of this session box and its contents. To clone<br>" + "a whole subgraph, or to paste into a different sessions, select<br>" + "the subgraph and use the Copy/Paste gadgets in the Edit menu." + "</html>");
    cloneBox.addActionListener((e) -> {
        firePropertyChange("cloneMe", null, SessionEditorNode.this);
    });
    JMenuItem deleteBox = new JMenuItem("Delete Box");
    deleteBox.setToolTipText("<html>Deletes this box from the workbench</html>");
    deleteBox.addActionListener((e) -> {
        Component centeringComp = SessionEditorNode.this;
        int ret = JOptionPane.showConfirmDialog(centeringComp, "Are you sure you want to delete this box? It contains some work.", null, JOptionPane.YES_NO_OPTION);
        if (ret != JOptionPane.YES_OPTION) {
            return;
        }
        firePropertyChange("deleteNode", null, null);
    });
    popup.add(createModel);
    SessionModel model = getSessionNode().getModel();
    Class modelClass = (model == null) ? determineTheModelClass(getSessionNode()) : model.getClass();
    if (getSessionNode().existsParameterizedConstructor(modelClass)) {
        final ParameterEditor paramEditor = getParameterEditor(modelClass);
        if (paramEditor != null) {
            JMenuItem editSimulationParameters = new JMenuItem("Edit Parameters...");
            editSimulationParameters.setToolTipText("<html>");
            editSimulationParameters.addActionListener((e) -> {
                Parameters param = getSessionNode().getParam(modelClass);
                Object[] arguments = getSessionNode().getModelConstructorArguments(modelClass);
                if (param != null) {
                    try {
                        editParameters(modelClass, param, arguments);
                        int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), "Should I overwrite the contents of this box and all delete the contents\n" + "of all boxes downstream?", "Double check...", JOptionPane.YES_NO_OPTION);
                        if (ret == JOptionPane.YES_OPTION) {
                            getSessionNode().destroyModel();
                            getSessionNode().createModel(modelClass, true);
                        }
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
            popup.add(editSimulationParameters);
        }
    }
    // final SessionNode thisNode = getSessionNode();
    // 
    // //        popup.add(getConsistentParentMenuItems(getConsistentParentBoxTypes(thisNode)));
    // //        popup.add(getConsistentChildBoxMenus(getConsistentChildBoxTypes(thisNode, null)));
    // 
    // addConsistentParentMenuItems(popup, getConsistentParentBoxTypes(thisNode));
    // addConsistentChildBoxMenus(popup, getConsistentChildBoxTypes(thisNode, null));
    // 
    // popup.addSeparator();
    popup.add(createModel);
    popup.add(editModel);
    popup.add(destroyModel);
    popup.addSeparator();
    popup.add(renameBox);
    popup.add(cloneBox);
    popup.add(deleteBox);
    popup.addSeparator();
    addEditLoggerSettings(popup);
    popup.add(propagateDownstream);
    return popup;
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) SessionNode(edu.cmu.tetrad.session.SessionNode) JPopupMenu(javax.swing.JPopupMenu) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) Point(java.awt.Point) SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) UnlistedSessionModel(edu.cmu.tetradapp.model.UnlistedSessionModel) SessionModel(edu.cmu.tetrad.session.SessionModel) FinalizingParameterEditor(edu.cmu.tetradapp.editor.FinalizingParameterEditor) ParameterEditor(edu.cmu.tetradapp.editor.ParameterEditor) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 10 with SessionNodeWrapper

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

the class SessionWrappers method addNode.

public static Node addNode(SessionWrapper sessionWrapper, String nodeType, String nodeName, int centerX, int centerY) {
    SessionNodeWrapper node = getNewModelNode(nodeType, nodeName);
    node.setCenter(centerX, centerY);
    sessionWrapper.addNode(node);
    return node;
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper)

Aggregations

SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)17 SessionNode (edu.cmu.tetrad.session.SessionNode)11 Component (java.awt.Component)5 Point (java.awt.Point)5 JComponent (javax.swing.JComponent)5 Edge (edu.cmu.tetrad.graph.Edge)3 JMenuItem (javax.swing.JMenuItem)3 Node (edu.cmu.tetrad.graph.Node)2 FinalizingParameterEditor (edu.cmu.tetradapp.editor.FinalizingParameterEditor)2 ParameterEditor (edu.cmu.tetradapp.editor.ParameterEditor)2 JPopupMenu (javax.swing.JPopupMenu)2 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)1 SessionModel (edu.cmu.tetrad.session.SessionModel)1 Parameters (edu.cmu.tetrad.util.Parameters)1 TetradLoggerConfig (edu.cmu.tetrad.util.TetradLoggerConfig)1 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)1 LinkedList (java.util.LinkedList)1 JDialog (javax.swing.JDialog)1