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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations