annotate agent/src/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.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) 2000, 2002, 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.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.ObjectHistogram;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.oops.ObjectHistogramElement;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.ui.table.LongCellRenderer;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.ui.table.SortableTableModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.ui.table.SortHeaderCellRenderer;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.ui.table.SortHeaderMouseAdapter;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.ui.table.TableModelComparator;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import sun.jvm.hotspot.ui.action.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 import com.sun.java.swing.ui.StatusBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 import com.sun.java.swing.ui.CommonToolBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 import com.sun.java.swing.action.ActionManager;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 import com.sun.java.swing.action.DelegateAction;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
54 * Displays the results of an ObjectHistogram run in a JTable, with a
a61af66fc99e Initial load
duke
parents:
diff changeset
55 * button to display all objects of that type
a61af66fc99e Initial load
duke
parents:
diff changeset
56 */
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public class ObjectHistogramPanel extends JPanel implements ActionListener {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private ObjectHistogramTableModel dataModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private ObjectHistogramToolBar toolbar;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private StatusBar statusBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private JTable table;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private java.util.List listeners;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public ObjectHistogramPanel(ObjectHistogram histo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 dataModel = new ObjectHistogramTableModel(histo);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 statusBar = new StatusBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 table = new JTable(dataModel, new ObjectHistogramColummModel());
a61af66fc99e Initial load
duke
parents:
diff changeset
69 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 table.addMouseListener(new MouseAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public void mouseClicked(MouseEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (evt.getClickCount() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 fireShowObjectsOfType();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 });
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 JTableHeader header = table.getTableHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 header.setDefaultRenderer(new SortHeaderCellRenderer(header, dataModel));
a61af66fc99e Initial load
duke
parents:
diff changeset
80 header.addMouseListener(new SortHeaderMouseAdapter(table, dataModel));
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 toolbar = new ObjectHistogramToolBar(statusBar);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 add(toolbar, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 add(new JScrollPane(table), BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 add(statusBar, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 registerActions();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 private class ObjectHistogramToolBar extends CommonToolBar {
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private JTextField searchTF;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public ObjectHistogramToolBar(StatusBar status) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 super(HSDBActionManager.getInstance(), status);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 protected void addComponents() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 searchTF = new JTextField();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 searchTF.setToolTipText("Find in Class Description");
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Pressing Enter on the text field will search
a61af66fc99e Initial load
duke
parents:
diff changeset
105 InputMap im = searchTF.getInputMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 im.put(KeyStroke.getKeyStroke("ENTER"), "enterPressed");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 ActionMap am = searchTF.getActionMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 am.put("enterPressed", manager.getAction(FindAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 add(searchTF);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 addButton(manager.getAction(FindAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
112 addButton(manager.getAction(ShowAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public String getFindText() {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return searchTF.getText();
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 private class ObjectHistogramColummModel extends DefaultTableColumnModel {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 private final String LABEL_SIZE = "Size";
a61af66fc99e Initial load
duke
parents:
diff changeset
122 private final String LABEL_COUNT = "Count";
a61af66fc99e Initial load
duke
parents:
diff changeset
123 private final String LABEL_DESC = "Class Description";
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public ObjectHistogramColummModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Should actually get the line metrics for
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int PREF_WIDTH = 80;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 int MAX_WIDTH = 100;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 int HUGE_WIDTH = 140;
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 LongCellRenderer lcRender = new LongCellRenderer();
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 TableColumn column;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Size
a61af66fc99e Initial load
duke
parents:
diff changeset
137 column = new TableColumn(0, PREF_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 column.setHeaderValue(LABEL_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 column.setMaxWidth(MAX_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 column.setResizable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 column.setCellRenderer(lcRender);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 addColumn(column);
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Count
a61af66fc99e Initial load
duke
parents:
diff changeset
145 column = new TableColumn(1, PREF_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 column.setHeaderValue(LABEL_COUNT);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 column.setMaxWidth(MAX_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 column.setResizable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 column.setCellRenderer(lcRender);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 addColumn(column);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Description
a61af66fc99e Initial load
duke
parents:
diff changeset
153 column = new TableColumn(2, HUGE_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 column.setHeaderValue(LABEL_DESC);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 addColumn(column);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
161 * A table model which encapsulates the ObjectHistogram
a61af66fc99e Initial load
duke
parents:
diff changeset
162 */
a61af66fc99e Initial load
duke
parents:
diff changeset
163 private class ObjectHistogramTableModel extends SortableTableModel {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 private String[] columnNames = { "Size", "Count", "Class Description" };
a61af66fc99e Initial load
duke
parents:
diff changeset
165 private Class[] columnClasses = { Long.class, Long.class, String.class };
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public ObjectHistogramTableModel(ObjectHistogram histo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Set the rows
a61af66fc99e Initial load
duke
parents:
diff changeset
169 elements = histo.getElements();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 setComparator(new ObjectHistogramComparator(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public int getColumnCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return columnNames.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public int getRowCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return elements.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public String getColumnName(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return columnNames[col];
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public Class getColumnClass(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return columnClasses[col];
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public Object getValueAt(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return getValueForColumn(getElement(row), col);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public Object getValueForColumn(Object obj, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 ObjectHistogramElement el = (ObjectHistogramElement)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return new Long(el.getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
199 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
200 return new Long(el.getCount());
a61af66fc99e Initial load
duke
parents:
diff changeset
201 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return el.getDescription();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
204 throw new RuntimeException("Index (" + col + ") out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 public ObjectHistogramElement getElement(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return (ObjectHistogramElement) elements.get(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 private class ObjectHistogramComparator extends TableModelComparator {
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public ObjectHistogramComparator(ObjectHistogramTableModel model) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 super(model);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
219 * Returns the value for the comparing object for the
a61af66fc99e Initial load
duke
parents:
diff changeset
220 * column.
a61af66fc99e Initial load
duke
parents:
diff changeset
221 *
a61af66fc99e Initial load
duke
parents:
diff changeset
222 * @param obj Object that was passed for Comparator
a61af66fc99e Initial load
duke
parents:
diff changeset
223 * @param column the column to retrieve
a61af66fc99e Initial load
duke
parents:
diff changeset
224 */
a61af66fc99e Initial load
duke
parents:
diff changeset
225 public Object getValueForColumn(Object obj, int column) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 ObjectHistogramTableModel omodel = (ObjectHistogramTableModel)model;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return omodel.getValueForColumn(obj, column);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 //
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // ActionListener implementation and actions support
a61af66fc99e Initial load
duke
parents:
diff changeset
236 //
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public void actionPerformed(ActionEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 String command = evt.getActionCommand();
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (command.equals(ShowAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 fireShowObjectsOfType();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 } else if (command.equals(FindAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 findObject();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 protected void registerActions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 registerAction(FindAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 registerAction(ShowAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 private void registerAction(String actionName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ActionManager manager = ActionManager.getInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
256 DelegateAction action = manager.getDelegateAction(actionName);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 action.addActionListener(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 public interface Listener {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 public void showObjectsOfType(Klass type);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 public void addPanelListener(Listener listener) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (listeners == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 listeners = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 listeners.add(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 public void removePanelListener(Listener listener) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (listeners != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 listeners.remove(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
279 //
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
282 * Find and select the row that contains the text in the find field starting
a61af66fc99e Initial load
duke
parents:
diff changeset
283 * from the current selected row.
a61af66fc99e Initial load
duke
parents:
diff changeset
284 *
a61af66fc99e Initial load
duke
parents:
diff changeset
285 * Uses a linear search from the current row. Could be optimized withing the
a61af66fc99e Initial load
duke
parents:
diff changeset
286 * model and internal representation.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 */
a61af66fc99e Initial load
duke
parents:
diff changeset
288 private void findObject() {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 String findText = toolbar.getFindText();
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (findText == null || findText.equals("")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 TableModel model = table.getModel();
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 int row = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (row == model.getRowCount()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 row = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // Start at the row after the selected row.
a61af66fc99e Initial load
duke
parents:
diff changeset
302 row++;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 String value;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 for (int i = row; i < model.getRowCount(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 value = (String)model.getValueAt(i, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (value != null && value.startsWith(findText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 table.setRowSelectionInterval(i, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 Rectangle cellBounds = table.getCellRect(i, 0, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 table.scrollRectToVisible(cellBounds);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // Wrap the table to search in the top rows.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for (int i = 0; i < row; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 value = (String)model.getValueAt(i, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (value != null && value.startsWith(findText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 table.setRowSelectionInterval(i, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 Rectangle cellBounds = table.getCellRect(i, 0, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 table.scrollRectToVisible(cellBounds);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 private void fireShowObjectsOfType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 int i = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 ObjectHistogramElement el = dataModel.getElement(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 Listener listener = (Listener) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 listener.showObjectsOfType(el.getKlass());
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }