Search in sources :

Example 1 with Version

use of edu.cmu.tetrad.util.Version in project tetrad by cmu-phil.

the class AboutTetradAction method actionPerformed.

/**
 * Closes the frontmost session of this action's desktop.
 */
public void actionPerformed(ActionEvent e) {
    Box b1 = Box.createVerticalBox();
    Version currentVersion = Version.currentViewableVersion();
    String copyright = LicenseUtils.copyright();
    copyright = copyright.replaceAll("\n", "<br>");
    String latestVersion = LatestClient.getInstance().getLatestResult(60);
    latestVersion = latestVersion.replaceAll("\n", "<br>");
    JLabel label = new JLabel();
    label.setText("<html>" + "<b>Tetrad " + currentVersion + "</b>" + "<br>" + "<br>Laboratory for Symbolic and Educational Computing" + "<br>Department of Philosophy" + "<br>Carnegie Mellon University" + "<br>" + "<br>Project Direction: Clark Glymour, Richard Scheines, Peter Spirtes" + "<br>Lead Developer: Joseph Ramsey" + "<br>" + copyright + "<br>" + latestVersion + "</html>");
    label.setBackground(Color.LIGHT_GRAY);
    label.setFont(new Font("Dialog", Font.PLAIN, 12));
    label.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(10, 10, 10, 10)));
    b1.add(label);
    JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), b1, "About Tetrad...", JOptionPane.PLAIN_MESSAGE);
}
Also used : Version(edu.cmu.tetrad.util.Version) LineBorder(javax.swing.border.LineBorder) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder)

Example 2 with Version

use of edu.cmu.tetrad.util.Version in project tetrad by cmu-phil.

the class TestVersion method testNextVersion.

@Test
public void testNextVersion() {
    Version version = new Version("4.3.1-5");
    Version version2 = version.nextMajorVersion();
    assertEquals(version2, new Version("5.0.0-0"));
    Version version3 = version.nextMinorVersion();
    assertEquals(version3, new Version("4.4.0-0"));
    Version version4 = version.nextMinorSubversion();
    assertEquals(version4, new Version("4.3.2-0"));
    Version version5 = version.nextIncrementalRelease();
    assertEquals(version5, new Version("4.3.1-6"));
}
Also used : Version(edu.cmu.tetrad.util.Version) Test(org.junit.Test)

Example 3 with Version

use of edu.cmu.tetrad.util.Version in project tetrad by cmu-phil.

the class TestVersion method testRoundtrip.

@Test
public void testRoundtrip() {
    Version version = new Version("4.3.1-5");
    String versionString = version.toString();
    Version version2 = new Version(versionString);
    assertTrue(version.equals(version2));
}
Also used : Version(edu.cmu.tetrad.util.Version) Test(org.junit.Test)

Example 4 with Version

use of edu.cmu.tetrad.util.Version in project tetrad by cmu-phil.

the class SessionFileTransferHandler method importData.

@Override
public boolean importData(TransferSupport support) {
    try {
        List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
        for (File file : files) {
            Preferences.userRoot().put("sessionSaveLocation", file.getParent());
            Session session = DesktopController.getInstance().getSessionByName(file.getName());
            if (session != null) {
                if (session.isEmpty()) {
                    DesktopController.getInstance().closeSessionByName(file.getName());
                } else {
                    int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), "Replace existing session by that name?.", "Confirm", JOptionPane.YES_NO_OPTION);
                    if (ret == JOptionPane.YES_OPTION) {
                        DesktopController.getInstance().closeSessionByName(file.getName());
                    } else {
                        return false;
                    }
                }
            }
            try (InputStream in = Files.newInputStream(file.toPath())) {
                DecompressibleInputStream objIn = new DecompressibleInputStream(in);
                Object o = objIn.readObject();
                TetradMetadata metadata = null;
                SessionWrapper sessionWrapper = null;
                if (o instanceof TetradMetadata) {
                    metadata = (TetradMetadata) o;
                    sessionWrapper = (SessionWrapper) objIn.readObject();
                } else if (o instanceof SessionWrapper) {
                    metadata = null;
                    sessionWrapper = (SessionWrapper) o;
                }
                in.close();
                if (metadata == null) {
                    throw new NullPointerException("Could not read metadata.");
                }
                if (sessionWrapper == null) {
                    Version version = metadata.getVersion();
                    Date date = metadata.getDate();
                    SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy");
                    JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Could not load session. The version of the session was \n" + version + "; it was saved on " + df.format(date) + ". You " + "\nmight try loading it with that version instead.");
                    return false;
                }
                SessionEditorWorkbench graph = new SessionEditorWorkbench(sessionWrapper);
                String name = file.getName();
                sessionWrapper.setName(name);
                SessionEditor editor = new SessionEditor(name, graph);
                DesktopController.getInstance().addSessionEditor(editor);
                DesktopController.getInstance().closeEmptySessions();
                DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
            } catch (FileNotFoundException exception) {
                LOGGER.error("", exception);
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "That wasn't a TETRAD session file: " + file);
            } catch (Exception exception) {
                LOGGER.error("", exception);
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "An error occurred attempting to load the session.");
            }
        }
    } catch (UnsupportedFlavorException | IOException exception) {
        LOGGER.error("", exception);
    }
    return super.importData(support);
}
Also used : TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) DecompressibleInputStream(edu.cmu.tetradapp.app.DecompressibleInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) DecompressibleInputStream(edu.cmu.tetradapp.app.DecompressibleInputStream) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Date(java.util.Date) SessionEditorWorkbench(edu.cmu.tetradapp.app.SessionEditorWorkbench) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Version(edu.cmu.tetrad.util.Version) List(java.util.List) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) SessionEditor(edu.cmu.tetradapp.app.SessionEditor) Session(edu.cmu.tetrad.session.Session) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Example 5 with Version

