Turn to Regex in ModuleReader.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / MsaTreeEditor.java
1 package org.tianocore.migration;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6 import javax.swing.tree.*;
7
8 public class MsaTreeEditor extends JPanel {
9 MsaTreeEditor(ModuleInfo m, UI u) {
10 mi = m;
11 ui = u;
12
13 rootNode = new DefaultMutableTreeNode("Root Node");
14 treeModel = new DefaultTreeModel(rootNode);
15
16 tree = new JTree(treeModel);
17 tree.setEditable(true);
18 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
19 tree.setShowsRootHandles(false);
20 tree.addMouseListener(mouseadapter);
21
22 JScrollPane scrollPane = new JScrollPane(tree);
23 add(scrollPane);
24
25 popupmenu = new JPopupMenu();
26 JMenuItem menuitemadd = new JMenuItem("addNode");
27 JMenuItem menuitemdel = new JMenuItem("deleteNode");
28 popupmenu.add(menuitemadd);
29 popupmenu.add(menuitemdel);
30 menuitemadd.addActionListener(actionListener);
31 menuitemdel.addActionListener(actionListener);
32
33 addNode(rootNode, "1st");
34 addNode(rootNode, "2nd");
35 }
36
37 private ModuleInfo mi;
38 private UI ui;
39
40 private JTree tree;
41 private DefaultMutableTreeNode rootNode;
42 private DefaultTreeModel treeModel;
43
44 private JPopupMenu popupmenu;
45 private MouseAdapter mouseadapter = new MouseAdapter() {
46 public void mouseReleased(MouseEvent me) {
47 if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {
48 tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));
49 popupmenu.show(tree, me.getX(), me.getY());
50 }
51 }
52 };
53 private ActionListener actionListener = new ActionListener() {
54 public void actionPerformed(ActionEvent ae) {
55 addNode();
56 }
57 };
58
59 public void addNode() {
60 addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));
61 System.out.println();
62 }
63
64 public void addNode(DefaultMutableTreeNode parentNode, Object child) {
65 DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
66 treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
67 tree.scrollPathToVisible(new TreePath(childNode.getPath()));
68 }
69
70 public static void init(ModuleInfo mi, UI ui) throws Exception {
71 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
72
73 JFrame frame = new JFrame("MsaTreeEditor");
74 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75
76 MsaTreeEditor mte = new MsaTreeEditor(mi, ui);
77 mte.setLayout(new GridBagLayout());
78 mte.setOpaque(true);
79 frame.setContentPane(mte);
80
81 frame.pack();
82 frame.setVisible(true);
83 }
84 }