mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-22 19:33:48 +01:00
Fix note styles issues.
This commit is contained in:
parent
308250ab73
commit
87465945ac
@ -42,10 +42,11 @@ public class FreemindExporter
|
||||
implements Exporter {
|
||||
|
||||
private static final String FREE_MIND_VERSION = "0.9.0";
|
||||
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
||||
private static final String POSITION_LEFT = "left";
|
||||
private static final String POSITION_RIGHT = "right";
|
||||
private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory;
|
||||
private com.wisemapping.xml.freemind.ObjectFactory objectFactory;
|
||||
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
||||
|
||||
private Map<String, Node> nodesMap = null;
|
||||
|
||||
public void export(MindMap map, OutputStream outputStream) throws ExportException {
|
||||
@ -58,7 +59,7 @@ public class FreemindExporter
|
||||
|
||||
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
|
||||
|
||||
freemindObjectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
||||
objectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
||||
nodesMap = new HashMap<String, Node>();
|
||||
final com.wisemapping.xml.mindmap.Map mindmapMap;
|
||||
|
||||
@ -66,7 +67,7 @@ public class FreemindExporter
|
||||
final ByteArrayInputStream stream = new ByteArrayInputStream(xml);
|
||||
mindmapMap = (com.wisemapping.xml.mindmap.Map) JAXBUtils.getMapObject(stream, "com.wisemapping.xml.mindmap");
|
||||
|
||||
final com.wisemapping.xml.freemind.Map freemindMap = freemindObjectFactory.createMap();
|
||||
final com.wisemapping.xml.freemind.Map freemindMap = objectFactory.createMap();
|
||||
freemindMap.setVersion(FREE_MIND_VERSION);
|
||||
|
||||
|
||||
@ -85,7 +86,7 @@ public class FreemindExporter
|
||||
centerTopic = topics.get(0);
|
||||
}
|
||||
|
||||
final Node main = freemindObjectFactory.createNode();
|
||||
final Node main = objectFactory.createNode();
|
||||
freemindMap.setNode(main);
|
||||
if (centerTopic != null) {
|
||||
nodesMap.put(centerTopic.getId(), main);
|
||||
@ -95,7 +96,7 @@ public class FreemindExporter
|
||||
List<RelationshipType> relationships = mindmapMap.getRelationship();
|
||||
for (RelationshipType relationship : relationships) {
|
||||
Node srcNode = nodesMap.get(relationship.getSrcTopicId());
|
||||
Arrowlink arrowlink = freemindObjectFactory.createArrowlink();
|
||||
Arrowlink arrowlink = objectFactory.createArrowlink();
|
||||
Node dstNode = nodesMap.get(relationship.getDestTopicId());
|
||||
arrowlink.setDESTINATION(dstNode.getID());
|
||||
if (relationship.isEndArrow())
|
||||
@ -116,7 +117,7 @@ public class FreemindExporter
|
||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||
|
||||
for (TopicType topicType : currentTopic) {
|
||||
final Node newNode = freemindObjectFactory.createNode();
|
||||
final Node newNode = objectFactory.createNode();
|
||||
nodesMap.put(topicType.getId(), newNode);
|
||||
setTopicPropertiesToNode(newNode, topicType);
|
||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||
@ -188,7 +189,7 @@ public class FreemindExporter
|
||||
|
||||
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||
if (mindmapTopic.getBrColor() != null) {
|
||||
final Edge edgeNode = freemindObjectFactory.createEdge();
|
||||
final Edge edgeNode = objectFactory.createEdge();
|
||||
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
||||
}
|
||||
@ -199,20 +200,21 @@ public class FreemindExporter
|
||||
* eg: Verdana;10;#ffffff;bold;italic;
|
||||
*
|
||||
*/
|
||||
private void addFontNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||
private void addFontNode(@NotNull com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic) {
|
||||
final String fontStyle = mindmapTopic.getFontStyle();
|
||||
if (fontStyle != null && fontStyle.length() != 0) {
|
||||
final Font font = freemindObjectFactory.createFont();
|
||||
final Font font = objectFactory.createFont();
|
||||
final String[] part = fontStyle.split(";", 6);
|
||||
int countParts = part.length;
|
||||
boolean updated = false;
|
||||
|
||||
if (!fontStyle.endsWith(EMPTY_FONT_STYLE)) {
|
||||
|
||||
|
||||
int idx = 0;
|
||||
|
||||
// Font name
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setNAME(part[idx]);
|
||||
updated = true;
|
||||
}
|
||||
idx++;
|
||||
|
||||
@ -220,6 +222,7 @@ public class FreemindExporter
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
String size = part[idx];
|
||||
font.setSIZE(new BigInteger(size));
|
||||
updated = true;
|
||||
}
|
||||
idx++;
|
||||
|
||||
@ -232,15 +235,18 @@ public class FreemindExporter
|
||||
// Font Styles
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setBOLD(Boolean.TRUE.toString());
|
||||
updated = true;
|
||||
}
|
||||
idx++;
|
||||
|
||||
if (idx < countParts && part[idx].length() != 0) {
|
||||
font.setITALIC(Boolean.TRUE.toString());
|
||||
updated = true;
|
||||
}
|
||||
|
||||
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||
if (updated) {
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.wisemapping.xml.mindmap.RelationshipType;
|
||||
import com.wisemapping.xml.mindmap.TopicType;
|
||||
import com.wisemapping.xml.mindmap.Link;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
@ -52,6 +53,8 @@ public class FreemindImporter
|
||||
private static final String EMPTY_NOTE = "";
|
||||
private java.util.Map<String, TopicType> nodesMap = null;
|
||||
private List<RelationshipType> relationships = null;
|
||||
private static final String EMPTY_FONT_STYLE = ";;;;;";
|
||||
|
||||
private int currentId;
|
||||
|
||||
public MindMap importMap(String mapName, String description, InputStream input) throws ImporterException {
|
||||
@ -259,7 +262,7 @@ public class FreemindImporter
|
||||
} else if (freemindNode instanceof Font) {
|
||||
final Font font = (Font) freemindNode;
|
||||
final String fontStyle = generateFontStyle(mainNode, font);
|
||||
if (!fontStyle.isEmpty()) {
|
||||
if (fontStyle!=null) {
|
||||
currentTopic.setFontStyle(fontStyle);
|
||||
}
|
||||
} else if (freemindNode instanceof Edge) {
|
||||
@ -391,8 +394,8 @@ public class FreemindImporter
|
||||
int position = pos * 200 + (orderPosition + 1) * 10;
|
||||
|
||||
mindmapTopic.setPosition(position + "," + 200 * orderPosition);
|
||||
String fontStyle = generateFontStyle(freemindNode, null);
|
||||
if (!fontStyle.isEmpty()) {
|
||||
final String fontStyle = generateFontStyle(freemindNode, null);
|
||||
if (fontStyle!=null) {
|
||||
mindmapTopic.setFontStyle(fontStyle);
|
||||
}
|
||||
Boolean folded = Boolean.valueOf(freemindNode.getFOLDED());
|
||||
@ -401,39 +404,55 @@ public class FreemindImporter
|
||||
}
|
||||
}
|
||||
|
||||
private String generateFontStyle(Node node, Font font) {
|
||||
private @Nullable String generateFontStyle(@NotNull Node node, @Nullable Font font) {
|
||||
/*
|
||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||
* eg: Verdana;10;#ffffff;bold;italic;
|
||||
*
|
||||
*/
|
||||
|
||||
// Font name ...
|
||||
final StringBuilder fontStyle = new StringBuilder();
|
||||
if (font != null) {
|
||||
fontStyle.append(fixFontName(font));
|
||||
fontStyle.append(";");
|
||||
BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE();
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Size ...
|
||||
if (font != null) {
|
||||
final BigInteger bigInteger = (font.getSIZE() == null || font.getSIZE().intValue() < 8) ? BigInteger.valueOf(8) : font.getSIZE();
|
||||
fontStyle.append(bigInteger);
|
||||
fontStyle.append(";");
|
||||
String color = node.getCOLOR();
|
||||
if (color != null && !color.equals("")) {
|
||||
fontStyle.append(color);
|
||||
}
|
||||
fontStyle.append(";");
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Color ...
|
||||
final String color = node.getCOLOR();
|
||||
if (color != null && !color.equals("")) {
|
||||
fontStyle.append(color);
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Bold ...
|
||||
if (font != null) {
|
||||
boolean hasBold = Boolean.parseBoolean(font.getBOLD());
|
||||
|
||||
fontStyle.append(hasBold ? BOLD : "");
|
||||
fontStyle.append(";");
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
// Italic ...
|
||||
if (font != null) {
|
||||
boolean hasItalic = Boolean.parseBoolean(font.getITALIC());
|
||||
fontStyle.append(hasItalic ? ITALIC : "");
|
||||
fontStyle.append(";");
|
||||
}
|
||||
fontStyle.append(";");
|
||||
|
||||
return fontStyle.toString();
|
||||
final String result = fontStyle.toString();
|
||||
return result.equals(EMPTY_FONT_STYLE) ? null : result;
|
||||
}
|
||||
|
||||
private @NotNull String fixFontName(@NotNull Font font) {
|
||||
private
|
||||
@NotNull
|
||||
String fixFontName(@NotNull Font font) {
|
||||
String result = com.wisemapping.model.Font.ARIAL.getFontName(); // Default Font
|
||||
if (com.wisemapping.model.Font.isValidFont(font.getNAME())) {
|
||||
result = font.getNAME();
|
||||
|
56
wise-webapp/src/test/data/freemind/node-styles.mm
Normal file
56
wise-webapp/src/test/data/freemind/node-styles.mm
Normal file
@ -0,0 +1,56 @@
|
||||
<map version="0.9.0">
|
||||
<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
|
||||
<node CREATED="1301248379797" ID="ID_0" MODIFIED="1301248654343" STYLE="elipse" TEXT="Shapes">
|
||||
<node CREATED="1301248379797" ID="ID_2" MODIFIED="1301248379797" POSITION="right" TEXT="Node Styles">
|
||||
<node CREATED="1301248379797" ID="ID_3" MODIFIED="1301248379797" TEXT="Fork">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node CREATED="1301248379797" ID="ID_4" MODIFIED="1301248379797" STYLE="bubble" TEXT="Bubble">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node CREATED="1301248379797" ID="ID_5" MODIFIED="1301248379797" TEXT="As parent">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node CREATED="1301248379797" ID="ID_6" MODIFIED="1301248379797" TEXT="Combined">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f20707" CREATED="1301248379797" ID="ID_7" MODIFIED="1301248525505" POSITION="left"
|
||||
TEXT="Node Background Color">
|
||||
<node BACKGROUND_COLOR="#0000cc" CREATED="1301248379797" ID="ID_8" MODIFIED="1301248379797" TEXT="Fork">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#ccffcc" CREATED="1301248379798" ID="ID_9" MODIFIED="1301248379798" STYLE="bubble"
|
||||
TEXT="Bubble">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#00ffff" CREATED="1301248379798" ID="ID_10" MODIFIED="1301248379798"
|
||||
TEXT="As parent">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#990099" CREATED="1301248379798" ID="ID_11" MODIFIED="1301248379798"
|
||||
TEXT="Combined">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f20707" CREATED="1301248379797" ID="ID_1276955531" MODIFIED="1301248543379"
|
||||
POSITION="left" TEXT="Node Text Color">
|
||||
<node BACKGROUND_COLOR="#0000cc" COLOR="#ffff00" CREATED="1301248379797" ID="ID_1451336169"
|
||||
MODIFIED="1301248561510" TEXT="Fork">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#ccffcc" COLOR="#ff6666" CREATED="1301248379798" ID="ID_1171072015"
|
||||
MODIFIED="1301248570584" STYLE="bubble" TEXT="Bubble">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#00ffff" COLOR="#009999" CREATED="1301248379798" ID="ID_456873657"
|
||||
MODIFIED="1301248589443" TEXT="As parent">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#990099" COLOR="#009999" CREATED="1301248379798" ID="ID_1030771078"
|
||||
MODIFIED="1301248578339" TEXT="Combined">
|
||||
<edge COLOR="#808080"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</map>
|
1
wise-webapp/src/test/data/freemind/node-styles.mmr
Normal file
1
wise-webapp/src/test/data/freemind/node-styles.mmr
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="Shapes" STYLE="elipse" ID="ID_0"><node TEXT="Node Styles" POSITION="right" ID="ID_1"><node TEXT="Fork" POSITION="right" ID="ID_2"><edge COLOR="#808080"/></node><node TEXT="Bubble" STYLE="bubble" POSITION="right" ID="ID_3"><edge COLOR="#808080"/></node><node TEXT="As parent" POSITION="right" ID="ID_4"><edge COLOR="#808080"/></node><node TEXT="Combined" POSITION="right" ID="ID_5"><edge COLOR="#808080"/></node></node><node TEXT="Node Background Color" POSITION="left" ID="ID_6" BACKGROUND_COLOR="#f20707"><node TEXT="Fork" POSITION="left" ID="ID_7" BACKGROUND_COLOR="#0000cc"><edge COLOR="#808080"/></node><node TEXT="Bubble" STYLE="bubble" POSITION="left" ID="ID_8" BACKGROUND_COLOR="#ccffcc"><edge COLOR="#808080"/></node><node TEXT="As parent" POSITION="left" ID="ID_9" BACKGROUND_COLOR="#00ffff"><edge COLOR="#808080"/></node><node TEXT="Combined" POSITION="left" ID="ID_10" BACKGROUND_COLOR="#990099"><edge COLOR="#808080"/></node></node><node TEXT="Node Text Color" POSITION="left" ID="ID_11" BACKGROUND_COLOR="#f20707"><node TEXT="Fork" POSITION="left" ID="ID_12" COLOR="#ffff00" BACKGROUND_COLOR="#0000cc"><edge COLOR="#808080"/></node><node TEXT="Bubble" STYLE="bubble" POSITION="left" ID="ID_13" COLOR="#ff6666" BACKGROUND_COLOR="#ccffcc"><edge COLOR="#808080"/></node><node TEXT="As parent" POSITION="left" ID="ID_14" COLOR="#009999" BACKGROUND_COLOR="#00ffff"><edge COLOR="#808080"/></node><node TEXT="Combined" POSITION="left" ID="ID_15" COLOR="#009999" BACKGROUND_COLOR="#990099"><edge COLOR="#808080"/></node></node></node></map>
|
Loading…
Reference in New Issue
Block a user