annotate agent/src/share/classes/sun/jvm/hotspot/ui/treetable/AbstractTreeTableModel.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.treetable;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import javax.swing.tree.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import javax.swing.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
31 * An abstract implementation of the TreeTableModel interface, handling the list
a61af66fc99e Initial load
duke
parents:
diff changeset
32 * of listeners.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 * @author Philip Milne
a61af66fc99e Initial load
duke
parents:
diff changeset
34 */
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public abstract class AbstractTreeTableModel implements TreeTableModel {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 protected Object root;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 protected EventListenerList listenerList = new EventListenerList();
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public AbstractTreeTableModel(Object root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 this.root = root;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 //
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Default implmentations for methods in the TreeModel interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public Object getRoot() {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return root;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public boolean isLeaf(Object node) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return getChildCount(node) == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public void valueForPathChanged(TreePath path, Object newValue) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // This is not called in the JTree's default mode: use a naive implementation.
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public int getIndexOfChild(Object parent, Object child) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 for (int i = 0; i < getChildCount(parent); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (getChild(parent, i).equals(child)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public void addTreeModelListener(TreeModelListener l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 listenerList.add(TreeModelListener.class, l);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public void removeTreeModelListener(TreeModelListener l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 listenerList.remove(TreeModelListener.class, l);
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 * Notify all listeners that have registered interest for
a61af66fc99e Initial load
duke
parents:
diff changeset
78 * notification on this event type. The event instance
a61af66fc99e Initial load
duke
parents:
diff changeset
79 * is lazily created using the parameters passed into
a61af66fc99e Initial load
duke
parents:
diff changeset
80 * the fire method.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 * @see EventListenerList
a61af66fc99e Initial load
duke
parents:
diff changeset
82 */
a61af66fc99e Initial load
duke
parents:
diff changeset
83 protected void fireTreeNodesChanged(Object source, Object[] path,
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int[] childIndices,
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Object[] children) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Guaranteed to return a non-null array
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Object[] listeners = listenerList.getListenerList();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 TreeModelEvent e = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Process the listeners last to first, notifying
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // those that are interested in this event
a61af66fc99e Initial load
duke
parents:
diff changeset
91 for (int i = listeners.length-2; i>=0; i-=2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (listeners[i]==TreeModelListener.class) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Lazily create the event:
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (e == null)
a61af66fc99e Initial load
duke
parents:
diff changeset
95 e = new TreeModelEvent(source, path,
a61af66fc99e Initial load
duke
parents:
diff changeset
96 childIndices, children);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
103 * Notify all listeners that have registered interest for
a61af66fc99e Initial load
duke
parents:
diff changeset
104 * notification on this event type. The event instance
a61af66fc99e Initial load
duke
parents:
diff changeset
105 * is lazily created using the parameters passed into
a61af66fc99e Initial load
duke
parents:
diff changeset
106 * the fire method.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 * @see EventListenerList
a61af66fc99e Initial load
duke
parents:
diff changeset
108 */
a61af66fc99e Initial load
duke
parents:
diff changeset
109 protected void fireTreeNodesInserted(Object source, Object[] path,
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int[] childIndices,
a61af66fc99e Initial load
duke
parents:
diff changeset
111 Object[] children) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Guaranteed to return a non-null array
a61af66fc99e Initial load
duke
parents:
diff changeset
113 Object[] listeners = listenerList.getListenerList();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 TreeModelEvent e = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Process the listeners last to first, notifying
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // those that are interested in this event
a61af66fc99e Initial load
duke
parents:
diff changeset
117 for (int i = listeners.length-2; i>=0; i-=2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (listeners[i]==TreeModelListener.class) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Lazily create the event:
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (e == null)
a61af66fc99e Initial load
duke
parents:
diff changeset
121 e = new TreeModelEvent(source, path,
a61af66fc99e Initial load
duke
parents:
diff changeset
122 childIndices, children);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 ((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
129 * Notify all listeners that have registered interest for
a61af66fc99e Initial load
duke
parents:
diff changeset
130 * notification on this event type. The event instance
a61af66fc99e Initial load
duke
parents:
diff changeset
131 * is lazily created using the parameters passed into
a61af66fc99e Initial load
duke
parents:
diff changeset
132 * the fire method.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 * @see EventListenerList
a61af66fc99e Initial load
duke
parents:
diff changeset
134 */
a61af66fc99e Initial load
duke
parents:
diff changeset
135 protected void fireTreeNodesRemoved(Object source, Object[] path,
a61af66fc99e Initial load
duke
parents:
diff changeset
136 int[] childIndices,
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Object[] children) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Guaranteed to return a non-null array
a61af66fc99e Initial load
duke
parents:
diff changeset
139 Object[] listeners = listenerList.getListenerList();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 TreeModelEvent e = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Process the listeners last to first, notifying
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // those that are interested in this event
a61af66fc99e Initial load
duke
parents:
diff changeset
143 for (int i = listeners.length-2; i>=0; i-=2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (listeners[i]==TreeModelListener.class) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Lazily create the event:
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (e == null)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 e = new TreeModelEvent(source, path,
a61af66fc99e Initial load
duke
parents:
diff changeset
148 childIndices, children);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
155 * Notify all listeners that have registered interest for
a61af66fc99e Initial load
duke
parents:
diff changeset
156 * notification on this event type. The event instance
a61af66fc99e Initial load
duke
parents:
diff changeset
157 * is lazily created using the parameters passed into
a61af66fc99e Initial load
duke
parents:
diff changeset
158 * the fire method.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 * @see EventListenerList
a61af66fc99e Initial load
duke
parents:
diff changeset
160 */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 protected void fireTreeStructureChanged(Object source, Object[] path,
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int[] childIndices,
a61af66fc99e Initial load
duke
parents:
diff changeset
163 Object[] children) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // Guaranteed to return a non-null array
a61af66fc99e Initial load
duke
parents:
diff changeset
165 Object[] listeners = listenerList.getListenerList();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 TreeModelEvent e = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Process the listeners last to first, notifying
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // those that are interested in this event
a61af66fc99e Initial load
duke
parents:
diff changeset
169 for (int i = listeners.length-2; i>=0; i-=2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (listeners[i]==TreeModelListener.class) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // Lazily create the event:
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (e == null)
a61af66fc99e Initial load
duke
parents:
diff changeset
173 e = new TreeModelEvent(source, path,
a61af66fc99e Initial load
duke
parents:
diff changeset
174 childIndices, children);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 ((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 //
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Default impelmentations for methods in the TreeTableModel interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 //
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 public Class getColumnClass(int column) { return Object.class; }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 /** By default, make the column with the Tree in it the only editable one.
a61af66fc99e Initial load
duke
parents:
diff changeset
187 * Making this column editable causes the JTable to forward mouse
a61af66fc99e Initial load
duke
parents:
diff changeset
188 * and keyboard events in the Tree column to the underlying JTree.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 */
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public boolean isCellEditable(Object node, int column) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return getColumnClass(column) == TreeTableModel.class;
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 void setValueAt(Object aValue, Object node, int column) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Left to be implemented in the subclass:
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
200 * public Object getChild(Object parent, int index)
a61af66fc99e Initial load
duke
parents:
diff changeset
201 * public int getChildCount(Object parent)
a61af66fc99e Initial load
duke
parents:
diff changeset
202 * public int getColumnCount()
a61af66fc99e Initial load
duke
parents:
diff changeset
203 * public String getColumnName(Object node, int column)
a61af66fc99e Initial load
duke
parents:
diff changeset
204 * public Object getValueAt(Object node, int column)
a61af66fc99e Initial load
duke
parents:
diff changeset
205 */
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }