]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | \r | |
3 | The file is used to override JTree to provides customized interfaces \r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | package org.tianocore.packaging.common.ui;\r | |
17 | \r | |
18 | import javax.swing.JTree;\r | |
19 | import javax.swing.tree.DefaultMutableTreeNode;\r | |
20 | import javax.swing.tree.DefaultTreeModel;\r | |
21 | import javax.swing.tree.TreeNode;\r | |
22 | import javax.swing.tree.TreePath;\r | |
23 | \r | |
24 | /**\r | |
25 | The class is used to override JTree to provides customized interfaces \r | |
26 | It extends JTree\r | |
27 | \r | |
28 | @since ModuleEditor 1.0\r | |
29 | \r | |
30 | **/\r | |
31 | public class ITree extends JTree {\r | |
32 | ///\r | |
33 | /// Define class Serial Version UID\r | |
34 | ///\r | |
35 | private static final long serialVersionUID = -7907086164518295327L;\r | |
36 | \r | |
37 | //\r | |
38 | // Define class members\r | |
39 | //\r | |
40 | DefaultTreeModel treeModel = null;\r | |
41 | \r | |
42 | /**\r | |
43 | This is the default constructor\r | |
44 | \r | |
45 | **/\r | |
46 | public ITree() {\r | |
47 | super();\r | |
48 | }\r | |
49 | \r | |
50 | /**\r | |
51 | This is the overrided constructor\r | |
52 | Init class members with input data\r | |
53 | \r | |
54 | @param iDmtRoot The root node of the tree\r | |
55 | \r | |
56 | **/\r | |
57 | public ITree(IDefaultMutableTreeNode iDmtRoot) {\r | |
58 | super(iDmtRoot);\r | |
59 | }\r | |
60 | \r | |
61 | /**\r | |
62 | Get category of selected node\r | |
63 | \r | |
64 | @return The category of selected node\r | |
65 | \r | |
66 | **/\r | |
67 | public int getSelectCategory() {\r | |
68 | int intCategory = 0;\r | |
69 | TreePath path = this.getSelectionPath();\r | |
70 | IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r | |
71 | intCategory = node.getCategory();\r | |
72 | return intCategory;\r | |
73 | }\r | |
74 | \r | |
75 | /**\r | |
76 | Get operation of selected node\r | |
77 | \r | |
78 | @return The operation of selected node\r | |
79 | \r | |
80 | **/\r | |
81 | public int getSelectOperation() {\r | |
82 | int intOperation = 0;\r | |
83 | TreePath path = this.getSelectionPath();\r | |
84 | IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r | |
85 | intOperation = node.getOperation();\r | |
86 | return intOperation;\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Get selectLoaction of selected node\r | |
91 | \r | |
92 | @return The selectLoaction of selected node\r | |
93 | \r | |
94 | **/\r | |
95 | public int getSelectLoaction() {\r | |
96 | int intLocation = 0;\r | |
97 | TreePath path = this.getSelectionPath();\r | |
98 | IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r | |
99 | intLocation = node.getLocation();\r | |
100 | return intLocation;\r | |
101 | }\r | |
102 | \r | |
103 | /**\r | |
104 | Main class, reserved for test\r | |
105 | \r | |
106 | @param args\r | |
107 | \r | |
108 | **/\r | |
109 | public static void main(String[] args) {\r | |
110 | // TODO Auto-generated method stub\r | |
111 | }\r | |
112 | \r | |
113 | /**\r | |
114 | Add input node as child node for current selected node\r | |
115 | \r | |
116 | @param strNewNode The name of the node which need be added\r | |
117 | \r | |
118 | **/\r | |
119 | public void addNode(String strNewNode) {\r | |
120 | DefaultMutableTreeNode parentNode = null;\r | |
121 | DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(strNewNode);\r | |
122 | newNode.setAllowsChildren(true);\r | |
123 | TreePath parentPath = this.getSelectionPath();\r | |
124 | \r | |
125 | /**\r | |
126 | * Get parent node of new node\r | |
127 | */\r | |
128 | parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());\r | |
129 | \r | |
130 | /**\r | |
131 | * Insert new node\r | |
132 | */\r | |
133 | treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());\r | |
134 | this.scrollPathToVisible(new TreePath(newNode.getPath()));\r | |
135 | }\r | |
136 | \r | |
137 | /**\r | |
138 | Add input node as child node for current selected node\r | |
139 | \r | |
140 | @param newNode The node need be added\r | |
141 | \r | |
142 | **/\r | |
143 | public void addNode(IDefaultMutableTreeNode newNode) {\r | |
144 | IDefaultMutableTreeNode parentNode = null;\r | |
145 | newNode.setAllowsChildren(true);\r | |
146 | TreePath parentPath = this.getSelectionPath();\r | |
147 | parentNode = (IDefaultMutableTreeNode) (parentPath.getLastPathComponent());\r | |
148 | treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());\r | |
149 | this.scrollPathToVisible(new TreePath(newNode.getPath()));\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Remove current selectd node\r | |
154 | \r | |
155 | **/\r | |
156 | public void removeNode() {\r | |
157 | TreePath treepath = this.getSelectionPath();\r | |
158 | if (treepath != null) {\r | |
159 | DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathComponent();\r | |
160 | TreeNode parent = (TreeNode) selectionNode.getParent();\r | |
161 | if (parent != null) {\r | |
162 | treeModel.removeNodeFromParent(selectionNode);\r | |
163 | }\r | |
164 | }\r | |
165 | }\r | |
166 | \r | |
167 | /**\r | |
168 | Remove all node on a same level\r | |
169 | \r | |
170 | **/\r | |
171 | public void removeNodeOnSameLevel() {\r | |
172 | TreePath treepath = this.getSelectionPath();\r | |
173 | IDefaultMutableTreeNode parentNode = (IDefaultMutableTreeNode) treepath.getLastPathComponent();\r | |
174 | parentNode.removeAllChildren();\r | |
175 | treeModel.reload();\r | |
176 | }\r | |
177 | \r | |
178 | /**\r | |
179 | Remove the input node by name\r | |
180 | \r | |
181 | @param strRemovedNode\r | |
182 | \r | |
183 | **/\r | |
184 | public void removeNode(String strRemovedNode) {\r | |
185 | TreePath treepath = this.getSelectionPath();\r | |
186 | if (treepath != null) {\r | |
187 | DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathComponent();\r | |
188 | TreeNode parent = (TreeNode) selectionNode.getParent();\r | |
189 | if (parent != null) {\r | |
190 | treeModel.removeNodeFromParent(selectionNode);\r | |
191 | }\r | |
192 | }\r | |
193 | }\r | |
194 | \r | |
195 | /**\r | |
196 | Remove all nodes of the tree\r | |
197 | \r | |
198 | **/\r | |
199 | public void removeAllNode() {\r | |
200 | DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();\r | |
201 | rootNode.removeAllChildren();\r | |
202 | treeModel.reload();\r | |
203 | }\r | |
204 | }\r |