/** * Loads the programming project specified in the projectContents String, which is associated with * the language definition file contained in the specified langDefContents. All the blocks * contained in projectContents must have an associted block genus defined in langDefContents. * * <p>If the langDefContents have any workspace settings such as pages or drawers and * projectContents has workspace settings as well, the workspace settings within the * projectContents will override the workspace settings in langDefContents. * * <p>NOTE: The language definition contained in langDefContents does not replace the default * language definition file set by: setLangDefFilePath() or setLangDefFile(). * * @param projectContents * @param langDefContents String XML that defines the language of projectContents */ public void loadProject(String projectContents, String langDefContents) { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder; final Document projectDoc; final Document langDoc; try { builder = factory.newDocumentBuilder(); projectDoc = builder.parse(new InputSource(new StringReader(projectContents))); final Element projectRoot = projectDoc.getDocumentElement(); langDoc = builder.parse(new InputSource(new StringReader(projectContents))); final Element langRoot = langDoc.getDocumentElement(); if (workspaceLoaded) { resetWorkspace(); } if (langDefContents == null) { loadBlockLanguage(langDefRoot); } else { loadBlockLanguage(langRoot); } workspace.loadWorkspaceFrom(projectRoot, langRoot); workspaceLoaded = true; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Loads a fresh workspace based on the default specifications in the language definition file. * The block canvas will have no live blocks. */ public void loadFreshWorkspace() { if (workspaceLoaded) { resetWorkspace(); } if (langDefDirty) { loadBlockLanguage(langDefRoot); } workspace.loadWorkspaceFrom(null, langDefRoot); workspaceLoaded = true; }