Search in sources :

Example 1 with Topic

use of com.igormaznitsa.mindmap.model.Topic 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 Topic

use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.

the class Freemind2MindMapImporter method parseTopic.

private void parseTopic(@Nonnull final File rootFolder, @Nonnull final MindMap map, @Nullable Topic parent, @Nullable Topic preGeneratedTopic, @Nonnull Element element, @Nonnull final Map<String, Topic> idTopicMap, @Nonnull final Map<String, String> linksMap) {
    final String text = element.getAttribute("TEXT");
    final String id = element.getAttribute("ID");
    final String position = element.getAttribute("POSITION");
    final String arrowDestination = findArrowlinkDestination(element);
    final String color = element.getAttribute("COLOR");
    final List<RichContent> foundRichContent = extractRichContent(element);
    final Topic topicToProcess;
    if (preGeneratedTopic == null) {
        topicToProcess = Assertions.assertNotNull(parent).makeChild(text, null);
        if (Assertions.assertNotNull(parent).isRoot()) {
            if ("left".equalsIgnoreCase(position)) {
                AbstractCollapsableElement.makeTopicLeftSided(topicToProcess, true);
            }
        }
    } else {
        topicToProcess = preGeneratedTopic;
    }
    if (!color.isEmpty()) {
        final Color converted = Utils.html2color(color, false);
        if (converted != null) {
            topicToProcess.setAttribute(ATTR_FILL_COLOR.getText(), Utils.color2html(converted, false));
            topicToProcess.setAttribute(ATTR_TEXT_COLOR.getText(), Utils.color2html(Utils.makeContrastColor(converted), false));
        }
    }
    topicToProcess.setText(text);
    for (final RichContent r : foundRichContent) {
        switch(r.getType()) {
            case NODE:
                {
                    if (!r.getText().isEmpty()) {
                        topicToProcess.setText(r.getText().trim());
                    }
                }
                break;
            case NOTE:
                {
                    if (!r.getText().isEmpty()) {
                        topicToProcess.setExtra(new ExtraNote(r.getText().trim()));
                    }
                }
                break;
        }
        processImageLinkForTopic(rootFolder, topicToProcess, r.getFoundImageURLs());
    }
    if (!id.isEmpty()) {
        idTopicMap.put(id, topicToProcess);
        if (!arrowDestination.isEmpty()) {
            linksMap.put(id, arrowDestination);
        }
    }
    for (final Element e : Utils.findDirectChildrenForName(element, "node")) {
        parseTopic(rootFolder, map, topicToProcess, null, e, idTopicMap, linksMap);
    }
}
Also used : ExtraNote(com.igormaznitsa.mindmap.model.ExtraNote) AbstractCollapsableElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractCollapsableElement) Element(org.w3c.dom.Element) ExtraTopic(com.igormaznitsa.mindmap.model.ExtraTopic) Topic(com.igormaznitsa.mindmap.model.Topic)

Example 3 with Topic

use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.

the class Text2MindMapImporter method decodeLine.

@Nullable
private Topic decodeLine(@Nonnull final MindMap map, @Nonnull final Iterator<String> lines, @Nonnull @MustNotContainNull final List<TopicData> topicStack) {
    Topic result = null;
    final String line = nextNonEmptyString(lines);
    if (line != null) {
        final int currentOffset = calcDataOffset(line);
        final String trimmed = line.trim();
        final Topic parentTopic = findPrevTopicForOffset(topicStack, currentOffset);
        if (parentTopic == null) {
            result = new Topic(map, null, trimmed);
            map.setRoot(result, false);
        } else {
            result = new Topic(map, parentTopic, trimmed);
        }
        topicStack.add(0, new TopicData(currentOffset, result));
    }
    return result;
}
Also used : Topic(com.igormaznitsa.mindmap.model.Topic) Nullable(javax.annotation.Nullable)

Example 4 with Topic

use of com.igormaznitsa.mindmap.model.Topic 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 5 with Topic

use of com.igormaznitsa.mindmap.model.Topic in project netbeans-mmd-plugin by raydac.

the class CloneTopicPlugin method doActionForTopic.

@Override
protected void doActionForTopic(@Nonnull final MindMapPanel panel, @Nonnull final DialogProvider dialogProvider, @Nullable final Topic actionTopic, @Nonnull @MustNotContainNull final Topic[] selectedTopics) {
    final Topic toClone = selectedTopics.length > 0 ? selectedTopics[0] : actionTopic;
    if (toClone != null) {
        final Boolean cloneSubtree = toClone.hasChildren() ? dialogProvider.msgConfirmYesNoCancel(null, Texts.getString("MindMapPanel.titleCloneTopicRequest"), Texts.getString("MindMapPanel.cloneTopicSubtreeRequestMsg")) : Boolean.FALSE;
        if (cloneSubtree == null) {
            return;
        }
        panel.cloneTopic(toClone, cloneSubtree);
    }
}
Also used : Topic(com.igormaznitsa.mindmap.model.Topic)

Aggregations

Topic (com.igormaznitsa.mindmap.model.Topic)34 Nonnull (javax.annotation.Nonnull)10 Nullable (javax.annotation.Nullable)10 MindMap (com.igormaznitsa.mindmap.model.MindMap)9 ArrayList (java.util.ArrayList)6 File (java.io.File)5 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)3 ExtraFile (com.igormaznitsa.mindmap.model.ExtraFile)3 Dimension2D (java.awt.geom.Dimension2D)3 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)3 ExtraTopic (com.igormaznitsa.mindmap.model.ExtraTopic)2 MMapURI (com.igormaznitsa.mindmap.model.MMapURI)2 MindMapPanel (com.igormaznitsa.mindmap.swing.panel.MindMapPanel)2 AbstractCollapsableElement (com.igormaznitsa.mindmap.swing.panel.ui.AbstractCollapsableElement)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 Extra (com.igormaznitsa.mindmap.model.Extra)1 ExtraNote (com.igormaznitsa.mindmap.model.ExtraNote)1 MindMapController (com.igormaznitsa.mindmap.model.MindMapController)1