use of edu.cmu.tetrad.util.Version in project tetrad by cmu-phil.

the class LoadSessionAction method actionPerformed.

/**
 * Performs the action of opening a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    Window owner = (Window) JOptionUtils.centeringComp().getTopLevelAncestor();
    // select a file to open using the file chooser
    JFileChooser chooser = new JFileChooser();
    String sessionSaveLocation = Preferences.userRoot().get("sessionSaveLocation", "");
    chooser.setCurrentDirectory(new File(sessionSaveLocation));
    chooser.addChoosableFileFilter(new TetFileFilter());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int ret1 = chooser.showOpenDialog(JOptionUtils.centeringComp());
    if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
        return;
    }
    final File file = chooser.getSelectedFile();
    if (file == null) {
        return;
    }
    Preferences.userRoot().put("sessionSaveLocation", file.getParent());
    Session session = DesktopController.getInstance().getSessionByName(file.getName());
    if (session != null) {
        if (session.isEmpty()) {
            DesktopController.getInstance().closeSessionByName(file.getName());
        } else {
            int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), "Replace existing session by that name?.", "Confirm", JOptionPane.YES_NO_OPTION);
            if (ret == JOptionPane.YES_OPTION) {
                DesktopController.getInstance().closeSessionByName(file.getName());
            } else {
                return;
            }
        }
    }
    // The watcher thread is causing a race condition with JFileChooser.showOpenDialog somehow. Placing that
    // code outside the thread.
    new WatchedProcess(owner) {

        public void watch() {
            try {
                FileInputStream in = new FileInputStream(file);
                // ObjectInputStream objIn = new ObjectInputStream(in);
                DecompressibleInputStream objIn = new DecompressibleInputStream(in);
                Object o = objIn.readObject();
                TetradMetadata metadata = null;
                SessionWrapper sessionWrapper = null;
                if (o instanceof TetradMetadata) {
                    metadata = (TetradMetadata) o;
                    try {
                        sessionWrapper = (SessionWrapper) objIn.readObject();
                    } catch (ClassNotFoundException e1) {
                        throw e1;
                    } catch (Exception e2) {
                        e2.printStackTrace();
                        sessionWrapper = null;
                    }
                } else if (o instanceof SessionWrapper) {
                    metadata = null;
                    sessionWrapper = (SessionWrapper) o;
                }
                in.close();
                if (metadata == null) {
                    throw new NullPointerException("Could not read metadata.");
                }
                if (sessionWrapper == null) {
                    Version version = metadata.getVersion();
                    Date date = metadata.getDate();
                    SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy");
                    JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Could not load session. The version of the session was \n" + version + "; it was saved on " + df.format(date) + ". You " + "\nmight try loading it with that version instead.");
                    return;
                }
                SessionEditorWorkbench graph = new SessionEditorWorkbench(sessionWrapper);
                String name = file.getName();
                sessionWrapper.setName(name);
                SessionEditor editor = new SessionEditor(name, graph);
                DesktopController.getInstance().addSessionEditor(editor);
                DesktopController.getInstance().closeEmptySessions();
                DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "That wasn't a TETRAD session file: " + file);
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "An error occurred attempting to load the session.");
            }
        }
    };
}
Also used : TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) Date(java.util.Date) Version(edu.cmu.tetrad.util.Version) SimpleDateFormat(java.text.SimpleDateFormat) Session(edu.cmu.tetrad.session.Session) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Aggregations

Version (edu.cmu.tetrad.util.Version)5 Session (edu.cmu.tetrad.session.Session)2 SessionWrapper (edu.cmu.tetradapp.model.SessionWrapper)2 TetradMetadata (edu.cmu.tetradapp.model.TetradMetadata)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Test (org.junit.Test)2 DecompressibleInputStream (edu.cmu.tetradapp.app.DecompressibleInputStream)1 SessionEditor (edu.cmu.tetradapp.app.SessionEditor)1 SessionEditorWorkbench (edu.cmu.tetradapp.app.SessionEditorWorkbench)1 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 CompoundBorder (javax.swing.border.CompoundBorder)1 EmptyBorder (javax.swing.border.EmptyBorder)1 LineBorder (javax.swing.border.LineBorder)1