Fix image mappings issue during export/import to freemind.

This commit is contained in:
Paulo Gustavo Veiga
2011-03-20 22:49:31 -03:00
parent 4ae0258411
commit d5ac7376b3
13 changed files with 518 additions and 405 deletions

View File

@@ -0,0 +1,99 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.importer.freemind;
import com.wisemapping.model.MindmapIcon;
import com.wisemapping.model.MindmapIcons;
import com.wisemapping.model.IconFamily;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
final public class FreemindIconConverter {
private final static Map<String, MindmapIcon> freeIdToIcon = new HashMap<String, MindmapIcon>();
private final static Map<MindmapIcon, String> iconToFreeId = new HashMap<MindmapIcon, String>();
private static final MindmapIcon DEFAULT_ICON = MindmapIcons.getIconByFamily(IconFamily.BULLET).get(3);
private FreemindIconConverter() {
}
@Nullable
public static String toWiseId(@NotNull String iconId) {
final MindmapIcon result = freeIdToIcon.get(iconId);
return result!=null?result.getId():null;
}
@Nullable
public static String toFreemindId(@NotNull String iconId) {
return iconToFreeId.get(MindmapIcons.findById(iconId));
}
static {
// Load bullets image mapping ...
final List<MindmapIcon> bulletsImages = MindmapIcons.getIconByFamily(IconFamily.BULLET);
for (int i = 0; i < bulletsImages.size(); i++) {
final MindmapIcon icon = bulletsImages.get(i);
iconToFreeId.put(icon, "full-" + i);
}
final List<MindmapIcon> bulbImages = MindmapIcons.getIconByFamily(IconFamily.BULB);
iconToFreeId.put(bulbImages.get(0), "idea");
final List<MindmapIcon> tickImages = MindmapIcons.getIconByFamily(IconFamily.TICK);
iconToFreeId.put(tickImages.get(0), "button_ok");
iconToFreeId.put(tickImages.get(1), "button_cancel");
// Map arrow icons ...
iconToFreeId.put(MindmapIcons.ARROW_UP, "up");
iconToFreeId.put(MindmapIcons.ARROW_DOWN, "down");
iconToFreeId.put(MindmapIcons.ARROW_RIGHT, "back");
iconToFreeId.put(MindmapIcons.ARROW_LEFT, "forward");
// Map smile icons ...
iconToFreeId.put(MindmapIcons.FACE_PLAIN, "smiley-neutral");
iconToFreeId.put(MindmapIcons.FACE_SMILE, "ksmiletris");
iconToFreeId.put(MindmapIcons.FACE_SURPRISE, "smiley-oh");
iconToFreeId.put(MindmapIcons.FACE_SAD, "smiley_bad");
// Maps Flag familly Icons ...
final List<MindmapIcon> flagImages = MindmapIcons.getIconByFamily(IconFamily.FLAG);
for (MindmapIcon flagImage : flagImages) {
iconToFreeId.put(flagImage, "flag-" + flagImage.getName());
}
final Set<MindmapIcon> mindmapIcons = iconToFreeId.keySet();
for (MindmapIcon mindmapIcon : mindmapIcons) {
freeIdToIcon.put(iconToFreeId.get(mindmapIcon), mindmapIcon);
}
}
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.importer.freemind;
import com.wisemapping.model.MindmapImage;
import com.wisemapping.model.MindmapImagesFactory;
import com.wisemapping.model.ImageFamily;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
public class FreemindIconMapper {
private static Map<String,String> freemindToMindmapIcon = new HashMap<String,String>();
private static final MindmapImage DEFAULT_ICON = MindmapImagesFactory.getImagesByFamily(ImageFamily.BULLET).get(3);
public FreemindIconMapper()
{
}
public static String getMindmapIcon(String freemindIconId)
{
String iconId = freemindToMindmapIcon.get(freemindIconId);
// The image doesn´t exists in freemind select he default image
if (iconId == null)
{
iconId = DEFAULT_ICON.getId();
}
return iconId;
}
static {
List<MindmapImage> images = MindmapImagesFactory.getImagesByFamily(ImageFamily.BULLET);
freemindToMindmapIcon.put( "full-1",images.get(0).getId());
freemindToMindmapIcon.put( "full-2",images.get(1).getId());
freemindToMindmapIcon.put( "full-3",images.get(2).getId());
freemindToMindmapIcon.put( "full-4",images.get(3).getId());
freemindToMindmapIcon.put( "full-5",images.get(4).getId());
freemindToMindmapIcon.put( "full-6",images.get(5).getId());
freemindToMindmapIcon.put( "full-7",images.get(6).getId());
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.BULB);
freemindToMindmapIcon.put( "idea",images.get(0).getId());
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.TICK);
freemindToMindmapIcon.put( "button_ok",images.get(0).getId());
freemindToMindmapIcon.put( "button_cancel",images.get(1).getId());
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.ARROW);
freemindToMindmapIcon.put( "back",images.get(2).getId());
freemindToMindmapIcon.put( "forward",images.get(3).getId());
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.FACE);
freemindToMindmapIcon.put( "ksmiletris",images.get(3).getId());
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.FLAG);
final MindmapImage orangeFlag = images.get(2);
freemindToMindmapIcon.put("flag", orangeFlag.getId());
}
}

View File

@@ -266,17 +266,22 @@ public class FreemindImporter
currentTopic.setBrColor(edge.getCOLOR());
} else if (freemindNode instanceof Icon) {
final Icon freemindIcon = (Icon) freemindNode;
final com.wisemapping.xml.mindmap.Icon mindmapIcon = new com.wisemapping.xml.mindmap.Icon();
final String mindmapIconId = FreemindIconMapper.getMindmapIcon(freemindIcon.getBUILTIN());
mindmapIcon.setId(mindmapIconId);
currentTopic.getIcon().add(mindmapIcon);
String iconId = freemindIcon.getBUILTIN();
final String wiseIconId = FreemindIconConverter.toWiseId(iconId);
if (wiseIconId != null) {
final com.wisemapping.xml.mindmap.Icon mindmapIcon = new com.wisemapping.xml.mindmap.Icon();
mindmapIcon.setId(wiseIconId);
currentTopic.getIcon().add(mindmapIcon);
}
} else if (freemindNode instanceof Hook) {
final Hook hook = (Hook) freemindNode;
final com.wisemapping.xml.mindmap.Note mindmapNote = new com.wisemapping.xml.mindmap.Note();
String textNote = hook.getText();
if (textNote == null) // It is not a note is a BlinkingNodeHook or AutomaticLayout Hook
{
textNote = textNote != null ? textNote.replaceAll("\n", "%0A") : EMPTY_NOTE;
textNote = EMPTY_NOTE;
mindmapNote.setText(textNote);
currentTopic.setNote(mindmapNote);
}
@@ -285,9 +290,9 @@ public class FreemindImporter
final String type = content.getTYPE();
if (type.equals("NODE")) {
final String text = getText(content);
text.replaceAll("\n", "");
text.trim();
String text = getText(content);
text = text.replaceAll("\n", "");
text = text.trim();
currentTopic.setText(text);
} else {
String text = getRichContent(content);