annotate agent/src/share/classes/sun/jvm/hotspot/ui/ProcessListPanel.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
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.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public class ProcessListPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private Debugger dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private AbstractTableModel dataModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private java.util.List els;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private boolean sortByName = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private boolean sortReversed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private javax.swing.Timer timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private JTable table;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 /** Takes a Debugger in constructor. Updates the list once during
a61af66fc99e Initial load
duke
parents:
diff changeset
46 construction; list can be updated automatically by "starting"
a61af66fc99e Initial load
duke
parents:
diff changeset
47 the panel. */
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public ProcessListPanel(Debugger dbg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 this.dbg = dbg;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 update();
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 dataModel = new AbstractTableModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public int getColumnCount() { return 2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public int getRowCount() { return els.size(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public String getColumnName(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return "Process Name";
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return "Process ID";
a61af66fc99e Initial load
duke
parents:
diff changeset
64 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
65 throw new RuntimeException("Index " + col + " out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public Object getValueAt(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ProcessInfo info = (ProcessInfo) els.get(row);
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return info.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return new Integer(info.getPid());
a61af66fc99e Initial load
duke
parents:
diff changeset
77 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 throw new RuntimeException("Index (" + col + ", " + row + ") out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 };
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Create user interface
a61af66fc99e Initial load
duke
parents:
diff changeset
84 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
85 table = new JTable(dataModel);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 JTableHeader header = table.getTableHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 header.setReorderingAllowed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 table.setRowSelectionAllowed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 table.setColumnSelectionAllowed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Provide sorting in similar fashion to Task Manager
a61af66fc99e Initial load
duke
parents:
diff changeset
92 header.addMouseListener(new MouseAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public void mousePressed(MouseEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int viewColumn = table.getColumnModel().getColumnIndexAtX(e.getX());
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int column = table.convertColumnIndexToModel(viewColumn);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (column != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 boolean newSortByName = (column == 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (newSortByName == sortByName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Switch sense of "reversed" instead
a61af66fc99e Initial load
duke
parents:
diff changeset
100 sortReversed = !sortReversed;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 sortByName = newSortByName;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 sortReversed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Keep the current selection if possible
a61af66fc99e Initial load
duke
parents:
diff changeset
107 int i = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int pid = getPid(els, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 sort(els);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 i = findPid(els, pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 dataModel.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if ((i >= 0) || (els.size() > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (i >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 table.setRowSelectionInterval(i, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 table.setRowSelectionInterval(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 });
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 JScrollPane scrollPane = new JScrollPane(table);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 add(scrollPane, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (els.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 table.setRowSelectionInterval(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 /** Set update interval for automatic updating of the process list */
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public void setAutoUpdateInterval(int millis) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 getTimer().setDelay(millis);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 /** Start auto updating of the panel */
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public void start() {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 getTimer().start();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 /** Stop auto updating of the panel */
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public void stop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 getTimer().stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 /** Call this to update the panel's notion of the process list */
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public synchronized void update() {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (!dbg.hasProcessList()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 throw new RuntimeException("ProcessListPanel requires that debugger supports getProcessList()");
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 java.util.List newEls = dbg.getProcessList();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 sort(newEls);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (table != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Keep the current selection if possible
a61af66fc99e Initial load
duke
parents:
diff changeset
156 int i = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 int pid = getPid(els, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 i = findPid(newEls, pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 els = newEls;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 dataModel.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if ((i >= 0) || (els.size() > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (i >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 table.setRowSelectionInterval(i, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 table.setRowSelectionInterval(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 els = newEls;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 /** Call this to get the selected ProcessInfo, or null if none selected */
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public synchronized ProcessInfo getSelectedProcess() {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 int i = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return (ProcessInfo) els.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 private synchronized void sort(java.util.List els) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 Comparator c;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (sortByName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 c = new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 int scale = (sortReversed ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return scale * ((ProcessInfo) o1).getName().compareToIgnoreCase(((ProcessInfo) o2).getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 };
a61af66fc99e Initial load
duke
parents:
diff changeset
191 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 c = new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 int scale = (sortReversed ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int pid1 = ((ProcessInfo) o1).getPid();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int pid2 = ((ProcessInfo) o2).getPid();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 int ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (pid1 < pid2) ret = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 else if (pid1 == pid2) ret = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 else ret = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return ret * scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 };
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 Collections.sort(els, c);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 private javax.swing.Timer getTimer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (timer == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 timer = new javax.swing.Timer(1000, new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 update();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 });
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 return timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 private synchronized int getPid(java.util.List els, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return ((ProcessInfo) els.get(index)).getPid();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 private synchronized int findPid(java.util.List els, int pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 for (int i = 0; i < els.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 ProcessInfo info = (ProcessInfo) els.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (info.getPid() == pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }