0
|
1 /*
|
|
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.bugspot;
|
|
26
|
|
27 import java.awt.*;
|
|
28 import java.util.*;
|
|
29 import javax.swing.*;
|
|
30 import javax.swing.table.*;
|
|
31
|
|
32 import sun.jvm.hotspot.debugger.*;
|
|
33
|
|
34 /** Displays registers in a window. FIXME: this will need more work to
|
|
35 understand and handle register windows. */
|
|
36
|
|
37 public class RegisterPanel extends JPanel {
|
|
38 private java.util.List/*<RegisterInfo>*/ registers;
|
|
39 private AbstractTableModel dataModel;
|
|
40 private boolean valid;
|
|
41 private boolean editable;
|
|
42 private String nullAddressString;
|
|
43 private ThreadProxy curThread;
|
|
44 private JTable table;
|
|
45
|
|
46 static class RegisterInfo {
|
|
47 private String name;
|
|
48 private Address value;
|
|
49
|
|
50 RegisterInfo(String name, Address value) {
|
|
51 this.name = name;
|
|
52 this.value = value;
|
|
53 }
|
|
54
|
|
55 String getName() { return name; }
|
|
56 Address getValue() { return value; }
|
|
57 }
|
|
58
|
|
59 public RegisterPanel() {
|
|
60 super();
|
|
61
|
|
62 registers = new ArrayList();
|
|
63
|
|
64 dataModel = new AbstractTableModel() {
|
|
65 public int getColumnCount() { return 2; }
|
|
66 public int getRowCount() { return registers.size(); }
|
|
67 public String getColumnName(int col) {
|
|
68 switch (col) {
|
|
69 case 0:
|
|
70 return "Register Name";
|
|
71 case 1:
|
|
72 return "Register Value";
|
|
73 default:
|
|
74 throw new RuntimeException("Index " + col + " out of bounds");
|
|
75 }
|
|
76 }
|
|
77 public Object getValueAt(int row, int col) {
|
|
78 RegisterInfo info = (RegisterInfo) registers.get(row);
|
|
79
|
|
80 switch (col) {
|
|
81 case 0:
|
|
82 return info.getName();
|
|
83 case 1:
|
|
84 if (valid) {
|
|
85 Address val = info.getValue();
|
|
86 if (val != null) {
|
|
87 return val;
|
|
88 } else {
|
|
89 return nullAddressString;
|
|
90 }
|
|
91 } else {
|
|
92 return "-";
|
|
93 }
|
|
94 default:
|
|
95 throw new RuntimeException("Index (" + col + ", " + row + ") out of bounds");
|
|
96 }
|
|
97 }
|
|
98 public boolean isCellEditable(int row, int col) {
|
|
99 if (col == 0) return false;
|
|
100 if (!valid) return false;
|
|
101 if (curThread == null) return false;
|
|
102 if (!curThread.canSetContext()) return false;
|
|
103
|
|
104 // FIXME: add listener to watch for register changes
|
|
105 // return true;
|
|
106 return false;
|
|
107 }
|
|
108 };
|
|
109
|
|
110 // Build user interface
|
|
111 setLayout(new BorderLayout());
|
|
112 table = new JTable(dataModel);
|
|
113 table.setCellSelectionEnabled(true);
|
|
114 table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
|
115 table.setDragEnabled(true);
|
|
116 JTableHeader header = table.getTableHeader();
|
|
117 header.setReorderingAllowed(false);
|
|
118 JScrollPane scrollPane = new JScrollPane(table);
|
|
119 add(scrollPane, BorderLayout.CENTER);
|
|
120 }
|
|
121
|
|
122
|
|
123 /** Updates the register panel with the register set from the
|
|
124 specified thread. Call this when the process has been suspended
|
|
125 and the current thread has been set. FIXME: this interface will
|
|
126 need to change to support register windows. */
|
|
127 public void update(ThreadProxy curThread) {
|
|
128 this.curThread = curThread;
|
|
129 ThreadContext context = curThread.getContext();
|
|
130 editable = curThread.canSetContext();
|
|
131 registers.clear();
|
|
132 for (int i = 0; i < context.getNumRegisters(); i++) {
|
|
133 String name = context.getRegisterName(i);
|
|
134 Address addr = context.getRegisterAsAddress(i);
|
|
135 if ((nullAddressString == null) && (addr != null)) {
|
|
136 String addrStr = addr.toString();
|
|
137 StringBuffer buf = new StringBuffer();
|
|
138 buf.append("0x");
|
|
139 int len = addrStr.length() - 2;
|
|
140 for (int j = 0; j < len; j++) {
|
|
141 buf.append("0");
|
|
142 }
|
|
143 nullAddressString = buf.toString();
|
|
144 }
|
|
145 registers.add(new RegisterInfo(name, addr));
|
|
146 }
|
|
147 valid = true;
|
|
148 SwingUtilities.invokeLater(new Runnable() {
|
|
149 public void run() {
|
|
150 dataModel.fireTableDataChanged();
|
|
151 }
|
|
152 });
|
|
153 }
|
|
154
|
|
155 /** Clears the registers' values. Call this when the processs has
|
|
156 been resumed. */
|
|
157 public void clear() {
|
|
158 valid = false;
|
|
159 nullAddressString = null;
|
|
160 SwingUtilities.invokeLater(new Runnable() {
|
|
161 public void run() {
|
|
162 dataModel.fireTableDataChanged();
|
|
163 }
|
|
164 });
|
|
165 }
|
|
166
|
|
167 public void setFont(Font font) {
|
|
168 super.setFont(font);
|
|
169 if (table != null) {
|
|
170 table.setFont(font);
|
|
171 }
|
|
172 }
|
|
173 }
|