Search in sources :

Example 6 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionWrapper method removeNode.

/**
 * Removes a node from the workbench.
 *
 * @param node the node to be removed.
 * @return true if the node was removed, false if not.
 */
public boolean removeNode(Node node) {
    if (sessionNodeWrappers.contains(node)) {
        for (Edge edge : getEdges(node)) {
            removeEdge(edge);
        }
        SessionNodeWrapper wrapper = (SessionNodeWrapper) node;
        SessionNode sessionNode = wrapper.getSessionNode();
        try {
            this.session.removeNode(sessionNode);
            sessionNodeWrappers.remove(wrapper);
            getPropertyChangeSupport().firePropertyChange("nodeRemoved", node, null);
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }
    return false;
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 7 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionWrapper method removeEdge.

/**
 * Removes an edge from the workbench.
 */
public boolean removeEdge(Edge edge) {
    if (sessionEdges.contains(edge)) {
        SessionNodeWrapper nodeAWrapper = (SessionNodeWrapper) edge.getNode1();
        SessionNodeWrapper nodeBWrapper = (SessionNodeWrapper) edge.getNode2();
        SessionNode nodeA = nodeAWrapper.getSessionNode();
        SessionNode nodeB = nodeBWrapper.getSessionNode();
        boolean removed = nodeB.removeParent(nodeA);
        if (removed) {
            sessionEdges.remove(edge);
            getPropertyChangeSupport().firePropertyChange("edgeRemoved", edge, null);
            return true;
        }
    }
    return false;
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 8 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionEditorNode method addListeners.

private void addListeners(final SessionEditorNode sessionEditorNode, final SessionNodeWrapper modelNode) {
    // Add a mouse listener for popups.
    sessionEditorNode.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
                toolTipManager.setInitialDelay(750);
                sessionEditorNode.getPopup().show(sessionEditorNode, e.getX(), e.getY());
            }
            e.consume();
        }
    });
    // sessionEditorNode.addMouseMotionListener(new MouseMotionAdapter() {
    // public void mouseMoved(MouseEvent e) {
    // Point p = e.getPoint();
    // if (p.getX() > 40 && p.getY() > 40) {
    // ToolTipManager toolTipManager =
    // ToolTipManager.sharedInstance();
    // toolTipManager.setInitialDelay(750);
    // JPopupMenu popup = sessionEditorNode.getPopup();
    // 
    // if (!popup.isShowing()) {
    // popup.show(sessionEditorNode, e.getX(), e.getY());
    // }
    // }
    // }
    // });
    sessionEditorNode.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentMoved(ComponentEvent e) {
            sessionEditorNode.getSimulationStudy().getSession().setSessionChanged(true);
        }
    });
    SessionNode sessionNode = modelNode.getSessionNode();
    sessionNode.addSessionListener(new SessionAdapter() {

        @Override
        public void modelCreated(SessionEvent sessionEvent) {
            sessionEditorNode.adjustToModel();
            // 5/18/02
            if (sessionEditorNode.spawnedEditor() != null) {
                EditorWindow editorWindow = sessionEditorNode.spawnedEditor();
                editorWindow.closeDialog();
            }
        }

        @Override
        public void modelDestroyed(SessionEvent sessionEvent) {
            sessionEditorNode.adjustToModel();
            // the getModel editor window is closed. jdramsey 5/18/02
            if (sessionEditorNode.spawnedEditor() != null) {
                EditorWindow editorWindow = sessionEditorNode.spawnedEditor();
                editorWindow.closeDialog();
            }
        }

        @Override
        public void modelUnclear(SessionEvent sessionEvent) {
            try {
                if (simulationStudy == null) {
                    boolean created = sessionEditorNode.createModel(false);
                    if (!created) {
                        return;
                    }
                    sessionEditorNode.adjustToModel();
                }
            } catch (Exception e) {
                String message = e.getMessage();
                message = "I could not make a model for this box, sorry. Maybe the \n" + "parents aren't right or have not been constructed yet.";
                e.printStackTrace();
                // throw new IllegalArgumentException("I could not make a model for this box, sorry. Maybe the \n" +
                // "parents aren't right or have not been constructed yet.");
                JOptionPane.showMessageDialog(sessionEditorNode, message);
            }
        }
    });
}
Also used : ToolTipManager(javax.swing.ToolTipManager) SessionEvent(edu.cmu.tetrad.session.SessionEvent) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) SessionNode(edu.cmu.tetrad.session.SessionNode) ComponentEvent(java.awt.event.ComponentEvent) SessionAdapter(edu.cmu.tetrad.session.SessionAdapter) ComponentAdapter(java.awt.event.ComponentAdapter) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow)

Example 9 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionEditorNode method addEditLoggerSettings.

