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