001package com.ganteater.ae; 002 003import java.awt.Color; 004import java.io.File; 005import java.io.FileInputStream; 006import java.io.IOException; 007import java.util.ArrayList; 008 009import org.apache.commons.io.IOUtils; 010import org.apache.commons.lang.StringEscapeUtils; 011import org.apache.commons.lang3.StringUtils; 012 013import com.ganteater.ae.util.xml.easyparser.Node; 014 015public class CustomizedMenu extends ArrayList<CustomizedMenu.Item> { 016 017 private static final long serialVersionUID = 1L; 018 019 public class Item { 020 021 private Node taskNode; 022 private String name; 023 private String toolTip; 024 private String image; 025 private Color color; 026 private String description; 027 028 public Item(Node node) { 029 taskNode = node; 030 031 this.name = taskNode.getAttribute("name"); 032 if (this.name == null) 033 this.name = taskNode.getAttribute("task"); 034 035 this.toolTip = taskNode.getAttribute("tooltip"); 036 this.image = taskNode.getAttribute("icon"); 037 038 String colorStr = taskNode.getAttribute("color"); 039 if (colorStr != null) { 040 Color color; 041 try { 042 color = (Color) Color.class.getDeclaredField(colorStr.toLowerCase()).get(null); 043 setColor(color); 044 } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException 045 | SecurityException e) { 046 e.printStackTrace(); 047 } 048 } 049 050 String text = node.getInnerXMLText(); 051 description = StringEscapeUtils.unescapeXml(text); 052 053 if (description != null) { 054 String path = taskNode.getAttribute("file"); 055 File file = AEWorkspace.getInstance().getFile(path); 056 if (file != null) { 057 try { 058 description = IOUtils.toString(new FileInputStream(file)); 059 } catch (IOException e) { 060 e.printStackTrace(); 061 } 062 } 063 } 064 } 065 066 public String getName() { 067 return name; 068 } 069 070 public String getToolTip() { 071 return toolTip; 072 } 073 074 public String getIcon() { 075 return image; 076 } 077 078 public Node getTaskNode() { 079 return taskNode; 080 } 081 082 public Color getColor() { 083 return color; 084 } 085 086 public void setColor(Color color) { 087 this.color = color; 088 } 089 090 public String getDescription() { 091 return StringUtils.defaultString(description, ""); 092 } 093 094 } 095 096 private String title; 097 private Color color; 098 099 public void setTitle(String title) { 100 this.title = title; 101 } 102 103 public void addItem(Node taskNode) { 104 add(new Item(taskNode)); 105 } 106 107 public String getTitle() { 108 return title; 109 } 110 111 public Color getColor() { 112 return color; 113 } 114 115 public void setColor(Color color) { 116 this.color = color; 117 } 118 119}