📄 mindmapmapmodel.java
字号:
" hide_layer('fold'+folder);"+el+""+el+" scrollBy(0,0); // This is a work around to make it work in Browsers (Explorer, Mozilla)"+el+"}"+el+""+el+"function fold_document() {"+el+" var i;"+el+" var folder = '1';"+el+" for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {"+el+" hide_folder(folder+'_'+i); }"+el+"}"+el+""+el+"function unfold_document() {"+el+" var i;"+el+" var folder = '1';"+el+" for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {"+el+" show_folder_completely(folder+'_'+i); }"+el+"}"+el+""+el+"</script>"+el); fileout.write("<SPAN class=foldspecial onclick=\"fold_document()\">All +</SPAN>"+el); fileout.write("<SPAN class=foldspecial onclick=\"unfold_document()\">All -</SPAN>"+el); } //fileout.write("<ul>"); rootNodeOfBranch.saveHTML(fileout, "1", 0, /*isRoot*/true, /*treatAsParagraph*/true, /*depth*/1); //fileout.write("</ul>"); if (writeFoldingCode) { fileout.write("<SCRIPT language=JavaScript>"+el); fileout.write("fold_document();"+el); fileout.write("</SCRIPT>"+el); } fileout.write("</body>"+el); fileout.write("</html>"+el); fileout.close(); return true; } catch(Exception e) { System.err.println("Error in MindMapMapModel.saveHTML(): "); e.printStackTrace(); return false; } } public String getAsPlainText(List mindMapNodes) { // Returns success of the operation. try { StringWriter stringWriter = new StringWriter(); BufferedWriter fileout = new BufferedWriter(stringWriter); for(ListIterator it=mindMapNodes.listIterator();it.hasNext();) { ((MindMapNodeModel)it.next()).saveTXT(fileout,/*depth=*/0); } fileout.close(); return stringWriter.toString(); } catch(Exception e) { e.printStackTrace(); return null; } } public boolean saveTXT(MindMapNodeModel rootNodeOfBranch, File file) { // Returns success of the operation. try { BufferedWriter fileout = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file) ) ); rootNodeOfBranch.saveTXT(fileout,/*depth=*/0); fileout.close(); return true; } catch(Exception e) { System.err.println("Error in MindMapMapModel.saveTXT(): "); e.printStackTrace(); return false; } } public String getAsRTF(List mindMapNodes) { // Returns success of the operation. try { StringWriter stringWriter = new StringWriter(); BufferedWriter fileout = new BufferedWriter(stringWriter); saveRTF(mindMapNodes, fileout); fileout.close(); return stringWriter.toString(); } catch(Exception e) { e.printStackTrace(); return null; } } public boolean saveRTF(List mindMapNodes, BufferedWriter fileout) { // Returns success of the operation. try { // First collect all used colors HashSet colors = new HashSet(); for(ListIterator it=mindMapNodes.listIterator();it.hasNext();) { ((MindMapNodeModel)it.next()).collectColors(colors); } // Prepare table of colors containing indices to color table String colorTableString="{\\colortbl;\\red0\\green0\\blue255;"; // 0 - Automatic, 1 - blue for links HashMap colorTable = new HashMap(); int colorPosition = 2; for(Iterator it=colors.iterator();it.hasNext();++colorPosition) { Color color = (Color)it.next(); colorTableString += "\\red"+color.getRed()+"\\green"+color.getGreen()+ "\\blue"+color.getBlue()+";"; colorTable.put(color,new Integer(colorPosition)); } colorTableString += "}"; fileout.write ("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}"+ colorTableString+ "}"+ "\\viewkind4\\uc1\\pard\\f0\\fs20{}"); // ^ If \\ud is appended here, Unicode does not work in MS Word. for(ListIterator it=mindMapNodes.listIterator();it.hasNext();) { ((MindMapNodeModel)it.next()).saveRTF(fileout,/*depth=*/0,colorTable); } fileout.write("}"); return true; } catch(Exception e) { e.printStackTrace(); return false; }} /** * Return the success of saving */ public boolean save(File file) { return saveInternal(file, false); } /** This method is intended to provide both normal save routines and saving of temporary (internal) files.*/ private boolean saveInternal(File file, boolean isInternal) { if (!isInternal && readOnly) { // unexpected situation, yet it's better to back it up System.err.println("Attempt to save read-only map."); return false; } try { //Generating output Stream BufferedWriter fileout = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file) ) ); getXml(fileout); if(!isInternal) { setFile(file); setSaved(true); } return true; } catch (FileNotFoundException e ) { String message = Tools.expandPlaceholders(getText("save_failed"),file.getName()); if(!isInternal) getFrame().getController().errorMessage(message); else getFrame().out(message); return false; } catch(Exception e) { System.err.println("Error in MindMapMapModel.save(): "); e.printStackTrace(); return false; } } /** writes the content of the map to a writer. * @param fileout * @throws IOException */ public void getXml(Writer fileout) throws IOException { fileout.write("<map version=\""+getFrame().getFreemindVersion()+"\">\n"); fileout.write("<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->\n"); ((MindMapNodeModel)getRoot()).save(fileout, this.getLinkRegistry()); fileout.write("</map>\n"); fileout.close(); } /** * Attempts to lock the map using a semaphore file * @param file * @return If the map is locked, return the name of the locking user, otherwise return null. * @throws Exception, when the locking failed for other reasons than that the * file is being edited. */ public String tryToLock(File file) throws Exception { String lockingUser = lockManager.tryToLock(file); String lockingUserOfOldLock = lockManager.popLockingUserOfOldLock(); if (lockingUserOfOldLock != null) { getFrame().getController().informationMessage( Tools.expandPlaceholders(getText("locking_old_lock_removed"), file.getName(), lockingUserOfOldLock)); } if (lockingUser == null) { readOnly = false; } // The map sure is not read only when the locking suceeded. return lockingUser; } public void load(File file) throws FileNotFoundException, IOException, XMLParseException { if (!file.exists()) { throw new FileNotFoundException(Tools.expandPlaceholders(getText("file_not_found"), file.getPath())); } if (!file.canWrite()) { readOnly = true; } else { // try to lock the map try { String lockingUser = tryToLock(file); if (lockingUser != null) { getFrame().getController().informationMessage( Tools.expandPlaceholders(getText("map_locked_by_open"), file.getName(), lockingUser)); readOnly = true; } else { readOnly = false; }} catch (Exception e){ // Throwed by tryToLock e.printStackTrace(); getFrame().getController().informationMessage( Tools.expandPlaceholders(getText("locking_failed_by_open"), file.getName())); readOnly = true; }} MindMapNodeModel root = loadTree(file); if (root != null) { setRoot(root); } setFile(file); setSaved(true); } /** When a map is closed, this method is called. */ public void destroy() { super.destroy(); lockManager.releaseLock(); lockManager.releaseTimer(); /* cancel the timer, if map is closed. */ timerForAutomaticSaving.cancel(); } MindMapNodeModel loadTree(File file) throws XMLParseException, IOException { MindMapXMLElement mapElement = new MindMapXMLElement(getFrame()); String expectedStartString = "<map version=\"" + FreeMind.version + "\""; // FIXME: fc, 27.8.2005: this is for 0.8.0 only. Remove me ASAP. String expectedAlternativeStartString = "<map version=\"0.7.1\""; int versionInfoLength = expectedStartString.length(); // reading the start of the file: StringBuffer buffer = readFileStart(file, versionInfoLength); String mapStart = ""; if(buffer.length() >= versionInfoLength){ mapStart = buffer.substring(0, versionInfoLength); } // the resulting file is accessed by the reader: Reader reader = null; if (mapStart.equals(expectedStartString) || mapStart.equals(expectedAlternativeStartString)) { // actual version: reader = getActualReader(file); } else { // older version: reader = getUpdateReader(file); } try { mapElement.parseFromReader(reader); } catch (Exception ex) { System.err.println("Error while parsing file:" + ex); ex.printStackTrace(); return null; } finally { if (reader != null) { reader.close(); } } // complete the arrow links: mapElement.processUnfinishedLinks(getLinkRegistry()); // we wait with "invokeHooksRecursively" until the map is fully // registered.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -