use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.
the class CutSubsessionAction method actionPerformed.
/**
* Copies a parentally closed selection of session nodes in the frontmost
* session editor to the clipboard.
*/
public void actionPerformed(ActionEvent e) {
SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
List modelElements = sessionEditor.getSelectedModelComponents();
SubsessionSelection selection = new SubsessionSelection(modelElements);
InternalClipboard.getInstance().setContents(selection, this);
SessionEditorWorkbench graph = sessionEditor.getSessionWorkbench();
graph.deleteSelectedObjects();
}
use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.
the class CopySubsessionAction method actionPerformed.
/**
* Copies a parentally closed selection of session nodes in the frontmost
* session editor to the clipboard.
*/
public void actionPerformed(ActionEvent e) {
SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
List modelNodes = sessionEditor.getSelectedModelComponents();
SubsessionSelection selection = new SubsessionSelection(modelNodes);
InternalClipboard.getInstance().setContents(selection, this);
}
use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.
the class PasteSubsessionAction method actionPerformed.
/**
* Copies a parentally closed selection of session nodes in the frontmost
* session editor to the clipboard.
*/
public void actionPerformed(ActionEvent e) {
Transferable transferable = InternalClipboard.getInstance().getContents(null);
if (!(transferable instanceof SubsessionSelection)) {
return;
}
SubsessionSelection selection = (SubsessionSelection) transferable;
DataFlavor flavor = new DataFlavor(SubsessionSelection.class, "Subsession Selection");
try {
List modelList = (List) selection.getTransferData(flavor);
if (modelList != null) {
SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
Point point = EditorUtils.getTopLeftPoint(modelList);
int numPastes = selection.getNumPastes();
point.translate(50 * numPastes, 50 * numPastes);
// Point point = sessionEditor.getSessionWorkbench().getCurrentMouseLocation();
//
sessionEditor.pasteSubsession(modelList, point);
}
} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.
the class SaveSessionAction method actionPerformed.
/**
* Performs the action of loading a session from a file.
*/
public void actionPerformed(ActionEvent e) {
// Get the frontmost SessionWrapper.
SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
SessionWrapper sessionWrapper = workbench.getSessionWrapper();
TetradMetadata metadata = new TetradMetadata();
File file = new File(Preferences.userRoot().get("sessionSaveLocation", Preferences.userRoot().absolutePath()), sessionWrapper.getName());
if (!file.exists() || sessionWrapper.isNewSession()) {
SaveSessionAsAction saveSessionAsAction = new SaveSessionAsAction();
saveSessionAsAction.actionPerformed(e);
this.saved = saveSessionAsAction.isSaved();
return;
}
if (file.exists()) {
int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), "File already exists. Overwrite?", "Save", JOptionPane.YES_NO_OPTION);
if (ret == JOptionPane.NO_OPTION) {
SaveSessionAsAction saveSessionAsAction = new SaveSessionAsAction();
saveSessionAsAction.actionPerformed(e);
this.saved = saveSessionAsAction.isSaved();
return;
}
}
// Save it.
try {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objOut = new ObjectOutputStream(out);
sessionWrapper.setNewSession(false);
objOut.writeObject(metadata);
objOut.writeObject(sessionWrapper);
out.close();
// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
// "Session saved.");
FileInputStream in = new FileInputStream(file);
ObjectInputStream objIn = new ObjectInputStream(in);
objIn.readObject();
} catch (Exception e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "An error occurred while attempting to save the session as " + file.getAbsolutePath() + ".");
}
sessionWrapper.setSessionChanged(false);
DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
}
Aggregations