Search in sources :

Example 1 with RcvrIOLoadException

use of edu.cmu.cs.hcii.cogtool.util.RcvrIOLoadException in project cogtool by cogtool.

the class Controller method open.

/**
     * Prompts for and opens a file.
     *
     * @throws RcvrIOLoadException if the open fails
     */
protected boolean open(DoublePoint loc, File[] openLocs) {
    try {
        // If the open dialog was canceled, do nothing.
        if (openLocs != null) {
            Interaction interaction = getUI().getStandardInteraction();
            // Otherwise, open all of the selected projects.
            for (int i = 0; i < openLocs.length; i++) {
                String statusMsg = null;
                if (!openLocs[i].exists()) {
                    interaction.protestFileNotFound(openLocs[i].getName());
                    continue;
                }
                Project proj = null;
                try {
                    proj = (Project) persist.isLoaded(openLocs[i]);
                    if (proj != null) {
                        if (UndoManager.isAtSavePoint(proj)) {
                            statusMsg = L10N.get("AC.OpenNotModified", "Project already open and not modified");
                        } else {
                            boolean revert = interaction.askRevertBeforeOpen(proj.getName());
                            if (revert) {
                                closeProject(proj, false);
                            } else {
                                continue;
                            }
                        }
                    }
                    proj = (Project) persist.load(openLocs[i]);
                } catch (RuntimeException e) {
                    // format
                    throw new RcvrIOLoadException(("Error loading project: " + e.getMessage()), e);
                }
                CogToolPref.setRecent(openLocs[i].getCanonicalPath());
                // Reset the project name in case the file was renamed
                String name = openLocs[i].getName();
                // Remove the .cgt, if it is there.
                int periodIndex = name.lastIndexOf('.');
                if (periodIndex > 0) {
                    name = name.substring(0, periodIndex);
                }
                proj.setName(name);
                // Create a window; the project is not yet registered
                // and is unmodified.
                ProjectController c = ProjectController.openController(proj, false, true);
                UI ui = getUI();
                if ((loc != null) && (ui != null)) {
                    c.getUI().setLocation(loc);
                }
                if (statusMsg != null) {
                    c.interaction.setStatusMessage(statusMsg);
                }
            }
            return true;
        }
        return false;
    } catch (IOException e) {
        throw new RcvrIOLoadException("Error loading project: " + e.getMessage(), e);
    } catch (GraphicsUtil.ImageException e) {
        throw new RcvrImageException("Error loading image from project: " + e.getMessage(), e);
    }
}
Also used : Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) IOException(java.io.IOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Project(edu.cmu.cs.hcii.cogtool.model.Project) RcvrIOLoadException(edu.cmu.cs.hcii.cogtool.util.RcvrIOLoadException) UI(edu.cmu.cs.hcii.cogtool.ui.UI) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)

Aggregations

DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 Project (edu.cmu.cs.hcii.cogtool.model.Project)1 Interaction (edu.cmu.cs.hcii.cogtool.ui.Interaction)1 UI (edu.cmu.cs.hcii.cogtool.ui.UI)1 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)1 RcvrIOLoadException (edu.cmu.cs.hcii.cogtool.util.RcvrIOLoadException)1 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)1 IOException (java.io.IOException)1