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;
}
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;
}
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);
}
}
});
}
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);
}
}
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;
}
Aggregations