Search in sources :

Example 1 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class PValueImproverEditor method setGraphWorkbench.

private void setGraphWorkbench(final GraphWorkbench graphWorkbench) {
    JTabbedPane tabbedPane = new JTabbedPane();
    this.graphWorkbench = graphWorkbench;
    if (getOriginalSemIm() != null) {
        setOriginalSemIm(new SemIm(getWrapper().getOriginalSemIm()));
    }
    this.newSemIm = getWrapper().getNewSemIm();
    if (getNewSemIm() != null) {
        SemImEditor newEditor = new SemImEditor(new SemImWrapper(getNewSemIm()));
        final GraphWorkbench workbench = newEditor.getWorkbench();
        workbench.addPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                if ("modelChanged".equals(propertyChangeEvent.getPropertyName())) {
                    System.out.println(propertyChangeEvent);
                    Graph graph = workbench.getGraph();
                    System.out.println(graph);
                    try {
                        new Dag(graph);
                    } catch (IllegalArgumentException e) {
                        return;
                    }
                    Scorer scorer = new DagScorer((DataSet) getWrapper().getDataModel());
                    scorer.score(graph);
                    getWrapper().setNewSemIm(scorer.getEstSem());
                    setGraphWorkbench(graphWorkbench);
                }
            }
        });
        tabbedPane.addTab("New Model", newEditor);
    }
    if (getOriginalSemIm() != null) {
        SemImEditor originalEditor = new SemImEditor(new SemImWrapper(getOriginalSemIm()));
        tabbedPane.addTab("Original Model", originalEditor);
    }
    if (graphWorkbench != null) {
        tabbedPane.addTab("forbid_latent_common_causes", graphWorkbench);
    }
    panel.removeAll();
    panel.add(tabbedPane, BorderLayout.CENTER);
    panel.revalidate();
    panel.repaint();
    firePropertyChange("modelChanged", null, null);
}
Also used : DagScorer(edu.cmu.tetrad.sem.DagScorer) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DataSet(edu.cmu.tetrad.data.DataSet) Scorer(edu.cmu.tetrad.sem.Scorer) DagScorer(edu.cmu.tetrad.sem.DagScorer) Dag(edu.cmu.tetrad.graph.Dag) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) SemImWrapper(edu.cmu.tetradapp.model.SemImWrapper) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 2 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class PcGesSearchEditor method dagWorkbenchScroll.

private JScrollPane dagWorkbenchScroll(Graph dag) {
    GraphWorkbench dagWorkbench = new GraphWorkbench(dag);
    dagWorkbench.setAllowDoubleClickActions(false);
    dagWorkbench.setAllowNodeEdgeSelection(true);
    JScrollPane dagWorkbenchScroll = new JScrollPane(dagWorkbench);
    dagWorkbenchScroll.setPreferredSize(new Dimension(450, 450));
    dagWorkbench.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent e) {
            storeLatestWorkbenchGraph();
        }
    });
    return dagWorkbenchScroll;
}
Also used : MouseEvent(java.awt.event.MouseEvent) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) MouseAdapter(java.awt.event.MouseAdapter)

Example 3 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class LofsSearchEditorNew method addSpecialMenus.

protected void addSpecialMenus(JMenuBar menuBar) {
    if (!(getAlgorithmRunner() instanceof IGesRunner)) {
        JMenu test = new JMenu("Independence");
        menuBar.add(test);
        IndTestMenuItems.addIndependenceTestChoices(test, this);
    // test.addSeparator();
    // 
    // AlgorithmRunner algorithmRunner = getAlgorithmRunner();
    // if (algorithmRunner instanceof IndTestProducer) {
    // IndTestProducer p = (IndTestProducer) algorithmRunner;
    // IndependenceFactsAction action =
    // new IndependenceFactsAction(this, p, "Independence Facts...");
    // test.add(action);
    // }
    }
    JMenu graph = new JMenu("Graph");
    JMenuItem showDags = new JMenuItem("Show DAGs in forbid_latent_common_causes");
    // JMenuItem meekOrient = new JMenuItem("Meek Orientation");
    JMenuItem dagInPattern = new JMenuItem("Choose DAG in forbid_latent_common_causes");
    JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation");
    JMenuItem nextGraph = new JMenuItem("Next Graph");
    JMenuItem previousGraph = new JMenuItem("Previous Graph");
    graph.add(new GraphPropertiesAction(getWorkbench()));
    graph.add(new PathsAction(getWorkbench()));
    graph.add(new TriplesAction(getWorkbench().getGraph(), getAlgorithmRunner()));
    graph.addSeparator();
    // graph.add(meekOrient);
    graph.add(dagInPattern);
    graph.add(gesOrient);
    graph.addSeparator();
    graph.add(previousGraph);
    graph.add(nextGraph);
    graph.addSeparator();
    graph.add(showDags);
    graph.addSeparator();
    graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
    graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
    menuBar.add(graph);
    showDags.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Window owner = (Window) getTopLevelAncestor();
            new WatchedProcess(owner) {

                public void watch() {
                    // Needs to be a pattern search; this isn't checked
                    // before running the algorithm because of allowable
                    // "slop"--e.g. bidirected edges.
                    AlgorithmRunner runner = getAlgorithmRunner();
                    Graph graph = runner.getGraph();
                    if (graph == null) {
                        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "No result gaph.");
                        return;
                    }
                    PatternDisplay display = new PatternDisplay(graph);
                    GraphWorkbench workbench = getWorkbench();
                    EditorWindow editorWindow = new EditorWindow(display, "Independence Facts", "Close", false, workbench);
                    DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
                    editorWindow.setVisible(true);
                }
            };
        }
    });
    // meekOrient.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // ImpliedOrientation rules = getAlgorithmRunner().getMeekRules();
    // rules.setKnowledge((IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2()));
    // rules.orientImplied(getGraph());
    // getGraphHistory().add(getGraph());
    // getWorkbench().setGraph(getGraph());
    // firePropertyChange("modelChanged", null, null);
    // }
    // });
    dagInPattern.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Graph graph = new EdgeListGraph(getGraph());
            // Removing bidirected edges from the pattern before selecting a DAG.                                   4
            for (Edge edge : graph.getEdges()) {
                if (Edges.isBidirectedEdge(edge)) {
                    graph.removeEdge(edge);
                }
            }
            PatternToDag search = new PatternToDag(new EdgeListGraphSingleConnections(graph));
            Graph dag = search.patternToDagMeek();
            getGraphHistory().add(dag);
            getWorkbench().setGraph(dag);
            ((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(dag);
            firePropertyChange("modelChanged", null, null);
        }
    });
    gesOrient.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            DataModel dataModel = getAlgorithmRunner().getDataModel();
            final Graph graph = SearchGraphUtils.reorient(getGraph(), dataModel, getKnowledge());
            getGraphHistory().add(graph);
            getWorkbench().setGraph(graph);
            firePropertyChange("modelChanged", null, null);
        }
    });
    nextGraph.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Graph next = getGraphHistory().next();
            getWorkbench().setGraph(next);
            ((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(next);
            firePropertyChange("modelChanged", null, null);
        }
    });
    previousGraph.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Graph previous = getGraphHistory().previous();
            getWorkbench().setGraph(previous);
            ((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(previous);
            firePropertyChange("modelChanged", null, null);
        }
    });
    menuBar.add(new LayoutMenu(this));
}
Also used : LayoutMenu(edu.cmu.tetradapp.workbench.LayoutMenu) ActionEvent(java.awt.event.ActionEvent) WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) ActionListener(java.awt.event.ActionListener) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) DataModel(edu.cmu.tetrad.data.DataModel)

Example 4 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class SemGraphEditor method setEditor.

private void setEditor(SemGraphWrapper semGraphWrapper) {
    this.parameters = new Parameters(semGraphWrapper.getParameters());
    this.semGraphWrapper = semGraphWrapper;
    this.workbench = new GraphWorkbench(semGraphWrapper.getGraph());
    SemGraphToolbar toolbar = new SemGraphToolbar(getWorkbench());
    JMenuBar menuBar = createMenuBar();
    JScrollPane scroll = new JScrollPane(getWorkbench());
    scroll.setPreferredSize(new Dimension(450, 450));
    add(scroll, BorderLayout.CENTER);
    add(toolbar, BorderLayout.WEST);
    add(menuBar, BorderLayout.NORTH);
    JLabel label = new JLabel("Double click variable to change name. More information on graph edge types");
    label.setFont(new Font("SansSerif", Font.PLAIN, 12));
    // Info button added by Zhou to show edge types
    JButton infoBtn = new JButton(new ImageIcon(ImageUtils.getImage(this, "info.png")));
    infoBtn.setBorder(new EmptyBorder(0, 0, 0, 0));
    // Clock info button to show edge types instructions - Zhou
    infoBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            helpSet.setHomeID("graph_edge_types");
            HelpBroker broker = helpSet.createHelpBroker();
            ActionListener listener = new CSH.DisplayHelpFromSource(broker);
            listener.actionPerformed(e);
        }
    });
    Box b = Box.createHorizontalBox();
    b.add(Box.createHorizontalStrut(2));
    b.add(label);
    b.add(infoBtn);
    b.add(Box.createHorizontalGlue());
    b.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
    add(b, BorderLayout.SOUTH);
    this.workbench.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String propertyName = evt.getPropertyName();
            if ("graph".equals(propertyName)) {
                Graph _graph = (Graph) evt.getNewValue();
                if (getWorkbench() != null) {
                    getSemGraphWrapper().setGraph(_graph);
                }
            }
        }
    });
    this.workbench.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String propertyName = evt.getPropertyName();
            if ("modelChanged".equals(propertyName)) {
                firePropertyChange("modelChanged", evt.getOldValue(), evt.getNewValue());
            }
        }
    });
}
Also used : HelpBroker(javax.help.HelpBroker) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) MatteBorder(javax.swing.border.MatteBorder) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) ActionListener(java.awt.event.ActionListener) CSH(javax.help.CSH) EmptyBorder(javax.swing.border.EmptyBorder)

Example 5 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class MimSearchEditor2 method updateDisplayPanel.

private void updateDisplayPanel() {
    displayPanel.removeAll();
    JTabbedPane tabbedPane = new JTabbedPane();
    if (getMimRunner().getStructureGraph() != null) {
        if (getMimRunner().getStructureGraph() != null) {
            // DataGraphUtils.circleLayout(structureGraph, 200, 200, 150);
            Graph structureGraph = getMimRunner().getStructureGraph();
            doDefaultArrangement(structureGraph);
            GraphWorkbench structureWorkbench = new GraphWorkbench(structureGraph);
            structureWorkbench.setAllowDoubleClickActions(false);
            tabbedPane.add("Structure Model", new JScrollPane(structureWorkbench));
        }
    }
    if (getMimRunner().getClusters() != null) {
        ClusterEditor editor = new ClusterEditor(getMimRunner().getClusters(), getMimRunner().getData().getVariableNames());
        ClusterEditor clusterEditor = editor;
        tabbedPane.add("Measurement Model", editor);
    }
    if (getMimRunner().getFullGraph() != null) {
        Graph fullGraph = getMimRunner().getFullGraph();
        doDefaultArrangement(fullGraph);
        GraphUtils.fruchtermanReingoldLayout(fullGraph);
        GraphWorkbench fullGraphBench = new GraphWorkbench(fullGraph);
        tabbedPane.add("Full Graph", new JScrollPane(fullGraphBench));
    }
    displayPanel.add(tabbedPane, BorderLayout.CENTER);
    displayPanel.revalidate();
    displayPanel.repaint();
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench)

Aggregations

GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)53 Graph (edu.cmu.tetrad.graph.Graph)24 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)13 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 IKnowledge (edu.cmu.tetrad.data.IKnowledge)8 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)8 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)8 LayoutMenu (edu.cmu.tetradapp.workbench.LayoutMenu)7 MouseAdapter (java.awt.event.MouseAdapter)7 MouseEvent (java.awt.event.MouseEvent)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)6 PropertyChangeListener (java.beans.PropertyChangeListener)6 TitledBorder (javax.swing.border.TitledBorder)6 DataModel (edu.cmu.tetrad.data.DataModel)4 PatternToDag (edu.cmu.tetrad.search.PatternToDag)3 CSH (javax.help.CSH)3 HelpBroker (javax.help.HelpBroker)3 EmptyBorder (javax.swing.border.EmptyBorder)3 MatteBorder (javax.swing.border.MatteBorder)3