1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.zmpp.debug;
24
25 import java.awt.BorderLayout;
26 import java.awt.FlowLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import javax.swing.JButton;
33 import javax.swing.JFrame;
34 import javax.swing.JPanel;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTree;
37
38 import org.zmpp.debug.ObjectTreeModel.ObjWrapper;
39 import org.zmpp.vm.Machine3;
40 import org.zmpp.vm.ObjectTree;
41 import org.zmpp.vm.ZObject;
42
43 public class ObjectTreeFrame extends JFrame implements ActionListener {
44
45 private ObjectTreeModel treeModel;
46 private ObjectTree objectTree;
47 private static final long serialVersionUID = 1L;
48
49 public ObjectTreeFrame(Machine3 machine) {
50 super("Object tree");
51
52 treeModel = new ObjectTreeModel(machine, machine.getObjectTree());
53 JTree tree = new JTree(treeModel);
54 this.objectTree = machine.getObjectTree();
55 JScrollPane spane = new JScrollPane(tree);
56 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
57 JButton okButton = new JButton("Ok");
58 buttonPanel.add(okButton);
59 okButton.addActionListener(this);
60 getContentPane().add(spane, BorderLayout.CENTER);
61 getContentPane().add(buttonPanel, BorderLayout.SOUTH);
62 update();
63 }
64
65 public void update() {
66
67 int numObjects = objectTree.getNumObjects();
68 List<ObjWrapper> rootObjs = new ArrayList<ObjWrapper>();
69
70 for (int i = 1; i <= numObjects; i++) {
71
72 ZObject obj = objectTree.getObject((short) i);
73 if (obj.getParent() == 0) {
74
75 ObjWrapper tlnode = treeModel.createObjWrapper();
76 tlnode.id = i;
77 tlnode.obj = obj;
78 rootObjs.add(tlnode);
79 }
80 }
81 treeModel.setToplevelObjects(rootObjs);
82 }
83
84 public void actionPerformed(ActionEvent e) {
85
86 System.out.println("update");
87 update();
88 }
89 }