use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class Freemind2MindMapImporter method doImport.
@Override
@Nullable
public MindMap doImport(@Nonnull final MindMapPanel panel, @Nonnull final DialogProvider dialogProvider, @Nullable final Topic actionTopic, @Nonnull @MustNotContainNull final Topic[] selectedTopics) throws Exception {
final File file = this.selectFileForExtension(panel, Texts.getString("MMDImporters.Freemind2MindMap.openDialogTitle"), "mm", "Freemind files (.MM)", Texts.getString("MMDImporters.ApproveImport"));
if (file == null) {
return null;
}
final Document document = Utils.loadXmlDocument(new FileInputStream(file), "UTF-8", true);
final Element rootElement = document.getDocumentElement();
if (!rootElement.getTagName().equals("map")) {
throw new IllegalArgumentException("Not Freemind file");
}
final Map<String, Topic> idTopicMap = new HashMap<String, Topic>();
final Map<String, String> linksMap = new HashMap<String, String>();
final MindMap resultedMap = new MindMap(null, true);
resultedMap.setAttribute(MindMapPanel.ATTR_SHOW_JUMPS, "true");
final List<Element> list = Utils.findDirectChildrenForName(rootElement, "node");
if (list.isEmpty()) {
Assertions.assertNotNull(resultedMap.getRoot()).setText("Empty");
} else {
parseTopic(file.getParentFile(), resultedMap, null, resultedMap.getRoot(), list.get(0), idTopicMap, linksMap);
}
for (final Map.Entry<String, String> l : linksMap.entrySet()) {
final Topic start = idTopicMap.get(l.getKey());
final Topic end = idTopicMap.get(l.getValue());
if (start != null && end != null) {
start.setExtra(ExtraTopic.makeLinkTo(resultedMap, end));
}
}
return resultedMap;
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class Text2MindMapImporter method makeFromLines.
@Nonnull
MindMap makeFromLines(@Nonnull @MustNotContainNull final List<String> lines, @Nullable final MindMapController controller) {
final MindMap result = new MindMap(controller, false);
final Iterator<String> iterator = lines.iterator();
final List<TopicData> topicStack = new ArrayList<TopicData>();
while (true) {
final Topic topic = decodeLine(result, iterator, topicStack);
if (topic == null) {
break;
}
}
final Topic root = result.getRoot();
final int size = root == null ? 0 : root.getChildren().size();
if (root != null && size != 0) {
final List<Topic> topics = root.getChildren();
final int left = (topics.size() + 1) / 2;
for (int i = 0; i < left; i++) {
AbstractCollapsableElement.makeTopicLeftSided(topics.get(i), true);
}
}
return result;
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class Text2MindMapImporter method doImport.
@Override
@Nullable
public MindMap doImport(@Nonnull final MindMapPanel panel, @Nonnull final DialogProvider dialogProvider, @Nullable final Topic actionTopic, @Nonnull @MustNotContainNull final Topic[] selectedTopics) throws Exception {
final File file = this.selectFileForExtension(panel, Texts.getString("MMDImporters.Text2MindMap.openDialogTitle"), "txt", "text files (.TXT)", Texts.getString("MMDImporters.ApproveImport"));
MindMap result = null;
if (file != null) {
final List<String> lines = FileUtils.readLines(file, "UTF-8");
result = makeFromLines(lines, panel.getModel().getController());
}
return result;
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class AbstractStandardExporterTest method testNoExceptionForExportOfEmptyMap.
@Test
public void testNoExceptionForExportOfEmptyMap() throws Exception {
final MindMap map = new MindMap(null, new StringReader("Empty Mind Map\n---"));
final String exported = new String(export(map, null), "UTF-8");
System.out.println(exported);
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class MindmupExporterTest method testNoExceptionsAndResultPresented.
@Test
public void testNoExceptionsAndResultPresented() throws Exception {
final MindMap map = new MindMap(null, true);
map.getRoot().setText("Hello World!");
final String text = new String(export(map, null), "UTF-8");
System.out.print("JSON\n----------------\n" + text + "\n----------------\n");
assertTrue(text.contains("Hello World!"));
}
Aggregations