- Mode dynamic way to declare new icons.

This commit is contained in:
Paulo Gustavo Veiga
2011-03-21 17:38:05 -03:00
parent 5d0d837062
commit 107e559364
31 changed files with 95 additions and 301 deletions

View File

@@ -19,35 +19,20 @@
package com.wisemapping.model;
public enum IconFamily {
FLAG("FLAG","flag_"),
BULLET("BULLET","bullet_"),
TAG("TAG","tag_"),
NUMBER("NUMBER","number_"),
SMILEY("FACE","face_"),
ARROW("ARROW","arrow_"),
ARROWC("ARROWC","arrowc_"),
CONN("CONN","conn_"),
BULB("BULB","bulb_"),
THUMB("THUMB","thumb_"),
TICK("TICK","tick_"),
ONOFF("ONOFF","onoff_"),
MONEY("MONEY","money_"),
CHART("CHART","chart_"),
TASK("TASK","task_");
FLAG(),
BULLET(),
TAG(),
// NUMBER("NUMBER","number_"),
FACE(),
FUNY(),
ARROW(),
ARROWC(),
CONN(),
BULB(),
THUMB(),
TICK(),
ONOFF(),
MONEY(),
CHART();
private String prefix;
private String name;
IconFamily(String name, String prefix) {
this.name = name;
this.prefix = prefix;
}
public String getPrefix() {
return prefix;
}
public String getName() {
return name;
}
}

View File

