枚举类就像一个数据集合一样.在我们的这个项目的可视化中,利用枚举类进行存储节点的id和color,本想通过解析xml的方式来实现一次配置颜色,全局使用的结果,经过分析还是利用枚举类来的更方便些也更直接些:话不多说,上代码....
/**
* this class is to build a static menu type.
* so it will be easy to manage the node/edge whth the color.
* 各种事件及其颜色搭配.
* @author lenovo
*
*/
public class Contants {
public static enum NodeColor{
nodeColor3("#090",3),
nodeColor6("#096",6),
personNodeColor("#fc6",8),
nodeColor11("#039",11),
nodeColor14("#900",14),
nodeColor16("#963",16),
timeNodeColor("#9f6",18), //时间
partyNodeColor("#93f",21), //党派
instituteNodeColor("#ddcdff",23),//组织或机构
nodeColor28("#0cf",28),
fileNodeColor("#09f",33), //文件
mettingNodeColor("#9cc",35), //会议
eventNodeColor("#6f6",36), //事件
nodeColor39("#603",39),
nodeColor41("#333",41),
organizationNodeColor("#33f",43),//机构
nodeColor44("#f3f",44),
nodeColor51("#669",51),
nodeColor66("#003",66),
nodeColor73("#00f",73),
nodeColor76("#36c",76),
nodeColor88("#f66",88),
nodeColor90("#660",90),
nodeColor117("#9f6",117),
nodeColor128("#6cc",128);
//以上是配置的枚举信息
//枚举信息的两个参数
private String color;
private Integer index;
//构造器:枚举类必备
private NodeColor(String color,Integer index){
this.color = color;
this.index = index;
}
//获取枚举信息的参数(根据id获取颜色):枚举类的遍历
public static String getColor(Integer index){
for(NodeColor nc : NodeColor.values()){
if(nc.getIndex() == index){
return nc.getColor();
}
}
return null;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}
public static enum EdgeColor{
actorColor("#ddcdff",61),//参会者
prePostsColor("#ff2",2),//曾任职务
nationalColor("#ff3",3)//民族
dieTimeColor("#ff4",4),//卒年
partyColor("#ff5",5),//所属党派
relateMettingColor("#64c",70),//相关会议
parentEventColor("#c32",82),//父事件
childEventColor("#f98",83),//子事件
setUpColor("#6f6",34),//成立
setupSituationColor("#9cc",32),//成立场合
passFileColor("#93f",67),//会议通过文件
speakerColor("#fc6",64),//发言人或报告人
filePassSituationColor("#c4c",100),//文件通过场合
electionColor("#09f",55),//选举或任命职务
appointPlaceColor("#33f",54),//任命场合
mettingTimeColor("#9f6",62);//会议时间
private String color;
private Integer index;
private EdgeColor(String color,Integer index){
this.color = color;
this.index = index;
}
public static String getColor(Integer index){
for(NodeColor nc : NodeColor.values()){
if(nc.getIndex() == index){
return nc.getColor();
}
}
return null;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}
}