Search in sources :

Example 1 with EditorWindow

use of edu.cmu.tetradapp.editor.EditorWindow in project tetrad by cmu-phil.

the class TetradDesktop method closeFrontmostSession.

public void closeFrontmostSession() {
    for (JInternalFrame frame : desktopPane.getAllFrames()) {
        if (frame instanceof EditorWindow) {
            ((EditorWindow) frame).closeDialog();
        }
    }
    JInternalFrame[] frames = desktopPane.getAllFramesInLayer(0);
    if (frames.length > 0) {
        frames[0].dispose();
        Map<SessionEditor, JInternalFrame> framesMap = this.framesMap;
        for (Iterator<SessionEditor> i = framesMap.keySet().iterator(); i.hasNext(); ) {
            SessionEditor sessionEditor = i.next();
            JInternalFrame frame = framesMap.get(sessionEditor);
            if (frame == frames[0]) {
                i.remove();
                break;
            }
        }
    }
}
Also used : JInternalFrame(javax.swing.JInternalFrame) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow)

Example 2 with EditorWindow

use of edu.cmu.tetradapp.editor.EditorWindow 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 3 with EditorWindow

use of edu.cmu.tetradapp.editor.EditorWindow in project tetrad by cmu-phil.

the class TetradDesktop method addEditorWindow.

/**
 * Adds the given componet to the given layer.
 */
public void addEditorWindow(EditorWindowIndirectRef windowRef, int layer) {
    final EditorWindow window = (EditorWindow) windowRef;
    // Dimension desktopSize = desktopPane.getSize();
    Dimension preferredSize = window.getPreferredSize();
    // int x = desktopSize.width / 2 - preferredSize.width / 2;
    // int y = desktopSize.height / 2 - preferredSize.height / 2;
    Component source = window.getCenteringComp();
    Point convertedPoint = SwingUtilities.convertPoint(source.getParent(), source.getLocation(), this);
    int x = convertedPoint.x + source.getWidth() / 2 - preferredSize.width / 2;
    int y = convertedPoint.y - 25 + source.getHeight() / 2 - preferredSize.height / 2;
    int topMargin = 35;
    int bottomMargin = 35;
    int leftMargin = 150;
    int rightMargin = 25;
    if (x < leftMargin) {
        x = leftMargin;
    }
    if (y < topMargin) {
        y = topMargin;
    }
    int height = Math.min(preferredSize.height, getHeight() - topMargin - bottomMargin);
    int width = Math.min(preferredSize.width, getWidth() - leftMargin - rightMargin);
    if (x + width > getWidth() - rightMargin) {
        x = getWidth() - width - rightMargin;
    }
    if (y + height > getHeight() - bottomMargin) {
        y = getHeight() - height - bottomMargin;
    }
    window.setLocation(x, y);
    window.setPreferredSize(new Dimension(width, height));
    // This line sometimes hangs, so I'm putting it in a watched process
    // so it can be stopped by the user. Not ideal.
    // Window owner = (Window) getTopLevelAncestor();
    // 
    // new WatchedProcess(owner) {
    // public void watch() {
    getDesktopPane().add(window);
    window.setLayer(layer);
    window.moveToFront();
    window.setVisible(true);
}
Also used : Dimension(java.awt.Dimension) Point(java.awt.Point) Component(java.awt.Component) Point(java.awt.Point) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow)

Example 4 with EditorWindow

use of edu.cmu.tetradapp.editor.EditorWindow in project tetrad by cmu-phil.

the class SessionEditorNode method launchEditorVisit.

