Fixing FreeMind importing nodes order

This commit is contained in:
Pablo Luna 2011-01-10 12:33:30 -03:00
parent fa58c683c0
commit bfa403a14f
2 changed files with 82 additions and 2 deletions

View File

@ -554,7 +554,7 @@ mindplot.MindmapDesigner.prototype._nodeModelToNodeGraph = function(nodeModel)
var children = nodeModel.getChildren().slice(); var children = nodeModel.getChildren().slice();
// Sort children by order to solve adding order ... // Sort children by order to solve adding order ...
if (children.length > 0) if (nodeGraph.getTopicType()!=mindplot.NodeModel.CENTRAL_TOPIC_TYPE && children.length > 0)
{ {
var oldChildren = children; var oldChildren = children;
children = []; children = [];

View File

@ -33,6 +33,7 @@ import javax.xml.bind.JAXBException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.math.BigInteger; import java.math.BigInteger;
@ -60,11 +61,12 @@ public class FreemindImporter
centralTopic.setCentral(true); centralTopic.setCentral(true);
setNodePropertiesToTopic(centralTopic,centralNode); setNodePropertiesToTopic(centralTopic,centralNode);
centralTopic.setShape(ShapeStyle.ROUNDED_RETAGLE.getStyle()); centralTopic.setShape(ShapeStyle.ELIPSE.getStyle());
mindmapMap.getTopic().add(centralTopic); mindmapMap.getTopic().add(centralTopic);
mindmapMap.setName(mapName); mindmapMap.setName(mapName);
addTopicFromNode(centralNode,centralTopic); addTopicFromNode(centralNode,centralTopic);
fixCentralTopicChildOrder(centralTopic);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
JAXBUtils.saveMap(mindmapMap,out,"com.wisemapping.xml.mindmap"); JAXBUtils.saveMap(mindmapMap,out,"com.wisemapping.xml.mindmap");
@ -84,6 +86,84 @@ public class FreemindImporter
return map; return map;
} }
private void fixCentralTopicChildOrder(TopicType centralTopic){
List<TopicType> topics = centralTopic.getTopic();
List<TopicType> leftTopics = new ArrayList<TopicType>();
List<TopicType> rightTopics = new ArrayList<TopicType>();
for (TopicType topic : topics){
if(isOnLeftSide(topic)){
leftTopics.add(topic);
} else {
rightTopics.add(topic);
}
}
if(leftTopics.size()>0){
int size = leftTopics.size();
int index = 0;
int center = size/2;
if(size %2==0){ //Even number, then place middle point in 1 index
index = 1;
center--;
}
int index2=index;
leftTopics.get(center).setOrder(index);
for(int i = center-1; i>=0; i--){
if(index==0){
index++;
}else{
index+=2;
}
leftTopics.get(i).setOrder(index);
}
index=index2;
for(int i = center+1; i<size; i++){
if(index==1){
index++;
}else{
index+=2;
}
leftTopics.get(i).setOrder(index);
}
}
if(rightTopics.size()>0){
int size = rightTopics.size();
int index = 0;
int center = size/2;
if(size %2==0){ //Even number, then place middle point in 1 index
index = 1;
center--;
}
int index2=index;
rightTopics.get(center).setOrder(index);
for(int i = center-1; i>=0; i--){
if(index==0){
index++;
}else{
index+=2;
}
rightTopics.get(i).setOrder(index);
}
index=index2;
for(int i = center+1; i<size; i++){
if(index==1){
index++;
}else{
index+=2;
}
rightTopics.get(i).setOrder(index);
}
}
}
private boolean isOnLeftSide(TopicType topic) {
String[] position = topic.getPosition().split(",");
int x = Integer.parseInt(position[0]);
return x<0;
}
private void addTopicFromNode(Node mainNode, TopicType topic) private void addTopicFromNode(Node mainNode, TopicType topic)
{ {
final List<Object> freemindNodes = mainNode.getArrowlinkOrCloudOrEdge(); final List<Object> freemindNodes = mainNode.getArrowlinkOrCloudOrEdge();