3 The file is used to override JTree to provides customized interfaces
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.packaging
.common
.ui
;
18 import javax
.swing
.JTree
;
19 import javax
.swing
.tree
.DefaultMutableTreeNode
;
20 import javax
.swing
.tree
.DefaultTreeModel
;
21 import javax
.swing
.tree
.TreeNode
;
22 import javax
.swing
.tree
.TreePath
;
25 The class is used to override JTree to provides customized interfaces
28 @since ModuleEditor 1.0
31 public class ITree
extends JTree
{
33 /// Define class Serial Version UID
35 private static final long serialVersionUID
= -7907086164518295327L;
38 // Define class members
40 DefaultTreeModel treeModel
= null;
43 This is the default constructor
51 This is the overrided constructor
52 Init class members with input data
54 @param iDmtRoot The root node of the tree
57 public ITree(IDefaultMutableTreeNode iDmtRoot
) {
62 Get category of selected node
64 @return The category of selected node
67 public int getSelectCategory() {
69 TreePath path
= this.getSelectionPath();
70 IDefaultMutableTreeNode node
= (IDefaultMutableTreeNode
) path
.getLastPathComponent();
71 intCategory
= node
.getCategory();
76 Get operation of selected node
78 @return The operation of selected node
81 public int getSelectOperation() {
83 TreePath path
= this.getSelectionPath();
84 IDefaultMutableTreeNode node
= (IDefaultMutableTreeNode
) path
.getLastPathComponent();
85 intOperation
= node
.getOperation();
90 Get selectLoaction of selected node
92 @return The selectLoaction of selected node
95 public int getSelectLoaction() {
97 TreePath path
= this.getSelectionPath();
98 IDefaultMutableTreeNode node
= (IDefaultMutableTreeNode
) path
.getLastPathComponent();
99 intLocation
= node
.getLocation();
104 Main class, reserved for test
109 public static void main(String
[] args
) {
110 // TODO Auto-generated method stub
114 Add input node as child node for current selected node
116 @param strNewNode The name of the node which need be added
119 public void addNode(String strNewNode
) {
120 DefaultMutableTreeNode parentNode
= null;
121 DefaultMutableTreeNode newNode
= new DefaultMutableTreeNode(strNewNode
);
122 newNode
.setAllowsChildren(true);
123 TreePath parentPath
= this.getSelectionPath();
126 * Get parent node of new node
128 parentNode
= (DefaultMutableTreeNode
) (parentPath
.getLastPathComponent());
133 treeModel
.insertNodeInto(newNode
, parentNode
, parentNode
.getChildCount());
134 this.scrollPathToVisible(new TreePath(newNode
.getPath()));
138 Add input node as child node for current selected node
140 @param newNode The node need be added
143 public void addNode(IDefaultMutableTreeNode newNode
) {
144 IDefaultMutableTreeNode parentNode
= null;
145 newNode
.setAllowsChildren(true);
146 TreePath parentPath
= this.getSelectionPath();
147 parentNode
= (IDefaultMutableTreeNode
) (parentPath
.getLastPathComponent());
148 treeModel
.insertNodeInto(newNode
, parentNode
, parentNode
.getChildCount());
149 this.scrollPathToVisible(new TreePath(newNode
.getPath()));
153 Remove current selectd node
156 public void removeNode() {
157 TreePath treepath
= this.getSelectionPath();
158 if (treepath
!= null) {
159 DefaultMutableTreeNode selectionNode
= (DefaultMutableTreeNode
) treepath
.getLastPathComponent();
160 TreeNode parent
= (TreeNode
) selectionNode
.getParent();
161 if (parent
!= null) {
162 treeModel
.removeNodeFromParent(selectionNode
);
168 Remove all node on a same level
171 public void removeNodeOnSameLevel() {
172 TreePath treepath
= this.getSelectionPath();
173 IDefaultMutableTreeNode parentNode
= (IDefaultMutableTreeNode
) treepath
.getLastPathComponent();
174 parentNode
.removeAllChildren();
179 Remove the input node by name
181 @param strRemovedNode
184 public void removeNode(String strRemovedNode
) {
185 TreePath treepath
= this.getSelectionPath();
186 if (treepath
!= null) {
187 DefaultMutableTreeNode selectionNode
= (DefaultMutableTreeNode
) treepath
.getLastPathComponent();
188 TreeNode parent
= (TreeNode
) selectionNode
.getParent();
189 if (parent
!= null) {
190 treeModel
.removeNodeFromParent(selectionNode
);
196 Remove all nodes of the tree
199 public void removeAllNode() {
200 DefaultMutableTreeNode rootNode
= (DefaultMutableTreeNode
) treeModel
.getRoot();
201 rootNode
.removeAllChildren();