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