// private void addConsistentChildBoxMenus(JPopupMenu menu, List<String> consistentChildBoxes) {
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String text = menuItem.getText();
// String[] tokens = text.split(" ");
// String type = tokens[1];
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, type);
// }
// });
// 
// menu.add(menuItem);
// }
// }
// private JMenu addConsistentChildBoxMenus(List<String> consistentChildBoxes) {
// JMenu newChildren = new JMenu("New Child Box");
// 
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, menuItem.getText());
// }
// });
// 
// 
// 
// newChildren.add(menuItem);
// }
// return newChildren;
// }
// private JMenu addConsistentParentMenuItems(JPopupMenu menu, List<SessionNode> consistentParentNodes) {
// final JMenu newParents = new JMenu("New Parent Box");
// 
// for (final SessionNode node : consistentParentNodes) {
// final JMenuItem menuItem = new JMenuItem("Add Links: " + node.getDisplayName());
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String displayName1 = node.getDisplayName();
// String displayName2 = SessionEditorNode.this.getSessionNode().getDisplayName();
// new ConstructTemplateAction("Test").addEdge(displayName1, displayName2);
// }
// });
// 
// menu.add(menuItem);
// }
// 
// return newParents;
// }
// private List<String> getConsistentChildBoxTypes(SessionNode thisNode, SessionModel model) {
// List<String> consistentChildBoxes = new ArrayList<>();
// 
// List<Node> nodes = sessionWorkbench.getSessionWrapper().getNodes();
// List<SessionNode> sessionNodes = new ArrayList<>();
// for (Node node : nodes) sessionNodes.add(((SessionNodeWrapper) node).getSessionNode());
// 
// Set<String> strings = TetradApplicationConfig.getInstance().getConfigs().keySet();
// 
// for (String type : strings) {
// SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
// Class[] modelClasses = config.getModels();
// 
// SessionNode newNode = new SessionNode(modelClasses);
// 
// if (newNode.isConsistentParent(thisNode, sessionNodes)) {
// consistentChildBoxes.add("Add " + type);
// }
// }
// 
// return consistentChildBoxes;
// }
// private List<SessionNode> getConsistentParentBoxTypes(SessionNode thisNode) {
// List<SessionNode> consistentParentBoxes = new ArrayList<>();
// 
// for (Node _node : getSessionWorkbench().getSessionWrapper().getNodes()) {
// SessionNode node = ((SessionNodeWrapper) _node).getSessionNode();
// 
// if (sessionWorkbench.getSessionWrapper().isAncestorOf(thisNode, node)) {
// continue;
// }
// 
// if (!thisNode.getParents().contains(node) && thisNode.isConsistentParent(node)) {
// consistentParentBoxes.add(node);
// }
// }
// 
// return consistentParentBoxes;
// }
/**
 * Adds the "Edit logger" option if applicable.
 */
private void addEditLoggerSettings(JPopupMenu menu) {
    SessionNodeWrapper modelNode = (SessionNodeWrapper) getModelNode();
    SessionNode sessionNode = modelNode.getSessionNode();
    final TetradLoggerConfig config = sessionNode.getLoggerConfig();
    if (config != null) {
        JMenuItem item = new JMenuItem("Edit Logger Settings ...");
        item.addActionListener((e) -> {
            showLogConfig(config);
        });
        menu.add(item);
    }
}
Also used : TetradLoggerConfig(edu.cmu.tetrad.util.TetradLoggerConfig) SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode) JMenuItem(javax.swing.JMenuItem)

Example 10 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionEditorNode method getNotePopup.

/**
 * Creates a popup for a note node.
 *
 * @return - popup
 */
private JPopupMenu getNotePopup() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem renameBox = new JMenuItem("Rename note");
    renameBox.setToolTipText("<html>Renames this note.</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 Note");
    cloneBox.setToolTipText("<html>" + "Makes a copy of this session note 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 Note");
    deleteBox.setToolTipText("<html>Deletes this note from the workbench</html>");
    deleteBox.addActionListener((e) -> {
        if (getSessionNode().getModel() == null) {
            Component centeringComp = SessionEditorNode.this;
            int ret = JOptionPane.showConfirmDialog(centeringComp, "Really delete note?");
            if (ret != JOptionPane.YES_OPTION) {
                return;
            }
        } else {
            Component centeringComp = SessionEditorNode.this;
            int ret = JOptionPane.showConfirmDialog(centeringComp, "<html>" + "Really delete note? Any information it contains will<br>" + "be destroyed." + "</html>");
            if (ret != JOptionPane.YES_OPTION) {
                return;
            }
        }
        firePropertyChange("deleteNode", null, null);
    });
    JMenuItem help = new JMenuItem("Help");
    deleteBox.setToolTipText("<html>Shows help for this box.</html>");
    help.addActionListener((e) -> {
        SessionNodeWrapper sessionNodeWrapper = (SessionNodeWrapper) getModelNode();
        SessionNode sessionNode = sessionNodeWrapper.getSessionNode();
        showInfoBoxForModel(sessionNode, sessionNode.getModelClasses());
    });
    popup.add(renameBox);
    popup.add(cloneBox);
    popup.add(deleteBox);
    popup.addSeparator();
    popup.add(help);
    return popup;
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point)

Aggregations

SessionNode (edu.cmu.tetrad.session.SessionNode)20 SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)9 Component (java.awt.Component)5 JComponent (javax.swing.JComponent)5 Point (java.awt.Point)4 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)3 Parameters (edu.cmu.tetrad.util.Parameters)3 JMenuItem (javax.swing.JMenuItem)3 SessionModel (edu.cmu.tetrad.session.SessionModel)2 EditorWindow (edu.cmu.tetradapp.editor.EditorWindow)2 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)2 JPopupMenu (javax.swing.JPopupMenu)2 Edge (edu.cmu.tetrad.graph.Edge)1 SessionAdapter (edu.cmu.tetrad.session.SessionAdapter)1 SessionEvent (edu.cmu.tetrad.session.SessionEvent)1 TetradLoggerConfig (edu.cmu.tetrad.util.TetradLoggerConfig)1 FinalizingParameterEditor (edu.cmu.tetradapp.editor.FinalizingParameterEditor)1 ParameterEditor (edu.cmu.tetradapp.editor.ParameterEditor)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1