annotate agent/src/share/classes/sun/jvm/hotspot/ui/MemoryPanel.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.datatransfer.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.io.IOException;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.math.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import javax.swing.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.ui.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public class MemoryPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private boolean is64Bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private Debugger debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private int addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private String unmappedAddrString;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private HighPrecisionJScrollBar scrollBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private AbstractTableModel model;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private JTable table;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private BigInteger startVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Includes any partially-visible row at the bottom
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private int numVisibleRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Frequently-used subexpression
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private int numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Multi-row (and multi-column) selection. Have to duplicate state
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // from UI so this can work as we scroll off the screen.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private boolean haveAnchor;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private int rowAnchorIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private int colAnchorIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private boolean haveLead;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private int rowLeadIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private int colLeadIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 abstract class ActionWrapper extends AbstractAction {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private Action parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void setParent(Action parent) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 this.parent = parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Action getParent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (getParent() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 getParent().actionPerformed(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public MemoryPanel(final Debugger debugger, boolean is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 this.debugger = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 this.is64Bit = is64Bit;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 addressSize = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 unmappedAddrString = "??????????????????";
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 addressSize = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 unmappedAddrString = "??????????";
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
93 setupScrollBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 add(scrollBar, BorderLayout.EAST);
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 model = new AbstractTableModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public int getRowCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return numVisibleRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public int getColumnCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public Object getValueAt(int row, int column) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 switch (column) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 case 0: return bigIntToHexString(startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
a61af66fc99e Initial load
duke
parents:
diff changeset
106 case 1: {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 Address addr = bigIntToAddress(startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (addr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return addressToString(addr.getAddressAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return unmappedAddrString;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } catch (UnmappedAddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return unmappedAddrString;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 default: throw new RuntimeException("Column " + column + " out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public boolean isCellEditable(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 };
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // View with JTable with no header
a61af66fc99e Initial load
duke
parents:
diff changeset
126 table = new JTable(model);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 table.setTableHeader(null);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 table.setShowGrid(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 table.setIntercellSpacing(new Dimension(0, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
130 table.setCellSelectionEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 table.setDragEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 Font font = GraphicsUtilities.lookupFont("Courier");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (font == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 throw new RuntimeException("Error looking up monospace font Courier");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 table.setFont(font);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Export proper data.
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // We need to keep our own notion of the selection in order to
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // properly export data, since the selection can go beyond the
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // visible area on the screen (and since the table's model doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // back all of those slots).
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Code thanks to Shannon.Hickey@sfbay
a61af66fc99e Initial load
duke
parents:
diff changeset
145 table.setTransferHandler(new TransferHandler() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 protected Transferable createTransferable(JComponent c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 JTable table = (JTable)c;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (haveSelection()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int iDir = (getRowAnchor() < getRowLead() ? 1 : -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 int jDir = (getColAnchor() < getColLead() ? 1 : -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 for (int i = getRowAnchor(); i != getRowLead() + iDir; i += iDir) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (int j = getColAnchor(); j != getColLead() + jDir; j += jDir) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 Object val = model.getValueAt(i, j);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 buf.append(val == null ? "" : val.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (j != getColLead()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 buf.append("\t");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (i != getRowLead()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 buf.append("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return new StringTransferable(buf.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 public int getSourceActions(JComponent c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return COPY;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean importData(JComponent c, Transferable t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (canImport(c, t.getTransferDataFlavors())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 String str = (String)t.getTransferData(DataFlavor.stringFlavor);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 handleImport(c, str);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } catch (UnsupportedFlavorException ufe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } catch (IOException ioe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public boolean canImport(JComponent c, DataFlavor[] flavors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 for (int i = 0; i < flavors.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (DataFlavor.stringFlavor.equals(flavors[i])) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 private void handleImport(JComponent c, String str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // do whatever you want with the string here
a61af66fc99e Initial load
duke
parents:
diff changeset
200 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 makeVisible(debugger.parseAddress(str));
a61af66fc99e Initial load
duke
parents:
diff changeset
202 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 table.clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 System.err.println("Unable to parse address \"" + str + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 });
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Supporting keyboard scrolling
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // See src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java,
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // search for Table.AncestorInputMap
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Actions to override:
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // selectPreviousRow, selectNextRow,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // scrollUpChangeSelection, scrollDownChangeSelection,
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // selectPreviousRowExtendSelection, selectNextRowExtendSelection,
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // scrollDownExtendSelection, scrollUpExtendSelection (Shift-PgDn/PgUp)
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 ActionMap map = table.getActionMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Up arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
223 installActionWrapper(map, "selectPreviousRow", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (table.getSelectedRow() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 scrollBar.scrollUpOrLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 table.setRowSelectionInterval(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 super.actionPerformed(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 });
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Down arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
238 installActionWrapper(map, "selectNextRow", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int row = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (row >= numUsableRows) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 scrollBar.scrollDownOrRight();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 table.setRowSelectionInterval(row, row);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 super.actionPerformed(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 });
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Page up
a61af66fc99e Initial load
duke
parents:
diff changeset
254 installActionWrapper(map, "scrollUpChangeSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int row = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
259 scrollBar.pageUpOrLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (row >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 table.setRowSelectionInterval(row, row);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 });
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Page down
a61af66fc99e Initial load
duke
parents:
diff changeset
268 installActionWrapper(map, "scrollDownChangeSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 int row = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
273 scrollBar.pageDownOrRight();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (row >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 table.setRowSelectionInterval(row, row);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
278 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 });
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // Shift + Up arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
282 installActionWrapper(map, "selectPreviousRowExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // setAnchor(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // setLead(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 int newLead = getRowLead() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 int newAnchor = getRowAnchor();
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (newLead < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 scrollBar.scrollUpOrLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 ++newLead;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 ++newAnchor;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 setSelection(newAnchor, newLead, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 });
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // Shift + Left arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
304 installActionWrapper(map, "selectPreviousColumnExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 int newLead = Math.max(0, getColLead() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
314 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 });
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // Shift + Down arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
318 installActionWrapper(map, "selectNextRowExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
323 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // setAnchor(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // setLead(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 int newLead = getRowLead() + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 int newAnchor = getRowAnchor();
a61af66fc99e Initial load
duke
parents:
diff changeset
329 if (newLead > numUsableRows) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 scrollBar.scrollDownOrRight();
a61af66fc99e Initial load
duke
parents:
diff changeset
331 --newLead;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 --newAnchor;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 setSelection(newAnchor, newLead, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
336 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338 });
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // Shift + Right arrow
a61af66fc99e Initial load
duke
parents:
diff changeset
340 installActionWrapper(map, "selectNextColumnExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 int newLead = Math.min(model.getColumnCount() - 1, getColLead() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 });
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // Shift + Page up
a61af66fc99e Initial load
duke
parents:
diff changeset
354 installActionWrapper(map, "scrollUpExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // setAnchor(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // setLead(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 int newLead = getRowLead() - numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 int newAnchor = getRowAnchor();
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (newLead < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 scrollBar.pageUpOrLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 newLead += numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 newAnchor += numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 setSelection(newAnchor, newLead, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
372 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374 });
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // Shift + Page down
a61af66fc99e Initial load
duke
parents:
diff changeset
376 installActionWrapper(map, "scrollDownExtendSelection", new ActionWrapper() {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 setAnchorFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 setLeadFromTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // setAnchor(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // setLead(table.getSelectedRow());
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 int newLead = getRowLead() + numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 int newAnchor = getRowAnchor();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 if (newLead > numUsableRows) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 scrollBar.pageDownOrRight();
a61af66fc99e Initial load
duke
parents:
diff changeset
389 newLead -= numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 newAnchor -= numUsableRows;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 setSelection(newAnchor, newLead, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
394 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 });
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Clear our notion of selection upon mouse press
a61af66fc99e Initial load
duke
parents:
diff changeset
399 table.addMouseListener(new MouseAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 public void mousePressed(MouseEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (shouldIgnore(e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // Make shift-clicking work properly
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (e.isShiftDown()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // System.err.println(" Clearing selection on mouse press");
a61af66fc99e Initial load
duke
parents:
diff changeset
410 clearSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 });
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // Watch for mouse going out of bounds
a61af66fc99e Initial load
duke
parents:
diff changeset
415 table.addMouseMotionListener(new MouseMotionAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 public void mouseDragged(MouseEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 if (shouldIgnore(e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // System.err.println(" (Ignoring consumed mouse event)");
a61af66fc99e Initial load
duke
parents:
diff changeset
419 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // Look for drag events outside table and scroll if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
423 Point p = e.getPoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (table.rowAtPoint(p) == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // See whether we are above or below the table
a61af66fc99e Initial load
duke
parents:
diff changeset
426 Rectangle rect = new Rectangle();
a61af66fc99e Initial load
duke
parents:
diff changeset
427 getBounds(rect);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (p.y < rect.y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 // System.err.println(" Scrolling up due to mouse event");
a61af66fc99e Initial load
duke
parents:
diff changeset
431 // Scroll up
a61af66fc99e Initial load
duke
parents:
diff changeset
432 scrollBar.scrollUpOrLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
433 setSelection(getRowAnchor(), 0, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
434 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // System.err.println(" Scrolling down due to mouse event");
a61af66fc99e Initial load
duke
parents:
diff changeset
436 // Scroll down
a61af66fc99e Initial load
duke
parents:
diff changeset
437 scrollBar.scrollDownOrRight();
a61af66fc99e Initial load
duke
parents:
diff changeset
438 setSelection(getRowAnchor(), numUsableRows, getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
441 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
442 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 maybeGrabSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 });
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 add(table, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Make sure we recompute number of visible rows
a61af66fc99e Initial load
duke
parents:
diff changeset
452 addComponentListener(new ComponentAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 public void componentResized(ComponentEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 recomputeNumVisibleRows();
a61af66fc99e Initial load
duke
parents:
diff changeset
455 constrain();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 });
a61af66fc99e Initial load
duke
parents:
diff changeset
458 addHierarchyListener(new HierarchyListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 public void hierarchyChanged(HierarchyEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 recomputeNumVisibleRows();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 constrain();
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463 });
a61af66fc99e Initial load
duke
parents:
diff changeset
464 updateFromScrollBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 /** Makes the given address visible somewhere in the window */
a61af66fc99e Initial load
duke
parents:
diff changeset
468 public void makeVisible(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 BigInteger bi = addressToBigInt(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 scrollBar.setValueHP(bi);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
475 //
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 private void setupScrollBar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // 64-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
480 scrollBar =
a61af66fc99e Initial load
duke
parents:
diff changeset
481 new HighPrecisionJScrollBar(
a61af66fc99e Initial load
duke
parents:
diff changeset
482 Scrollbar.VERTICAL,
a61af66fc99e Initial load
duke
parents:
diff changeset
483 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
485 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}),
a61af66fc99e Initial load
duke
parents:
diff changeset
486 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
488 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}),
a61af66fc99e Initial load
duke
parents:
diff changeset
489 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
a61af66fc99e Initial load
duke
parents:
diff changeset
491 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFC}));
a61af66fc99e Initial load
duke
parents:
diff changeset
492 scrollBar.setUnitIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
494 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x08}));
a61af66fc99e Initial load
duke
parents:
diff changeset
495 scrollBar.setBlockIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
a61af66fc99e Initial load
duke
parents:
diff changeset
497 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40}));
a61af66fc99e Initial load
duke
parents:
diff changeset
498 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // 32-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
500 scrollBar=
a61af66fc99e Initial load
duke
parents:
diff changeset
501 new HighPrecisionJScrollBar(
a61af66fc99e Initial load
duke
parents:
diff changeset
502 Scrollbar.VERTICAL,
a61af66fc99e Initial load
duke
parents:
diff changeset
503 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
504 (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00}),
a61af66fc99e Initial load
duke
parents:
diff changeset
505 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
506 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}),
a61af66fc99e Initial load
duke
parents:
diff changeset
507 new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFC}));
a61af66fc99e Initial load
duke
parents:
diff changeset
509 scrollBar.setUnitIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04}));
a61af66fc99e Initial load
duke
parents:
diff changeset
511 scrollBar.setBlockIncrementHP(new BigInteger(1, new byte[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20}));
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 scrollBar.addChangeListener(new ChangeListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 public void stateChanged(ChangeEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 updateFromScrollBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518 });
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 private void updateFromScrollBar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 beginUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
523 BigInteger oldStartVal = startVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 startVal = scrollBar.getValueHP();
a61af66fc99e Initial load
duke
parents:
diff changeset
525 constrain();
a61af66fc99e Initial load
duke
parents:
diff changeset
526 model.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (oldStartVal != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 modifySelection(oldStartVal.subtract(startVal).intValue() / addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530 endUpdate();
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 private void constrain() {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 BigInteger offset = new BigInteger(Integer.toString(addressSize * (numUsableRows)));
a61af66fc99e Initial load
duke
parents:
diff changeset
535 BigInteger endVal = startVal.add(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (endVal.compareTo(scrollBar.getMaximumHP()) > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 startVal = scrollBar.getMaximumHP().subtract(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 endVal = scrollBar.getMaximumHP();
a61af66fc99e Initial load
duke
parents:
diff changeset
539 scrollBar.setValueHP(startVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
540 model.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 private void recomputeNumVisibleRows() {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 Rectangle rect = new Rectangle();
a61af66fc99e Initial load
duke
parents:
diff changeset
546 getBounds(rect);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 int h = table.getRowHeight();
a61af66fc99e Initial load
duke
parents:
diff changeset
548 numVisibleRows = (rect.height + (h - 1)) / h;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 numUsableRows = numVisibleRows - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 scrollBar.setBlockIncrementHP(new BigInteger(Integer.toString(addressSize * (numUsableRows))));
a61af66fc99e Initial load
duke
parents:
diff changeset
551 model.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // FIXME: refresh selection
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 private String bigIntToHexString(BigInteger bi) {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
557 buf.append("0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
558 String val = bi.toString(16);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 for (int i = 0; i < ((2 * addressSize) - val.length()); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 buf.append('0');
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 buf.append(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 private Address bigIntToAddress(BigInteger i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 String s = bigIntToHexString(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 return debugger.parseAddress(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 }
a61af66fc99e Initial load
duke
parents:
diff changeset
570
a61af66fc99e Initial load
duke
parents:
diff changeset
571 private BigInteger addressToBigInt(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 String s = addressToString(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
573 if (!s.startsWith("0x")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 throw new NumberFormatException(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
576 return new BigInteger(s.substring(2), 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 private String addressToString(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 if (a == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 if (is64Bit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 return "0x0000000000000000";
a61af66fc99e Initial load
duke
parents:
diff changeset
583 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
584 return "0x00000000";
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 return a.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 private static void installActionWrapper(ActionMap map,
a61af66fc99e Initial load
duke
parents:
diff changeset
591 String actionName,
a61af66fc99e Initial load
duke
parents:
diff changeset
592 ActionWrapper wrapper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 wrapper.setParent(map.get(actionName));
a61af66fc99e Initial load
duke
parents:
diff changeset
594 map.put(actionName, wrapper);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 private boolean shouldIgnore(MouseEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 return e.isConsumed() || (!(SwingUtilities.isLeftMouseButton(e) && table.isEnabled()));
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601 private void clearSelection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 haveAnchor = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
603 haveLead = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 private int updateLevel;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 private boolean updating() { return updateLevel > 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
608 private void beginUpdate() { ++updateLevel; }
a61af66fc99e Initial load
duke
parents:
diff changeset
609 private void endUpdate() { --updateLevel; }
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 private boolean haveAnchor() { return haveAnchor; }
a61af66fc99e Initial load
duke
parents:
diff changeset
612 private boolean haveLead() { return haveLead; }
a61af66fc99e Initial load
duke
parents:
diff changeset
613 private boolean haveSelection() { return haveAnchor() && haveLead(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
614 private int getRowAnchor() { return rowAnchorIndex; }
a61af66fc99e Initial load
duke
parents:
diff changeset
615 private int getColAnchor() { return colAnchorIndex; }
a61af66fc99e Initial load
duke
parents:
diff changeset
616 private int getRowLead() { return rowLeadIndex; }
a61af66fc99e Initial load
duke
parents:
diff changeset
617 private int getColLead() { return colLeadIndex; }
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 private void setAnchorFromTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
620 setAnchor(table.getSelectionModel().getAnchorSelectionIndex(),
a61af66fc99e Initial load
duke
parents:
diff changeset
621 table.getColumnModel().getSelectionModel().getAnchorSelectionIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623 private void setLeadFromTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 setLead(table.getSelectionModel().getAnchorSelectionIndex(),
a61af66fc99e Initial load
duke
parents:
diff changeset
625 table.getColumnModel().getSelectionModel().getAnchorSelectionIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 private void setAnchor(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
628 rowAnchorIndex = row;
a61af66fc99e Initial load
duke
parents:
diff changeset
629 colAnchorIndex = col;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 haveAnchor = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632 private void setLead(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 rowLeadIndex = row;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 colLeadIndex = col;
a61af66fc99e Initial load
duke
parents:
diff changeset
635 haveLead = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637 private int clamp(int val, int min, int max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 return Math.max(Math.min(val, max), min);
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640 private void maybeGrabSelection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (table.getSelectedRow() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // Grab selection
a61af66fc99e Initial load
duke
parents:
diff changeset
643 ListSelectionModel rowSel = table.getSelectionModel();
a61af66fc99e Initial load
duke
parents:
diff changeset
644 ListSelectionModel colSel = table.getColumnModel().getSelectionModel();
a61af66fc99e Initial load
duke
parents:
diff changeset
645 if (!haveAnchor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // System.err.println("Updating from table's selection");
a61af66fc99e Initial load
duke
parents:
diff changeset
647 setSelection(rowSel.getAnchorSelectionIndex(), rowSel.getLeadSelectionIndex(),
a61af66fc99e Initial load
duke
parents:
diff changeset
648 colSel.getAnchorSelectionIndex(), colSel.getLeadSelectionIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
649 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // System.err.println("Updating lead from table's selection");
a61af66fc99e Initial load
duke
parents:
diff changeset
651 setSelection(getRowAnchor(), rowSel.getLeadSelectionIndex(),
a61af66fc99e Initial load
duke
parents:
diff changeset
652 getColAnchor(), colSel.getLeadSelectionIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // printSelection();
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657 private void setSelection(int rowAnchor, int rowLead, int colAnchor, int colLead) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 setAnchor(rowAnchor, colAnchor);
a61af66fc99e Initial load
duke
parents:
diff changeset
659 setLead(rowLead, colLead);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 table.setRowSelectionInterval(clamp(rowAnchor, 0, numUsableRows),
a61af66fc99e Initial load
duke
parents:
diff changeset
661 clamp(rowLead, 0, numUsableRows));
a61af66fc99e Initial load
duke
parents:
diff changeset
662 table.setColumnSelectionInterval(colAnchor, colLead);
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664 private void modifySelection(int amount) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 if (haveSelection()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 setSelection(getRowAnchor() + amount, getRowLead() + amount,
a61af66fc99e Initial load
duke
parents:
diff changeset
667 getColAnchor(), getColLead());
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 private void printSelection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 System.err.println("Selection updated to (" +
a61af66fc99e Initial load
duke
parents:
diff changeset
672 model.getValueAt(getRowAnchor(), getColAnchor()) +
a61af66fc99e Initial load
duke
parents:
diff changeset
673 ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
674 model.getValueAt(getRowLead(), getColLead()) + ") [(" +
a61af66fc99e Initial load
duke
parents:
diff changeset
675 getRowAnchor() + ", " + getColAnchor() + "), (" +
a61af66fc99e Initial load
duke
parents:
diff changeset
676 getRowLead() + ", " + getColLead() + ")]");
a61af66fc99e Initial load
duke
parents:
diff changeset
677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }