mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Freemind Import/Export, supporting relationship lines
This commit is contained in:
parent
67d2954f9e
commit
be4cebf64b
@ -23,10 +23,8 @@ import com.wisemapping.exporter.ExportException;
|
||||
import com.wisemapping.exporter.Exporter;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.util.JAXBUtils;
|
||||
import com.wisemapping.xml.freemind.Font;
|
||||
import com.wisemapping.xml.freemind.Node;
|
||||
import com.wisemapping.xml.freemind.Edge;
|
||||
import com.wisemapping.xml.freemind.Hook;
|
||||
import com.wisemapping.xml.freemind.*;
|
||||
import com.wisemapping.xml.mindmap.RelationshipType;
|
||||
import com.wisemapping.xml.mindmap.TopicType;
|
||||
import com.wisemapping.xml.mindmap.Icon;
|
||||
|
||||
@ -35,13 +33,16 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FreemindExporter
|
||||
implements Exporter
|
||||
{
|
||||
|
||||
private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory;
|
||||
private Map<String, Node> nodesMap = null;
|
||||
|
||||
public void export(MindMap map, OutputStream outputStream) throws ExportException {
|
||||
try {
|
||||
@ -54,6 +55,7 @@ public class FreemindExporter
|
||||
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
|
||||
|
||||
freemindObjectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
||||
nodesMap = new HashMap<String, Node>();
|
||||
final com.wisemapping.xml.mindmap.Map mindmapMap;
|
||||
|
||||
try {
|
||||
@ -85,9 +87,21 @@ public class FreemindExporter
|
||||
freemindMap.setNode(main);
|
||||
if (centerTopic != null)
|
||||
{
|
||||
nodesMap.put(centerTopic.getId(), main);
|
||||
setTopicPropertiesToNode(main,centerTopic);
|
||||
addNodeFromTopic(centerTopic,main);
|
||||
}
|
||||
List<RelationshipType> relationships = mindmapMap.getRelationship();
|
||||
for(RelationshipType relationship : relationships){
|
||||
Node srcNode = nodesMap.get(relationship.getSrcTopicId());
|
||||
Arrowlink arrowlink = freemindObjectFactory.createArrowlink();
|
||||
Node dstNode = nodesMap.get(relationship.getDestTopicId());
|
||||
arrowlink.setDESTINATION(dstNode.getID());
|
||||
if(relationship.isEndArrow())
|
||||
arrowlink.setENDARROW("Default");
|
||||
List<Object> cloudOrEdge = srcNode.getArrowlinkOrCloudOrEdge();
|
||||
cloudOrEdge.add(arrowlink);
|
||||
}
|
||||
|
||||
JAXBUtils.saveMap(freemindMap,outputStream,"com.wisemapping.xml.freemind");
|
||||
} catch (JAXBException e) {
|
||||
@ -101,6 +115,7 @@ public class FreemindExporter
|
||||
|
||||
for (TopicType topicType : currentTopic) {
|
||||
final Node newNode = freemindObjectFactory.createNode();
|
||||
nodesMap.put(topicType.getId(), newNode);
|
||||
setTopicPropertiesToNode(newNode,topicType);
|
||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||
addNodeFromTopic(topicType,newNode);
|
||||
@ -109,6 +124,7 @@ public class FreemindExporter
|
||||
|
||||
private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
freemindNode.setID("ID_"+mindmapTopic.getId());
|
||||
freemindNode.setTEXT(mindmapTopic.getText());
|
||||
freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor());
|
||||
String style = "line"; // default style for freemind
|
||||
@ -122,7 +138,9 @@ public class FreemindExporter
|
||||
addFontNode(freemindNode,mindmapTopic);
|
||||
addEdgeNode(freemindNode,mindmapTopic);
|
||||
addNote(freemindNode,mindmapTopic);
|
||||
|
||||
Boolean shrink = mindmapTopic.isShrink();
|
||||
if(shrink!=null && shrink)
|
||||
freemindNode.setFOLDED(String.valueOf(shrink));
|
||||
}
|
||||
|
||||
private void addNote(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
|
@ -27,7 +27,9 @@ import com.wisemapping.model.ShapeStyle;
|
||||
import com.wisemapping.model.MindMapNative;
|
||||
import com.wisemapping.util.JAXBUtils;
|
||||
import com.wisemapping.xml.freemind.*;
|
||||
import com.wisemapping.xml.freemind.Map;
|
||||
import com.wisemapping.xml.freemind.Node;
|
||||
import com.wisemapping.xml.mindmap.RelationshipType;
|
||||
import com.wisemapping.xml.mindmap.TopicType;
|
||||
import com.wisemapping.xml.mindmap.Link;
|
||||
import org.w3c.dom.*;
|
||||
@ -36,8 +38,7 @@ import javax.xml.bind.JAXBException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class FreemindImporter
|
||||
@ -49,6 +50,9 @@ public class FreemindImporter
|
||||
private static final String BOLD = "bold";
|
||||
private static final String ITALIC = "italic";
|
||||
private static final String EMPTY_NOTE = "";
|
||||
private java.util.Map<String, TopicType> nodesMap = null;
|
||||
private List<RelationshipType> relationships = null;
|
||||
private int currentId;
|
||||
|
||||
public MindMap importMap(String mapName,String description,InputStream input) throws ImporterException {
|
||||
|
||||
@ -58,19 +62,25 @@ public class FreemindImporter
|
||||
final Map freemindMap = (Map) JAXBUtils.getMapObject(input,"com.wisemapping.xml.freemind");
|
||||
|
||||
final com.wisemapping.xml.mindmap.Map mindmapMap = mindmapObjectFactory.createMap();
|
||||
mindmapMap.setVersion("pela");
|
||||
currentId=0;
|
||||
|
||||
final Node centralNode = freemindMap.getNode();
|
||||
final TopicType centralTopic = mindmapObjectFactory.createTopicType();
|
||||
centralTopic.setId(String.valueOf(currentId++));
|
||||
centralTopic.setCentral(true);
|
||||
|
||||
setNodePropertiesToTopic(centralTopic,centralNode);
|
||||
centralTopic.setShape(ShapeStyle.ELIPSE.getStyle());
|
||||
mindmapMap.getTopic().add(centralTopic);
|
||||
mindmapMap.setName(mapName);
|
||||
|
||||
nodesMap = new HashMap<String, TopicType>();
|
||||
relationships = new ArrayList<RelationshipType>();
|
||||
addTopicFromNode(centralNode,centralTopic);
|
||||
fixCentralTopicChildOrder(centralTopic);
|
||||
|
||||
addRelationships(mindmapMap);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
JAXBUtils.saveMap(mindmapMap,out,"com.wisemapping.xml.mindmap");
|
||||
|
||||
@ -89,6 +99,17 @@ public class FreemindImporter
|
||||
return map;
|
||||
}
|
||||
|
||||
private void addRelationships(com.wisemapping.xml.mindmap.Map mindmapMap) {
|
||||
List<RelationshipType> mapRelationships = mindmapMap.getRelationship();
|
||||
for(RelationshipType relationship : relationships){
|
||||
relationship.setId(String.valueOf(currentId++));
|
||||
String destId = relationship.getDestTopicId();
|
||||
TopicType destTopic = nodesMap.get(destId);
|
||||
relationship.setDestTopicId(destTopic.getId());
|
||||
mapRelationships.add(relationship);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixCentralTopicChildOrder(TopicType centralTopic){
|
||||
List<TopicType> topics = centralTopic.getTopic();
|
||||
List<TopicType> leftTopics = new ArrayList<TopicType>();
|
||||
@ -178,6 +199,8 @@ public class FreemindImporter
|
||||
{
|
||||
final Node node = (Node) freemindNode;
|
||||
TopicType newTopic = mindmapObjectFactory.createTopicType();
|
||||
newTopic.setId(String.valueOf(currentId++));
|
||||
nodesMap.put(node.getID(), newTopic); //Lets use freemind id temporarily. This will be fixed when adding relationship to the map.
|
||||
newTopic.setOrder(order++);
|
||||
String url = node.getLINK();
|
||||
if (url != null)
|
||||
@ -245,6 +268,20 @@ public class FreemindImporter
|
||||
|
||||
}
|
||||
}
|
||||
else if (freemindNode instanceof Arrowlink){
|
||||
final Arrowlink arrow = (Arrowlink) freemindNode;
|
||||
RelationshipType relationship = mindmapObjectFactory.createRelationshipType();
|
||||
String destId = arrow.getDESTINATION();
|
||||
relationship.setSrcTopicId(currentTopic.getId());
|
||||
relationship.setDestTopicId(destId);
|
||||
/*String[] inclination = arrow.getENDINCLINATION().split(";");
|
||||
relationship.setDestCtrlPoint(inclination[0]+","+inclination[1]);
|
||||
inclination = arrow.getSTARTINCLINATION().split(";");
|
||||
relationship.setSrcCtrlPoint(inclination[0]+","+inclination[1]);*/
|
||||
relationship.setEndArrow(!arrow.getENDARROW().equals("None"));
|
||||
relationship.setLineType("3");
|
||||
relationships.add(relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user