use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class AbstractSearchEditor method workbenchScroll.
JScrollPane workbenchScroll(String resultLabel) {
Graph resultGraph = resultGraph();
Graph sourceGraph = algorithmRunner.getSourceGraph();
Parameters searchParams = algorithmRunner.getParams();
Graph latestWorkbenchGraph = null;
if (searchParams != null) {
latestWorkbenchGraph = (Graph) searchParams.get("sourceGraph", null);
}
if (latestWorkbenchGraph == null) {
GraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
} else {
GraphUtils.arrangeBySourceGraph(resultGraph, latestWorkbenchGraph);
}
// boolean arrangedAll = DataGraphUtils.arrangeBySourceGraph(resultGraph,
// latestWorkbenchGraph);
//
// if (!arrangedAll) {
// arrangedAll =
// DataGraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
// }
// if (!arrangedAll) {
// DataGraphUtils.circleLayout(resultGraph, 200, 200, 150);
// }
this.workbench = new GraphWorkbench(resultGraph);
graphHistory.clear();
graphHistory.add(resultGraph);
this.workbench.setAllowDoubleClickActions(false);
this.workbench.setAllowNodeEdgeSelection(true);
this.workbenchScroll = new JScrollPane(workbench);
// workbenchScroll.setPreferredSize(new Dimension(450, 450));
// workbenchScroll.setBorder(new TitledBorder(resultLabel));
this.workbench.addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent e) {
storeLatestWorkbenchGraph();
}
});
return workbenchScroll;
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class BayesImEditor method setEditorPanel.
private void setEditorPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
BayesIm bayesIm = wrapper.getBayesIm();
Graph graph = bayesIm.getDag();
GraphWorkbench workbench = new GraphWorkbench(graph);
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
menuBar.add(file);
file.add(new SaveBayesImXmlAction(this));
file.add(new LoadBayesImXmlAction(wrapper, this));
file.add(new LoadBayesImXsdlXmlAction(wrapper, this));
file.add(new SaveScreenshot(this, true, "Save Screenshot..."));
file.add(new SaveComponentImage(workbench, "Save Graph Image..."));
setLayout(new BorderLayout());
panel.add(menuBar, BorderLayout.NORTH);
wizard = new BayesImEditorWizard(bayesIm, workbench);
wizard.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ("editorValueChanged".equals(evt.getPropertyName())) {
firePropertyChange("modelChanged", null, null);
}
}
});
JScrollPane workbenchScroll = new JScrollPane(workbench);
JScrollPane wizardScroll = new JScrollPane(getWizard());
workbenchScroll.setPreferredSize(new Dimension(450, 450));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, workbenchScroll, wizardScroll);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(workbenchScroll.getPreferredSize().width);
panel.add(splitPane, BorderLayout.CENTER);
setName("Bayes IM Editor");
getWizard().addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ("editorClosing".equals(evt.getPropertyName())) {
firePropertyChange("editorClosing", null, getName());
}
if ("closeFrame".equals(evt.getPropertyName())) {
firePropertyChange("closeFrame", null, null);
firePropertyChange("editorClosing", true, true);
}
if ("modelChanged".equals(evt.getPropertyName())) {
firePropertyChange("modelChanged", evt.getOldValue(), evt.getNewValue());
}
}
});
targetPanel.add(panel, BorderLayout.CENTER);
validate();
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FgesSearchEditor method layoutByKnowledge.
public void layoutByKnowledge() {
GraphWorkbench resultWorkbench = getWorkbench();
Graph graph = resultWorkbench.getGraph();
IKnowledge knowledge = (IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2());
SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
// resultWorkbench.setGraph(graph);
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FgesSearchEditor method addSpecialMenus.
protected void addSpecialMenus(JMenuBar menuBar) {
if (!(getAlgorithmRunner() instanceof FgesRunner)) {
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");
final 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 DirectedPathsAction(getWorkbench()));
// graph.add(new TreksAction(getWorkbench()));
// graph.add(new AllPathsAction(getWorkbench()));
// graph.add(new NeighborhoodsAction(getWorkbench()));
// graph.add(new TriplesAction(getWorkbench(), 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;
}
if (runner instanceof FgesRunner) {
GraphScorer scorer = ((FgesRunner) runner).getGraphScorer();
Graph _graph = ((FgesRunner) runner).getTopGraphs().get(getIndex()).getGraph();
ScoredGraphsDisplay display = new ScoredGraphsDisplay(_graph, scorer);
GraphWorkbench workbench = getWorkbench();
EditorWindow editorWindow = new EditorWindow(display, "Independence Facts", "Close", false, workbench);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.setVisible(true);
} else {
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));
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FofcSearchEditor 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());
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();
}
Aggregations