Search in sources :

Example 1 with MindMap

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;
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) AbstractCollapsableElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractCollapsableElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) ExtraTopic(com.igormaznitsa.mindmap.model.ExtraTopic) Topic(com.igormaznitsa.mindmap.model.Topic) File(java.io.File) MindMap(com.igormaznitsa.mindmap.model.MindMap) Nullable(javax.annotation.Nullable)

Example 2 with MindMap

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;
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) ArrayList(java.util.ArrayList) Topic(com.igormaznitsa.mindmap.model.Topic) Nonnull(javax.annotation.Nonnull)

Example 3 with MindMap

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;
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 4 with MindMap

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);
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 5 with MindMap

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!"));
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) Test(org.junit.Test)

Aggregations

MindMap (com.igormaznitsa.mindmap.model.MindMap)23 File (java.io.File)13 Topic (com.igormaznitsa.mindmap.model.Topic)8 IOException (java.io.IOException)7 StringReader (java.io.StringReader)7 Nonnull (javax.annotation.Nonnull)7 Test (org.junit.Test)7 Nullable (javax.annotation.Nullable)6 ArrayList (java.util.ArrayList)5 MMapURI (com.igormaznitsa.mindmap.model.MMapURI)4 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)3 StringWriter (java.io.StringWriter)3 ExtraFile (com.igormaznitsa.mindmap.model.ExtraFile)2 HasOptions (com.igormaznitsa.mindmap.plugins.api.HasOptions)2 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)2 FileInputStream (java.io.FileInputStream)2 PsiExtraFile (com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile)1 ExtraTopic (com.igormaznitsa.mindmap.model.ExtraTopic)1 MindMapController (com.igormaznitsa.mindmap.model.MindMapController)1 DialogProvider (com.igormaznitsa.mindmap.swing.panel.DialogProvider)1