📄 mindmapcontroller.java
字号:
// // Actions //_______________________________________________________________________________ // Export and Import // _________________ // This may later be moved to ControllerAdapter. So far there is no reason for it. protected class ExportToHTMLAction extends AbstractAction { MindMapController c; public ExportToHTMLAction(MindMapController controller) { super(getText("export_to_html")); c = controller; } public void actionPerformed(ActionEvent e) { File file = new File(c.getMindMapMapModel().getFile()+".html"); if (c.getMindMapMapModel().saveHTML((MindMapNodeModel)c.getMindMapMapModel().getRoot(),file)) { loadURL(file.toString()); }}} protected class ExportBranchToHTMLAction extends AbstractAction { MindMapController c; public ExportBranchToHTMLAction(MindMapController controller) { super(getText("export_branch_to_html")); c = controller; } public void actionPerformed(ActionEvent e) { try { File file = File.createTempFile("tmm", ".html"); if (c.getMindMapMapModel().saveHTML((MindMapNodeModel)getSelected(),file)) { loadURL(file.toString()); }} catch (IOException ex) {}}} private class ExportBranchAction extends AbstractAction { ExportBranchAction() { super(getText("export_branch")); } public void actionPerformed(ActionEvent e) { MindMapNodeModel node = (MindMapNodeModel) getSelected(); //if something is wrong, abort. if (getMap() == null || node == null || node.isRoot()) { getFrame().err("Could not export branch."); return; } //If the current map is not saved yet, save it first. if (getMap().getFile() == null) { getFrame().out("You must save the current map first!"); save(); } //Open FileChooser to choose in which file the exported //branch should be stored JFileChooser chooser; if (getMap().getFile().getParentFile() != null) { chooser = new JFileChooser(getMap().getFile().getParentFile()); } else { chooser = new JFileChooser(); } //chooser.setLocale(currentLocale); if (getFileFilter() != null) { chooser.addChoosableFileFilter(getFileFilter()); } int returnVal = chooser.showSaveDialog(getSelected().getViewer()); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); URL link; //Force the extension to be .mm String ext = Tools.getExtension(chosenFile.getName()); if (!ext.equals("mm")) { chosenFile = new File(chosenFile.getParent(), chosenFile.getName() + ".mm"); } try { link = chosenFile.toURL(); } catch (MalformedURLException ex) { JOptionPane.showMessageDialog(getView(), "couldn't create valid URL!"); return; } //Now make a copy from the node, remove the node from the map // and create a new //Map with the node as root, store the new Map, add the copy of // the node to the parent, //and set a link from the copy to the new Map. MindMapNodeModel parent = (MindMapNodeModel) node .getParentNode(); if (getMindMapMapModel().getFile() != null) { try { //set a link from the new root to the old map String linkToNewMapString = Tools.toRelativeURL(chosenFile.toURL(), getMindMapMapModel().getFile().toURL()); setLink(node, linkToNewMapString); } catch (MalformedURLException ex) { } } int nodePosition = parent.getChildPosition(node); deleteNode(node); // save node: node.setParent(null); MindMapMapModel map = new MindMapMapModel(node, getFrame()); map.save(chosenFile); // new node instead: MindMapNode newNode = addNewNode(parent, nodePosition, node.isLeft()); setNodeText(newNode, node.getText()); try { String linkString = Tools.toRelativeURL( getMindMapMapModel().getFile().toURL(), chosenFile.toURL()); setLink(newNode, linkString); } catch (MalformedURLException ex) { } // map should not be save automatically!! //getMindMapMapModel().save(getMindMapMapModel().getFile()); } } } private class ImportBranchAction extends AbstractAction { ImportBranchAction() { super(getText("import_branch")); } public void actionPerformed(ActionEvent e) { MindMapNodeModel parent = (MindMapNodeModel)getSelected(); if (parent == null) { return; } JFileChooser chooser = new JFileChooser(); //chooser.setLocale(currentLocale); if (getFileFilter() != null) { chooser.addChoosableFileFilter(getFileFilter()); } int returnVal = chooser.showOpenDialog(getFrame().getContentPane()); if (returnVal==JFileChooser.APPROVE_OPTION) { try { MindMapNodeModel node = getMindMapMapModel().loadTree(chooser.getSelectedFile()); paste(node, parent); invokeHooksRecursively(node, getMindMapMapModel()); } catch (Exception ex) { handleLoadingException(ex); }}}} private class ImportLinkedBranchAction extends AbstractAction { ImportLinkedBranchAction() { super(getText("import_linked_branch")); } public void actionPerformed(ActionEvent e) { MindMapNodeModel selected = (MindMapNodeModel)getSelected(); if (selected == null || selected.getLink() == null) { JOptionPane.showMessageDialog(getView(),getText("import_linked_branch_no_link")); return; } URL absolute = null; try { String relative = selected.getLink(); absolute = Tools.isAbsolutePath(relative) ? new File(relative).toURL() : new URL(getMap().getFile().toURL(), relative); } catch (MalformedURLException ex) { JOptionPane.showMessageDialog(getView(),"Couldn't create valid URL for:"+getMap().getFile()); ex.printStackTrace(); return; } try { MindMapNodeModel node = getMindMapMapModel().loadTree(new File(absolute.getFile())); paste(node, selected); invokeHooksRecursively(node, getMindMapMapModel()); } catch (Exception ex) { handleLoadingException(ex); }}} /** * This is exactly the opposite of exportBranch. */ private class ImportLinkedBranchWithoutRootAction extends AbstractAction { ImportLinkedBranchWithoutRootAction() { super(getText("import_linked_branch_without_root")); } public void actionPerformed(ActionEvent e) { MindMapNodeModel selected = (MindMapNodeModel)getSelected(); if (selected == null || selected.getLink() == null) { JOptionPane.showMessageDialog(getView(),getText("import_linked_branch_no_link")); return; } URL absolute = null; try { String relative = selected.getLink(); absolute = Tools.isAbsolutePath(relative) ? new File(relative).toURL() : new URL(getMap().getFile().toURL(), relative); } catch (MalformedURLException ex) { JOptionPane.showMessageDialog(getView(),"Couldn't create valid URL."); return; } try { MindMapNodeModel node = getMindMapMapModel().loadTree(new File(absolute.getFile())); for (ListIterator i = node.childrenUnfolded();i.hasNext();) { MindMapNodeModel importNode = (MindMapNodeModel)i.next(); paste(importNode, selected); invokeHooksRecursively(importNode, getMindMapMapModel()); } } //getModel().setLink(parent, null); } catch (Exception ex) { handleLoadingException(ex); }}} private class FollowLinkAction extends AbstractAction { FollowLinkAction() { super(getText("follow_link")); } public void actionPerformed(ActionEvent e) { loadURL(); }}/* MindMapController.java private class NodeViewStyleAction extends AbstractAction { NodeViewStyleAction(final String style) { super(getText(style)); m_style = style; } public void actionPerformed(ActionEvent e) { for(ListIterator it = getSelecteds().listIterator();it.hasNext();) { MindMapNodeModel selected = (MindMapNodeModel)it.next(); getModel().setNodeStyle(selected, m_style); }} private String m_style;} private class EdgeStyleAction extends AbstractAction { String style; EdgeStyleAction(String style) { super(getText(style)); this.style = style; } public void actionPerformed(ActionEvent e) { for(ListIterator it = getSelecteds().listIterator();it.hasNext();) { MindMapNodeModel selected = (MindMapNodeModel)it.next(); getModel().setEdgeStyle(selected, style); }}} private class ApplyPatternAction extends AbstractAction { StylePattern pattern; ApplyPatternAction(StylePattern pattern) { super(pattern.getName()); this.pattern=pattern; } public void actionPerformed(ActionEvent e) { for(ListIterator it = getSelecteds().listIterator();it.hasNext();) { MindMapNodeModel selected = (MindMapNodeModel)it.next(); ((MindMapMapModel)getModel()).applyPattern(selected, pattern); }}} // Nonaction classes // ________________________________________________________________________=======*/ private class MindMapFilter extends FileFilter { public boolean accept(File f) { if (f.isDirectory()) return true; String extension = Tools.getExtension(f.getName()); if (extension != null) { if (extension.equals("mm")) { return true; } else { return false; } } return false; } public String getDescription() { return getText("mindmaps_desc"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -