Search in sources :

Example 1 with SessionAdapter

use of edu.cmu.tetrad.session.SessionAdapter 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)

Aggregations

CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)1 SessionAdapter (edu.cmu.tetrad.session.SessionAdapter)1 SessionEvent (edu.cmu.tetrad.session.SessionEvent)1 SessionNode (edu.cmu.tetrad.session.SessionNode)1 EditorWindow (edu.cmu.tetradapp.editor.EditorWindow)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 ToolTipManager (javax.swing.ToolTipManager)1