Search in sources :

Example 16 with SessionEditorIndirectRef

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();
}
Also used : List(java.util.List) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef)

Example 17 with SessionEditorIndirectRef

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);
}
Also used : List(java.util.List) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef)

Example 18 with SessionEditorIndirectRef

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);
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) List(java.util.List) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 19 with SessionEditorIndirectRef

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);
}
Also used : TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Aggregations

SessionEditorIndirectRef (edu.cmu.tetradapp.util.SessionEditorIndirectRef)19 Node (edu.cmu.tetrad.graph.Node)7 SessionNode (edu.cmu.tetrad.session.SessionNode)7 SessionWrapper (edu.cmu.tetradapp.model.SessionWrapper)5 LinkedList (java.util.LinkedList)5 TetradMetadata (edu.cmu.tetradapp.model.TetradMetadata)3 List (java.util.List)3 Endpoint (edu.cmu.tetrad.graph.Endpoint)2 Edge (edu.cmu.tetrad.graph.Edge)1 HpcAccountSettingAction (edu.cmu.tetradapp.app.hpc.action.HpcAccountSettingAction)1 TetradMetadataIndirectRef (edu.cmu.tetradapp.util.TetradMetadataIndirectRef)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 SimpleDateFormat (java.text.SimpleDateFormat)1