private void launchEditorVisit() {
    try {
        // If there is already an editor open, don't launch another one.
        if (spawnedEditor() != null) {
            return;
        }
        boolean created = createModel(false);
        if (!created) {
            return;
        }
        final SessionNode sessionNode = getSessionNode();
        boolean cloned = sessionNode.useClonedModel();
        SessionModel model = sessionNode.getModel();
        Class<?> modelClass = model.getClass();
        SessionNodeModelConfig modelConfig = this.config.getModelConfig(modelClass);
        Object[] arguments = new Object[] { model };
        JPanel editor = modelConfig.getEditorInstance(arguments);
        addEditorListener(editor);
        ModificationRegistery.registerEditor(sessionNode, editor);
        String descrip = modelConfig.getName();
        editor.setName(getName() + " (" + descrip + ")");
        EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Done", cloned, this);
        editorWindow.addInternalFrameListener(new InternalFrameAdapter() {

            @Override
            public void internalFrameClosing(InternalFrameEvent e) {
                if (getChildren().iterator().hasNext()) {
                    finishedEditingDialog();
                }
                ModificationRegistery.unregisterSessionNode(sessionNode);
                setSpawnedEditor(null);
                EditorWindow window = (EditorWindow) e.getSource();
                if (window.isCanceled()) {
                    sessionNode.restoreOriginalModel();
                }
                sessionNode.forgetSavedModel();
            }
        });
        DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
        editorWindow.pack();
        editorWindow.setVisible(true);
        spawnedEditor = editorWindow;
        if (sessionWrapper != null) {
            sessionWrapper.setSessionChanged(true);
        }
    // for (SessionNode child : getChildren()) {
    // 
    // // only break edges to children.
    // if (edge.getNode2() == getModelNode()) {
    // SessionNodeWrapper otherWrapper =
    // (SessionNodeWrapper) edge.getNode1();
    // SessionNode other = otherWrapper.getSessionNode();
    // if (getChildren().contains(other)) {
    // sessionWrapper.removeEdge(edge);
    // }
    // } else {
    // SessionNodeWrapper otherWrapper =
    // (SessionNodeWrapper) edge.getNode2();
    // SessionNode other = otherWrapper.getSessionNode();
    // if (getChildren().contains(other)) {
    // sessionWrapper.removeEdge(edge);
    // }
    // }
    // }
    // Class[] consistentModelClasses = child.getConsistentModelClasses(false);
    // if (consistentModelClasses.length == 0) {
    // child.removeParent(sessionNode);
    // SessionEditorWorkbench sessionWorkbench = getSessionWorkbench();
    // SessionWrapper sessionWrapper = sessionWorkbench.getSessionWrapper();
    // Node node1 = sessionWrapper.getNode(sessionNode.getDisplayName());
    // Node node2 = sessionWrapper.getNode(child.getDisplayName());
    // Edge edge = sessionWrapper.getEdge(node1, node2);
    // sessionWrapper.removeEdge(edge);
    // }
    } catch (CouldNotCreateModelException e) {
        SessionUtils.showPermissibleParentsDialog(e.getModelClass(), SessionEditorNode.this, true, true);
        e.printStackTrace();
    } catch (ClassCastException e) {
        e.printStackTrace();
    } catch (Exception e) {
        Throwable cause = e;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        Component centeringComp = SessionEditorNode.this;
        String s = cause.getMessage();
        if (!"".equals(s)) {
            JOptionPane.showMessageDialog(centeringComp, s, null, JOptionPane.WARNING_MESSAGE);
        }
        e.printStackTrace();
    }
}
Also used : JPanel(javax.swing.JPanel) SessionNode(edu.cmu.tetrad.session.SessionNode) InternalFrameEvent(javax.swing.event.InternalFrameEvent) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) UnlistedSessionModel(edu.cmu.tetradapp.model.UnlistedSessionModel) SessionModel(edu.cmu.tetrad.session.SessionModel) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

EditorWindow (edu.cmu.tetradapp.editor.EditorWindow)4 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)2 SessionNode (edu.cmu.tetrad.session.SessionNode)2 Component (java.awt.Component)2 SessionAdapter (edu.cmu.tetrad.session.SessionAdapter)1 SessionEvent (edu.cmu.tetrad.session.SessionEvent)1 SessionModel (edu.cmu.tetrad.session.SessionModel)1 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)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 JComponent (javax.swing.JComponent)1 JInternalFrame (javax.swing.JInternalFrame)1 JPanel (javax.swing.JPanel)1 ToolTipManager (javax.swing.ToolTipManager)1 InternalFrameAdapter (javax.swing.event.InternalFrameAdapter)1 InternalFrameEvent (javax.swing.event.InternalFrameEvent)1