@@ -18,29 +18,24 @@
package com.wisemapping.model;
public class MindmapIcon
{
public class MindmapIcon {
private String name;
private IconFamily family;
MindmapIcon(IconFamily family, String name)
{
MindmapIcon(IconFamily family, String name) {
this.name = name;
this.family = family;
}
public String getName()
{
public String getName() {
return name;
}
public IconFamily getFamily()
{
public IconFamily getFamily() {
return family;
}
public String getId()
{
return family.getPrefix() + name;
public String getId() {
return family.name().toLowerCase() + "_" + name;
}
}

View File

@@ -29,12 +29,12 @@ public class MindmapIcons {
private static Map<IconFamily, List<MindmapIcon>> iconsByFamily;
public static final MindmapIcon FACE_PLAIN = new MindmapIcon(IconFamily.SMILEY, "plain");
public static final MindmapIcon FACE_SAD = new MindmapIcon(IconFamily.SMILEY, "sad");
public static final MindmapIcon FACE_CRYING = new MindmapIcon(IconFamily.SMILEY, "crying");
public static final MindmapIcon FACE_SMILE = new MindmapIcon(IconFamily.SMILEY, "smile");
public static final MindmapIcon FACE_SURPRISE = new MindmapIcon(IconFamily.SMILEY, "surprise");
public static final MindmapIcon FACE_WINK = new MindmapIcon(IconFamily.SMILEY, "wink");
public static final MindmapIcon FACE_PLAIN = new MindmapIcon(IconFamily.FACE, "plain");
public static final MindmapIcon FACE_SAD = new MindmapIcon(IconFamily.FACE, "sad");
public static final MindmapIcon FACE_CRYING = new MindmapIcon(IconFamily.FACE, "crying");
public static final MindmapIcon FACE_SMILE = new MindmapIcon(IconFamily.FACE, "smile");
public static final MindmapIcon FACE_SURPRISE = new MindmapIcon(IconFamily.FACE, "surprise");
public static final MindmapIcon FACE_WINK = new MindmapIcon(IconFamily.FACE, "wink");
public static final MindmapIcon THUMB__UP = new MindmapIcon(IconFamily.THUMB, "thumb_up");
public static final MindmapIcon THUMB_DOWN = new MindmapIcon(IconFamily.THUMB, "thumb_down");
@@ -44,13 +44,13 @@ public class MindmapIcons {
public static final MindmapIcon ARROW_LEFT = new MindmapIcon(IconFamily.ARROW, "left");
public static final MindmapIcon ARROW_RIGHT = new MindmapIcon(IconFamily.ARROW, "right");
public static final MindmapIcon TASK_ONE = new MindmapIcon(IconFamily.TASK, "one");
public static final MindmapIcon TASK_TWO = new MindmapIcon(IconFamily.TASK, "two");
public static final MindmapIcon TASK_THREE = new MindmapIcon(IconFamily.TASK, "three");
public static final MindmapIcon TASK_FOUR = new MindmapIcon(IconFamily.TASK, "four");
public static final MindmapIcon TASK_FIVE = new MindmapIcon(IconFamily.TASK, "five");
// public static final MindmapIcon TASK_ONE = new MindmapIcon(IconFamily.TASK, "one");
// public static final MindmapIcon TASK_TWO = new MindmapIcon(IconFamily.TASK, "two");
// public static final MindmapIcon TASK_THREE = new MindmapIcon(IconFamily.TASK, "three");
// public static final MindmapIcon TASK_FOUR = new MindmapIcon(IconFamily.TASK, "four");
// public static final MindmapIcon TASK_FIVE = new MindmapIcon(IconFamily.TASK, "five");
public static final MindmapIcon ARROWC_UNDO = new MindmapIcon(IconFamily.ARROWC, "undo");
// public static final MindmapIcon ARROWC_UNDO = new MindmapIcon(IconFamily.ARROWC, "undo");
public static final MindmapIcon ARROWC_ANTICLOCK_WISE = new MindmapIcon(IconFamily.ARROWC, "rotate_anticlockwise");
public static final MindmapIcon ARROWC_CLOCK_WISE = new MindmapIcon(IconFamily.ARROWC, "rotate_clockwise");
public static final MindmapIcon ARROWC_LEFT = new MindmapIcon(IconFamily.ARROWC, "turn_left");
@@ -80,15 +80,23 @@ public class MindmapIcons {
public static final MindmapIcon TAG_PINK = new MindmapIcon(IconFamily.TAG, "pink");
public static final MindmapIcon TAG_YELLOW = new MindmapIcon(IconFamily.TAG, "yellow");
public static final MindmapIcon NUMBER_ONE = new MindmapIcon(IconFamily.NUMBER, "one");
public static final MindmapIcon NUMBER_TWO = new MindmapIcon(IconFamily.NUMBER, "two");
public static final MindmapIcon NUMBER_THREE = new MindmapIcon(IconFamily.NUMBER, "three");
public static final MindmapIcon NUMBER_FOUR = new MindmapIcon(IconFamily.NUMBER, "four");
public static final MindmapIcon NUMBER_FIVE = new MindmapIcon(IconFamily.NUMBER, "five");
public static final MindmapIcon NUMBER_SIX = new MindmapIcon(IconFamily.NUMBER, "six");
public static final MindmapIcon NUMBER_SEVEN = new MindmapIcon(IconFamily.NUMBER, "seven");
public static final MindmapIcon NUMBER_EIGHT = new MindmapIcon(IconFamily.NUMBER, "eight");
public static final MindmapIcon NUMBER_NINE = new MindmapIcon(IconFamily.NUMBER, "nine");
// public static final MindmapIcon NUMBER_ONE = new MindmapIcon(IconFamily.NUMBER, "one");
// public static final MindmapIcon NUMBER_TWO = new MindmapIcon(IconFamily.NUMBER, "two");
// public static final MindmapIcon NUMBER_THREE = new MindmapIcon(IconFamily.NUMBER, "three");
// public static final MindmapIcon NUMBER_FOUR = new MindmapIcon(IconFamily.NUMBER, "four");
// public static final MindmapIcon NUMBER_FIVE = new MindmapIcon(IconFamily.NUMBER, "five");
// public static final MindmapIcon NUMBER_SIX = new MindmapIcon(IconFamily.NUMBER, "six");
// public static final MindmapIcon NUMBER_SEVEN = new MindmapIcon(IconFamily.NUMBER, "seven");
// public static final MindmapIcon NUMBER_EIGHT = new MindmapIcon(IconFamily.NUMBER, "eight");
// public static final MindmapIcon NUMBER_NINE = new MindmapIcon(IconFamily.NUMBER, "nine");
public static final MindmapIcon FUNNY_ANGEL = new MindmapIcon(IconFamily.FUNY, "angel");
public static final MindmapIcon FUNNY_DEVILISH = new MindmapIcon(IconFamily.FUNY, "devilish");
public static final MindmapIcon FUNNY_GLASSES = new MindmapIcon(IconFamily.FUNY, "glasses");
public static final MindmapIcon FUNNY_GRIN = new MindmapIcon(IconFamily.FUNY, "grin");
public static final MindmapIcon FUNNY_KISS = new MindmapIcon(IconFamily.FUNY, "kiss");
public static final MindmapIcon FUNNY_MONKEY = new MindmapIcon(IconFamily.FUNY, "monkey");
public static final MindmapIcon FLAG_BLUE = new MindmapIcon(IconFamily.FLAG, "blue");
public static final MindmapIcon FLAG_GREEN = new MindmapIcon(IconFamily.FLAG, "green");

View File

Before

Width:  |  Height:  |  Size: 608 B

After

Width:  |  Height:  |  Size: 608 B

View File

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 602 B

View File

Before

Width:  |  Height:  |  Size: 516 B

After

Width:  |  Height:  |  Size: 516 B

View File

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 489 B

View File

Before

Width:  |  Height:  |  Size: 700 B

After

Width:  |  Height:  |  Size: 700 B

View File

Before

Width:  |  Height:  |  Size: 782 B

After

Width:  |  Height:  |  Size: 782 B

View File

Before

Width:  |  Height:  |  Size: 748 B

After

Width:  |  Height:  |  Size: 748 B

View File

Before

Width:  |  Height:  |  Size: 796 B

After

Width:  |  Height:  |  Size: 796 B

View File

Before

Width:  |  Height:  |  Size: 992 B

After

Width:  |  Height:  |  Size: 992 B

View File

Before

Width:  |  Height:  |  Size: 855 B

After

Width:  |  Height:  |  Size: 855 B

View File

Before

Width:  |  Height:  |  Size: 949 B

After

Width:  |  Height:  |  Size: 949 B

View File

Before

Width:  |  Height:  |  Size: 905 B

After

Width:  |  Height:  |  Size: 905 B

View File

Before

Width:  |  Height:  |  Size: 919 B

After

Width:  |  Height:  |  Size: 919 B

View File

Before

Width:  |  Height:  |  Size: 784 B

After

Width:  |  Height:  |  Size: 784 B

View File

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 732 B

View File

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 738 B

View File

Before

Width:  |  Height:  |  Size: 592 B

After

Width:  |  Height:  |  Size: 592 B

View File

Before

Width:  |  Height:  |  Size: 733 B

After

Width:  |  Height:  |  Size: 733 B

View File

Before

Width:  |  Height:  |  Size: 882 B

After

Width:  |  Height:  |  Size: 882 B

View File

Before

Width:  |  Height:  |  Size: 889 B

After

Width:  |  Height:  |  Size: 889 B

View File

Before

Width:  |  Height:  |  Size: 715 B

After

Width:  |  Height:  |  Size: 715 B

View File

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 601 B

View File

Before

Width:  |  Height:  |  Size: 619 B

After

Width:  |  Height:  |  Size: 619 B

View File

Before

Width:  |  Height:  |  Size: 655 B

After

Width:  |  Height:  |  Size: 655 B

View File

Before

Width:  |  Height:  |  Size: 537 B

After

Width:  |  Height:  |  Size: 537 B

View File

@@ -461,7 +461,7 @@ function buildIconChooser() {
var count = 0;
for (var i = 0; i < mindplot.ImageIcon.prototype.ICON_FAMILIES.length; i = i + 1)
{
var familyIcons = mindplot.ImageIcon.prototype.ICON_FAMILIES[i];
var familyIcons = mindplot.ImageIcon.prototype.ICON_FAMILIES[i].icons;
for (var j = 0; j < familyIcons.length; j = j + 1)
{
// Separate icons by line ...

View File

@@ -12,6 +12,8 @@ import java.util.List;
@Test
public class IconsTest {
final private static String CURRENT_JSON_ICONS = "[{\"id\": \"flag\", \"icons\" : [\"flag_blue\",\"flag_green\",\"flag_orange\",\"flag_pink\",\"flag_purple\",\"flag_yellow\"]},{\"id\": \"bullet\", \"icons\" : [\"bullet_black\",\"bullet_blue\",\"bullet_green\",\"bullet_orange\",\"bullet_red\",\"bullet_pink\",\"bullet_purple\"]},{\"id\": \"tag\", \"icons\" : [\"tag_blue\",\"tag_green\",\"tag_orange\",\"tag_red\",\"tag_pink\",\"tag_yellow\"]},{\"id\": \"face\", \"icons\" : [\"face_plain\",\"face_sad\",\"face_crying\",\"face_smile\",\"face_surprise\",\"face_wink\"]},{\"id\": \"funy\", \"icons\" : [\"funy_angel\",\"funy_devilish\",\"funy_glasses\",\"funy_grin\",\"funy_kiss\",\"funy_monkey\"]},{\"id\": \"arrow\", \"icons\" : [\"arrow_up\",\"arrow_down\",\"arrow_left\",\"arrow_right\"]},{\"id\": \"arrowc\", \"icons\" : [\"arrowc_rotate_anticlockwise\",\"arrowc_rotate_clockwise\",\"arrowc_turn_left\",\"arrowc_turn_right\"]},{\"id\": \"conn\", \"icons\" : [\"conn_connect\",\"conn_disconnect\"]},{\"id\": \"bulb\", \"icons\" : [\"bulb_light_on\",\"bulb_light_off\"]},{\"id\": \"thumb\", \"icons\" : [\"thumb_thumb_up\",\"thumb_thumb_down\"]},{\"id\": \"tick\", \"icons\" : [\"tick_tick\",\"tick_cross\"]},{\"id\": \"onoff\", \"icons\" : [\"onoff_clock\",\"onoff_clock_red\",\"onoff_add\",\"onoff_delete\"]},{\"id\": \"money\", \"icons\" : [\"money_money\",\"money_dollar\",\"money_euro\",\"money_pound\",\"money_yen\",\"money_coins\",\"money_ruby\"]},{\"id\": \"chart\", \"icons\" : [\"chart_bar\",\"chart_line\",\"chart_curve\",\"chart_pie\",\"chart_organisation\"]},]";
@Test
void checkImagesByFamily() throws IllegalAccessException {
List<MindmapIcon> iconByFamily = MindmapIcons.getIconByFamily(IconFamily.BULLET);
@@ -27,21 +29,40 @@ public class IconsTest {
final List<MindmapIcon> iconByFamily = MindmapIcons.getIconByFamily(family);
for (MindmapIcon mindmapIcon : iconByFamily) {
final String pngName = mindmapIcon.getId() + ".png";
File file = new File("src/main/webapp/icons/", pngName);
if (!file.exists()) {
System.err.println("File not found:" + pngName);
}
// else {
// System.err.println("Found:" + pngName);
// }
final File file = new File("src/main/webapp/icons/", pngName);
Assert.assertTrue(file.exists(), "Could not be found:" + file.getAbsolutePath());
}
}
}
@Test
void jsonGenerationRepresentation() {
IconFamily[] values = IconFamily.values();
final StringBuilder result = new StringBuilder("[");
for (IconFamily family : values) {
result.append("{");
result.append("\"id\": \"" + family.name().toLowerCase() + "\"");
result.append(", \"icons\" : [");
final List<MindmapIcon> iconByFamily = MindmapIcons.getIconByFamily(family);
for (int i = 0; i < iconByFamily.size(); i++) {
if (i != 0) {
result.append(",");
}
MindmapIcon mindmapIcon = iconByFamily.get(i);
result.append("\"" + mindmapIcon.getId() + "\"");
}
result.append("]},");
}
result.append("]");
System.out.println(result.toString());
Assert.assertEquals(result.toString(), CURRENT_JSON_ICONS, "Some change has been introduced in the icons library. Please, check the IconIcons.js and update the variable.mindplot.ImageIcon.prototype.ICON_FAMILIES");
}
}