author | darcy |
Fri, 03 Apr 2015 10:41:34 -0700 | |
changeset 29894 | 3e16b51732f5 |
parent 29250 | f9edd0824de6 |
child 31657 | 6b5f36a9a3c0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.beans.*; |
|
31 |
import java.io.*; |
|
32 |
import java.util.*; |
|
33 |
import javax.swing.event.*; |
|
34 |
import javax.swing.plaf.*; |
|
35 |
import javax.swing.tree.*; |
|
36 |
import javax.swing.text.Position; |
|
37 |
import javax.accessibility.*; |
|
38 |
import sun.swing.SwingUtilities2; |
|
39 |
import sun.swing.SwingUtilities2.Section; |
|
40 |
import static sun.swing.SwingUtilities2.Section.*; |
|
41 |
||
42 |
||
43 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
44 |
* <a name="jtree_description"></a> |
2 | 45 |
* A control that displays a set of hierarchical data as an outline. |
46 |
* You can find task-oriented documentation and examples of using trees in |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
20157
diff
changeset
|
47 |
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>, |
2 | 48 |
* a section in <em>The Java Tutorial.</em> |
49 |
* <p> |
|
50 |
* A specific node in a tree can be identified either by a |
|
51 |
* <code>TreePath</code> (an object |
|
52 |
* that encapsulates a node and all of its ancestors), or by its |
|
53 |
* display row, where each row in the display area displays one node. |
|
54 |
* An <i>expanded</i> node is a non-leaf node (as identified by |
|
55 |
* <code>TreeModel.isLeaf(node)</code> returning false) that will displays |
|
56 |
* its children when all its ancestors are <i>expanded</i>. |
|
57 |
* A <i>collapsed</i> |
|
58 |
* node is one which hides them. A <i>hidden</i> node is one which is |
|
59 |
* under a collapsed ancestor. All of a <i>viewable</i> nodes parents |
|
60 |
* are expanded, but may or may not be displayed. A <i>displayed</i> node |
|
61 |
* is both viewable and in the display area, where it can be seen. |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
62 |
* </p> |
2 | 63 |
* The following <code>JTree</code> methods use "visible" to mean "displayed": |
64 |
* <ul> |
|
65 |
* <li><code>isRootVisible()</code> |
|
66 |
* <li><code>setRootVisible()</code> |
|
67 |
* <li><code>scrollPathToVisible()</code> |
|
68 |
* <li><code>scrollRowToVisible()</code> |
|
69 |
* <li><code>getVisibleRowCount()</code> |
|
70 |
* <li><code>setVisibleRowCount()</code> |
|
71 |
* </ul> |
|
72 |
* The next group of <code>JTree</code> methods use "visible" to mean |
|
73 |
* "viewable" (under an expanded parent): |
|
74 |
* <ul> |
|
75 |
* <li><code>isVisible()</code> |
|
76 |
* <li><code>makeVisible()</code> |
|
77 |
* </ul> |
|
78 |
* If you are interested in knowing when the selection changes implement |
|
79 |
* the <code>TreeSelectionListener</code> interface and add the instance |
|
80 |
* using the method <code>addTreeSelectionListener</code>. |
|
81 |
* <code>valueChanged</code> will be invoked when the |
|
82 |
* selection changes, that is if the user clicks twice on the same |
|
83 |
* node <code>valueChanged</code> will only be invoked once. |
|
84 |
* <p> |
|
85 |
* If you are interested in detecting either double-click events or when |
|
86 |
* a user clicks on a node, regardless of whether or not it was selected, |
|
87 |
* we recommend you do the following: |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
88 |
* </p> |
2 | 89 |
* <pre> |
90 |
* final JTree tree = ...; |
|
91 |
* |
|
92 |
* MouseListener ml = new MouseAdapter() { |
|
93 |
* public void <b>mousePressed</b>(MouseEvent e) { |
|
94 |
* int selRow = tree.getRowForLocation(e.getX(), e.getY()); |
|
95 |
* TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); |
|
96 |
* if(selRow != -1) { |
|
97 |
* if(e.getClickCount() == 1) { |
|
98 |
* mySingleClick(selRow, selPath); |
|
99 |
* } |
|
100 |
* else if(e.getClickCount() == 2) { |
|
101 |
* myDoubleClick(selRow, selPath); |
|
102 |
* } |
|
103 |
* } |
|
104 |
* } |
|
105 |
* }; |
|
106 |
* tree.addMouseListener(ml); |
|
107 |
* </pre> |
|
108 |
* NOTE: This example obtains both the path and row, but you only need to |
|
109 |
* get the one you're interested in. |
|
110 |
* <p> |
|
111 |
* To use <code>JTree</code> to display compound nodes |
|
112 |
* (for example, nodes containing both |
|
113 |
* a graphic icon and text), subclass {@link TreeCellRenderer} and use |
|
114 |
* {@link #setCellRenderer} to tell the tree to use it. To edit such nodes, |
|
115 |
* subclass {@link TreeCellEditor} and use {@link #setCellEditor}. |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
116 |
* </p> |
2 | 117 |
* <p> |
118 |
* Like all <code>JComponent</code> classes, you can use {@link InputMap} and |
|
119 |
* {@link ActionMap} |
|
120 |
* to associate an {@link Action} object with a {@link KeyStroke} |
|
121 |
* and execute the action under specified conditions. |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
122 |
* </p> |
2 | 123 |
* <strong>Warning:</strong> Swing is not thread safe. For more |
124 |
* information see <a |
|
125 |
* href="package-summary.html#threading">Swing's Threading |
|
126 |
* Policy</a>. |
|
127 |
* <p> |
|
128 |
* <strong>Warning:</strong> |
|
129 |
* Serialized objects of this class will not be compatible with |
|
130 |
* future Swing releases. The current serialization support is |
|
131 |
* appropriate for short term storage or RMI between applications running |
|
132 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 133 |
* of all JavaBeans™ |
2 | 134 |
* has been added to the <code>java.beans</code> package. |
135 |
* Please see {@link java.beans.XMLEncoder}. |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
136 |
*</p> |
2 | 137 |
* @beaninfo |
138 |
* attribute: isContainer false |
|
139 |
* description: A component that displays a set of hierarchical data as an outline. |
|
140 |
* |
|
141 |
* @author Rob Davis |
|
142 |
* @author Ray Ryan |
|
143 |
* @author Scott Violet |
|
25201
4adc75e0c4e5
8046485: Add missing @since tag under javax.swing.*
henryjen
parents:
24983
diff
changeset
|
144 |
* @since 1.2 |
2 | 145 |
*/ |
11268 | 146 |
@SuppressWarnings("serial") |
2 | 147 |
public class JTree extends JComponent implements Scrollable, Accessible |
148 |
{ |
|
149 |
/** |
|
150 |
* @see #getUIClassID |
|
151 |
* @see #readObject |
|
152 |
*/ |
|
153 |
private static final String uiClassID = "TreeUI"; |
|
154 |
||
155 |
/** |
|
156 |
* The model that defines the tree displayed by this object. |
|
157 |
*/ |
|
158 |
transient protected TreeModel treeModel; |
|
159 |
||
160 |
/** |
|
161 |
* Models the set of selected nodes in this tree. |
|
162 |
*/ |
|
163 |
transient protected TreeSelectionModel selectionModel; |
|
164 |
||
165 |
/** |
|
166 |
* True if the root node is displayed, false if its children are |
|
167 |
* the highest visible nodes. |
|
168 |
*/ |
|
169 |
protected boolean rootVisible; |
|
170 |
||
171 |
/** |
|
172 |
* The cell used to draw nodes. If <code>null</code>, the UI uses a default |
|
173 |
* <code>cellRenderer</code>. |
|
174 |
*/ |
|
175 |
transient protected TreeCellRenderer cellRenderer; |
|
176 |
||
177 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
178 |
* Height to use for each display row. If this is <= 0 the renderer |
2 | 179 |
* determines the height for each row. |
180 |
*/ |
|
181 |
protected int rowHeight; |
|
182 |
private boolean rowHeightSet = false; |
|
183 |
||
184 |
/** |
|
185 |
* Maps from <code>TreePath</code> to <code>Boolean</code> |
|
186 |
* indicating whether or not the |
|
187 |
* particular path is expanded. This ONLY indicates whether a |
|
188 |
* given path is expanded, and NOT if it is visible or not. That |
|
189 |
* information must be determined by visiting all the parent |
|
190 |
* paths and seeing if they are visible. |
|
191 |
*/ |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
192 |
transient private Hashtable<TreePath, Boolean> expandedState; |
2 | 193 |
|
194 |
||
195 |
/** |
|
196 |
* True if handles are displayed at the topmost level of the tree. |
|
197 |
* <p> |
|
198 |
* A handle is a small icon that displays adjacent to the node which |
|
199 |
* allows the user to click once to expand or collapse the node. A |
|
200 |
* common interface shows a plus sign (+) for a node which can be |
|
201 |
* expanded and a minus sign (-) for a node which can be collapsed. |
|
202 |
* Handles are always shown for nodes below the topmost level. |
|
203 |
* <p> |
|
204 |
* If the <code>rootVisible</code> setting specifies that the root |
|
205 |
* node is to be displayed, then that is the only node at the topmost |
|
206 |
* level. If the root node is not displayed, then all of its |
|
207 |
* children are at the topmost level of the tree. Handles are |
|
208 |
* always displayed for nodes other than the topmost. |
|
209 |
* <p> |
|
210 |
* If the root node isn't visible, it is generally a good to make |
|
211 |
* this value true. Otherwise, the tree looks exactly like a list, |
|
212 |
* and users may not know that the "list entries" are actually |
|
213 |
* tree nodes. |
|
214 |
* |
|
215 |
* @see #rootVisible |
|
216 |
*/ |
|
217 |
protected boolean showsRootHandles; |
|
218 |
private boolean showsRootHandlesSet = false; |
|
219 |
||
220 |
/** |
|
221 |
* Creates a new event and passed it off the |
|
222 |
* <code>selectionListeners</code>. |
|
223 |
*/ |
|
224 |
protected transient TreeSelectionRedirector selectionRedirector; |
|
225 |
||
226 |
/** |
|
227 |
* Editor for the entries. Default is <code>null</code> |
|
228 |
* (tree is not editable). |
|
229 |
*/ |
|
230 |
transient protected TreeCellEditor cellEditor; |
|
231 |
||
232 |
/** |
|
233 |
* Is the tree editable? Default is false. |
|
234 |
*/ |
|
235 |
protected boolean editable; |
|
236 |
||
237 |
/** |
|
238 |
* Is this tree a large model? This is a code-optimization setting. |
|
239 |
* A large model can be used when the cell height is the same for all |
|
240 |
* nodes. The UI will then cache very little information and instead |
|
241 |
* continually message the model. Without a large model the UI caches |
|
242 |
* most of the information, resulting in fewer method calls to the model. |
|
243 |
* <p> |
|
244 |
* This value is only a suggestion to the UI. Not all UIs will |
|
245 |
* take advantage of it. Default value is false. |
|
246 |
*/ |
|
247 |
protected boolean largeModel; |
|
248 |
||
249 |
/** |
|
250 |
* Number of rows to make visible at one time. This value is used for |
|
251 |
* the <code>Scrollable</code> interface. It determines the preferred |
|
252 |
* size of the display area. |
|
253 |
*/ |
|
254 |
protected int visibleRowCount; |
|
255 |
||
256 |
/** |
|
257 |
* If true, when editing is to be stopped by way of selection changing, |
|
258 |
* data in tree changing or other means <code>stopCellEditing</code> |
|
259 |
* is invoked, and changes are saved. If false, |
|
260 |
* <code>cancelCellEditing</code> is invoked, and changes |
|
261 |
* are discarded. Default is false. |
|
262 |
*/ |
|
263 |
protected boolean invokesStopCellEditing; |
|
264 |
||
265 |
/** |
|
266 |
* If true, when a node is expanded, as many of the descendants are |
|
267 |
* scrolled to be visible. |
|
268 |
*/ |
|
269 |
protected boolean scrollsOnExpand; |
|
270 |
private boolean scrollsOnExpandSet = false; |
|
271 |
||
272 |
/** |
|
273 |
* Number of mouse clicks before a node is expanded. |
|
274 |
*/ |
|
275 |
protected int toggleClickCount; |
|
276 |
||
277 |
/** |
|
278 |
* Updates the <code>expandedState</code>. |
|
279 |
*/ |
|
280 |
transient protected TreeModelListener treeModelListener; |
|
281 |
||
282 |
/** |
|
283 |
* Used when <code>setExpandedState</code> is invoked, |
|
284 |
* will be a <code>Stack</code> of <code>Stack</code>s. |
|
285 |
*/ |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
286 |
transient private Stack<Stack<TreePath>> expandedStack; |
2 | 287 |
|
288 |
/** |
|
289 |
* Lead selection path, may not be <code>null</code>. |
|
290 |
*/ |
|
291 |
private TreePath leadPath; |
|
292 |
||
293 |
/** |
|
294 |
* Anchor path. |
|
295 |
*/ |
|
296 |
private TreePath anchorPath; |
|
297 |
||
298 |
/** |
|
299 |
* True if paths in the selection should be expanded. |
|
300 |
*/ |
|
301 |
private boolean expandsSelectedPaths; |
|
302 |
||
303 |
/** |
|
304 |
* This is set to true for the life of the <code>setUI</code> call. |
|
305 |
*/ |
|
306 |
private boolean settingUI; |
|
307 |
||
308 |
/** If true, mouse presses on selections initiate a drag operation. */ |
|
309 |
private boolean dragEnabled; |
|
310 |
||
311 |
/** |
|
312 |
* The drop mode for this component. |
|
313 |
*/ |
|
314 |
private DropMode dropMode = DropMode.USE_SELECTION; |
|
315 |
||
316 |
/** |
|
317 |
* The drop location. |
|
318 |
*/ |
|
319 |
private transient DropLocation dropLocation; |
|
320 |
||
321 |
/** |
|
322 |
* A subclass of <code>TransferHandler.DropLocation</code> representing |
|
323 |
* a drop location for a <code>JTree</code>. |
|
324 |
* |
|
325 |
* @see #getDropLocation |
|
326 |
* @since 1.6 |
|
327 |
*/ |
|
328 |
public static final class DropLocation extends TransferHandler.DropLocation { |
|
329 |
private final TreePath path; |
|
330 |
private final int index; |
|
331 |
||
332 |
private DropLocation(Point p, TreePath path, int index) { |
|
333 |
super(p); |
|
334 |
this.path = path; |
|
335 |
this.index = index; |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Returns the index where the dropped data should be inserted |
|
340 |
* with respect to the path returned by <code>getPath()</code>. |
|
341 |
* <p> |
|
342 |
* For drop modes <code>DropMode.USE_SELECTION</code> and |
|
343 |
* <code>DropMode.ON</code>, this index is unimportant (and it will |
|
344 |
* always be <code>-1</code>) as the only interesting data is the |
|
345 |
* path over which the drop operation occurred. |
|
346 |
* <p> |
|
347 |
* For drop mode <code>DropMode.INSERT</code>, this index |
|
348 |
* indicates the index at which the data should be inserted into |
|
349 |
* the parent path represented by <code>getPath()</code>. |
|
350 |
* <code>-1</code> indicates that the drop occurred over the |
|
351 |
* parent itself, and in most cases should be treated as inserting |
|
352 |
* into either the beginning or the end of the parent's list of |
|
353 |
* children. |
|
354 |
* <p> |
|
355 |
* For <code>DropMode.ON_OR_INSERT</code>, this value will be |
|
356 |
* an insert index, as described above, or <code>-1</code> if |
|
357 |
* the drop occurred over the path itself. |
|
358 |
* |
|
359 |
* @return the child index |
|
360 |
* @see #getPath |
|
361 |
*/ |
|
362 |
public int getChildIndex() { |
|
363 |
return index; |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* Returns the path where dropped data should be placed in the |
|
368 |
* tree. |
|
369 |
* <p> |
|
370 |
* Interpretation of this value depends on the drop mode set on the |
|
371 |
* component. If the drop mode is <code>DropMode.USE_SELECTION</code> |
|
372 |
* or <code>DropMode.ON</code>, the return value is the path in the |
|
373 |
* tree over which the data has been (or will be) dropped. |
|
374 |
* <code>null</code> indicates that the drop is over empty space, |
|
375 |
* not associated with a particular path. |
|
376 |
* <p> |
|
377 |
* If the drop mode is <code>DropMode.INSERT</code>, the return value |
|
378 |
* refers to the path that should become the parent of the new data, |
|
379 |
* in which case <code>getChildIndex()</code> indicates where the |
|
380 |
* new item should be inserted into this parent path. A |
|
381 |
* <code>null</code> path indicates that no parent path has been |
|
382 |
* determined, which can happen for multiple reasons: |
|
383 |
* <ul> |
|
384 |
* <li>The tree has no model |
|
385 |
* <li>There is no root in the tree |
|
386 |
* <li>The root is collapsed |
|
387 |
* <li>The root is a leaf node |
|
388 |
* </ul> |
|
389 |
* It is up to the developer to decide if and how they wish to handle |
|
390 |
* the <code>null</code> case. |
|
391 |
* <p> |
|
392 |
* If the drop mode is <code>DropMode.ON_OR_INSERT</code>, |
|
393 |
* <code>getChildIndex</code> can be used to determine whether the |
|
394 |
* drop is on top of the path itself (<code>-1</code>) or the index |
|
395 |
* at which it should be inserted into the path (values other than |
|
396 |
* <code>-1</code>). |
|
397 |
* |
|
398 |
* @return the drop path |
|
399 |
* @see #getChildIndex |
|
400 |
*/ |
|
401 |
public TreePath getPath() { |
|
402 |
return path; |
|
403 |
} |
|
404 |
||
405 |
/** |
|
406 |
* Returns a string representation of this drop location. |
|
407 |
* This method is intended to be used for debugging purposes, |
|
408 |
* and the content and format of the returned string may vary |
|
409 |
* between implementations. |
|
410 |
* |
|
411 |
* @return a string representation of this drop location |
|
412 |
*/ |
|
413 |
public String toString() { |
|
414 |
return getClass().getName() |
|
415 |
+ "[dropPoint=" + getDropPoint() + "," |
|
416 |
+ "path=" + path + "," |
|
417 |
+ "childIndex=" + index + "]"; |
|
418 |
} |
|
419 |
} |
|
420 |
||
421 |
/** |
|
422 |
* The row to expand during DnD. |
|
423 |
*/ |
|
424 |
private int expandRow = -1; |
|
425 |
||
11268 | 426 |
@SuppressWarnings("serial") |
2 | 427 |
private class TreeTimer extends Timer { |
428 |
public TreeTimer() { |
|
429 |
super(2000, null); |
|
430 |
setRepeats(false); |
|
431 |
} |
|
432 |
||
433 |
public void fireActionPerformed(ActionEvent ae) { |
|
434 |
JTree.this.expandRow(expandRow); |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
/** |
|
439 |
* A timer to expand nodes during drop. |
|
440 |
*/ |
|
441 |
private TreeTimer dropTimer; |
|
442 |
||
443 |
/** |
|
444 |
* When <code>addTreeExpansionListener</code> is invoked, |
|
445 |
* and <code>settingUI</code> is true, this ivar gets set to the passed in |
|
446 |
* <code>Listener</code>. This listener is then notified first in |
|
447 |
* <code>fireTreeCollapsed</code> and <code>fireTreeExpanded</code>. |
|
448 |
* <p>This is an ugly workaround for a way to have the UI listener |
|
449 |
* get notified before other listeners. |
|
450 |
*/ |
|
451 |
private transient TreeExpansionListener uiTreeExpansionListener; |
|
452 |
||
453 |
/** |
|
454 |
* Max number of stacks to keep around. |
|
455 |
*/ |
|
456 |
private static int TEMP_STACK_SIZE = 11; |
|
457 |
||
458 |
// |
|
459 |
// Bound property names |
|
460 |
// |
|
461 |
/** Bound property name for <code>cellRenderer</code>. */ |
|
462 |
public final static String CELL_RENDERER_PROPERTY = "cellRenderer"; |
|
463 |
/** Bound property name for <code>treeModel</code>. */ |
|
464 |
public final static String TREE_MODEL_PROPERTY = "model"; |
|
465 |
/** Bound property name for <code>rootVisible</code>. */ |
|
466 |
public final static String ROOT_VISIBLE_PROPERTY = "rootVisible"; |
|
467 |
/** Bound property name for <code>showsRootHandles</code>. */ |
|
468 |
public final static String SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles"; |
|
469 |
/** Bound property name for <code>rowHeight</code>. */ |
|
470 |
public final static String ROW_HEIGHT_PROPERTY = "rowHeight"; |
|
471 |
/** Bound property name for <code>cellEditor</code>. */ |
|
472 |
public final static String CELL_EDITOR_PROPERTY = "cellEditor"; |
|
473 |
/** Bound property name for <code>editable</code>. */ |
|
474 |
public final static String EDITABLE_PROPERTY = "editable"; |
|
475 |
/** Bound property name for <code>largeModel</code>. */ |
|
476 |
public final static String LARGE_MODEL_PROPERTY = "largeModel"; |
|
477 |
/** Bound property name for selectionModel. */ |
|
478 |
public final static String SELECTION_MODEL_PROPERTY = "selectionModel"; |
|
479 |
/** Bound property name for <code>visibleRowCount</code>. */ |
|
480 |
public final static String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount"; |
|
481 |
/** Bound property name for <code>messagesStopCellEditing</code>. */ |
|
482 |
public final static String INVOKES_STOP_CELL_EDITING_PROPERTY = "invokesStopCellEditing"; |
|
483 |
/** Bound property name for <code>scrollsOnExpand</code>. */ |
|
484 |
public final static String SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand"; |
|
485 |
/** Bound property name for <code>toggleClickCount</code>. */ |
|
486 |
public final static String TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount"; |
|
487 |
/** Bound property name for <code>leadSelectionPath</code>. |
|
488 |
* @since 1.3 */ |
|
489 |
public final static String LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath"; |
|
490 |
/** Bound property name for anchor selection path. |
|
491 |
* @since 1.3 */ |
|
492 |
public final static String ANCHOR_SELECTION_PATH_PROPERTY = "anchorSelectionPath"; |
|
493 |
/** Bound property name for expands selected paths property |
|
494 |
* @since 1.3 */ |
|
495 |
public final static String EXPANDS_SELECTED_PATHS_PROPERTY = "expandsSelectedPaths"; |
|
496 |
||
497 |
||
498 |
/** |
|
499 |
* Creates and returns a sample <code>TreeModel</code>. |
|
500 |
* Used primarily for beanbuilders to show something interesting. |
|
501 |
* |
|
502 |
* @return the default <code>TreeModel</code> |
|
503 |
*/ |
|
504 |
protected static TreeModel getDefaultTreeModel() { |
|
505 |
DefaultMutableTreeNode root = new DefaultMutableTreeNode("JTree"); |
|
506 |
DefaultMutableTreeNode parent; |
|
507 |
||
508 |
parent = new DefaultMutableTreeNode("colors"); |
|
509 |
root.add(parent); |
|
510 |
parent.add(new DefaultMutableTreeNode("blue")); |
|
511 |
parent.add(new DefaultMutableTreeNode("violet")); |
|
512 |
parent.add(new DefaultMutableTreeNode("red")); |
|
513 |
parent.add(new DefaultMutableTreeNode("yellow")); |
|
514 |
||
515 |
parent = new DefaultMutableTreeNode("sports"); |
|
516 |
root.add(parent); |
|
517 |
parent.add(new DefaultMutableTreeNode("basketball")); |
|
518 |
parent.add(new DefaultMutableTreeNode("soccer")); |
|
519 |
parent.add(new DefaultMutableTreeNode("football")); |
|
520 |
parent.add(new DefaultMutableTreeNode("hockey")); |
|
521 |
||
522 |
parent = new DefaultMutableTreeNode("food"); |
|
523 |
root.add(parent); |
|
524 |
parent.add(new DefaultMutableTreeNode("hot dogs")); |
|
525 |
parent.add(new DefaultMutableTreeNode("pizza")); |
|
526 |
parent.add(new DefaultMutableTreeNode("ravioli")); |
|
527 |
parent.add(new DefaultMutableTreeNode("bananas")); |
|
528 |
return new DefaultTreeModel(root); |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* Returns a <code>TreeModel</code> wrapping the specified object. |
|
533 |
* If the object is:<ul> |
|
534 |
* <li>an array of <code>Object</code>s, |
|
535 |
* <li>a <code>Hashtable</code>, or |
|
536 |
* <li>a <code>Vector</code> |
|
537 |
* </ul>then a new root node is created with each of the incoming |
|
538 |
* objects as children. Otherwise, a new root is created with |
|
539 |
* a value of {@code "root"}. |
|
540 |
* |
|
541 |
* @param value the <code>Object</code> used as the foundation for |
|
542 |
* the <code>TreeModel</code> |
|
543 |
* @return a <code>TreeModel</code> wrapping the specified object |
|
544 |
*/ |
|
545 |
protected static TreeModel createTreeModel(Object value) { |
|
546 |
DefaultMutableTreeNode root; |
|
547 |
||
548 |
if((value instanceof Object[]) || (value instanceof Hashtable) || |
|
549 |
(value instanceof Vector)) { |
|
550 |
root = new DefaultMutableTreeNode("root"); |
|
551 |
DynamicUtilTreeNode.createChildren(root, value); |
|
552 |
} |
|
553 |
else { |
|
554 |
root = new DynamicUtilTreeNode("root", value); |
|
555 |
} |
|
556 |
return new DefaultTreeModel(root, false); |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Returns a <code>JTree</code> with a sample model. |
|
561 |
* The default model used by the tree defines a leaf node as any node |
|
562 |
* without children. |
|
563 |
* |
|
564 |
* @see DefaultTreeModel#asksAllowsChildren |
|
565 |
*/ |
|
566 |
public JTree() { |
|
567 |
this(getDefaultTreeModel()); |
|
568 |
} |
|
569 |
||
570 |
/** |
|
571 |
* Returns a <code>JTree</code> with each element of the |
|
572 |
* specified array as the |
|
573 |
* child of a new root node which is not displayed. |
|
574 |
* By default, the tree defines a leaf node as any node without |
|
575 |
* children. |
|
576 |
* |
|
577 |
* @param value an array of <code>Object</code>s |
|
578 |
* @see DefaultTreeModel#asksAllowsChildren |
|
579 |
*/ |
|
580 |
public JTree(Object[] value) { |
|
581 |
this(createTreeModel(value)); |
|
582 |
this.setRootVisible(false); |
|
583 |
this.setShowsRootHandles(true); |
|
584 |
expandRoot(); |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* Returns a <code>JTree</code> with each element of the specified |
|
589 |
* <code>Vector</code> as the |
|
590 |
* child of a new root node which is not displayed. By default, the |
|
591 |
* tree defines a leaf node as any node without children. |
|
592 |
* |
|
593 |
* @param value a <code>Vector</code> |
|
594 |
* @see DefaultTreeModel#asksAllowsChildren |
|
595 |
*/ |
|
596 |
public JTree(Vector<?> value) { |
|
597 |
this(createTreeModel(value)); |
|
598 |
this.setRootVisible(false); |
|
599 |
this.setShowsRootHandles(true); |
|
600 |
expandRoot(); |
|
601 |
} |
|
602 |
||
603 |
/** |
|
604 |
* Returns a <code>JTree</code> created from a <code>Hashtable</code> |
|
605 |
* which does not display with root. |
|
606 |
* Each value-half of the key/value pairs in the <code>HashTable</code> |
|
607 |
* becomes a child of the new root node. By default, the tree defines |
|
608 |
* a leaf node as any node without children. |
|
609 |
* |
|
610 |
* @param value a <code>Hashtable</code> |
|
611 |
* @see DefaultTreeModel#asksAllowsChildren |
|
612 |
*/ |
|
613 |
public JTree(Hashtable<?,?> value) { |
|
614 |
this(createTreeModel(value)); |
|
615 |
this.setRootVisible(false); |
|
616 |
this.setShowsRootHandles(true); |
|
617 |
expandRoot(); |
|
618 |
} |
|
619 |
||
620 |
/** |
|
621 |
* Returns a <code>JTree</code> with the specified |
|
622 |
* <code>TreeNode</code> as its root, |
|
623 |
* which displays the root node. |
|
624 |
* By default, the tree defines a leaf node as any node without children. |
|
625 |
* |
|
626 |
* @param root a <code>TreeNode</code> object |
|
627 |
* @see DefaultTreeModel#asksAllowsChildren |
|
628 |
*/ |
|
629 |
public JTree(TreeNode root) { |
|
630 |
this(root, false); |
|
631 |
} |
|
632 |
||
633 |
/** |
|
634 |
* Returns a <code>JTree</code> with the specified <code>TreeNode</code> |
|
635 |
* as its root, which |
|
636 |
* displays the root node and which decides whether a node is a |
|
637 |
* leaf node in the specified manner. |
|
638 |
* |
|
639 |
* @param root a <code>TreeNode</code> object |
|
640 |
* @param asksAllowsChildren if false, any node without children is a |
|
641 |
* leaf node; if true, only nodes that do not allow |
|
642 |
* children are leaf nodes |
|
643 |
* @see DefaultTreeModel#asksAllowsChildren |
|
644 |
*/ |
|
645 |
public JTree(TreeNode root, boolean asksAllowsChildren) { |
|
646 |
this(new DefaultTreeModel(root, asksAllowsChildren)); |
|
647 |
} |
|
648 |
||
649 |
/** |
|
650 |
* Returns an instance of <code>JTree</code> which displays the root node |
|
651 |
* -- the tree is created using the specified data model. |
|
652 |
* |
|
653 |
* @param newModel the <code>TreeModel</code> to use as the data model |
|
654 |
*/ |
|
655 |
@ConstructorProperties({"model"}) |
|
656 |
public JTree(TreeModel newModel) { |
|
657 |
super(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
658 |
expandedStack = new Stack<Stack<TreePath>>(); |
2 | 659 |
toggleClickCount = 2; |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
660 |
expandedState = new Hashtable<TreePath, Boolean>(); |
2 | 661 |
setLayout(null); |
662 |
rowHeight = 16; |
|
663 |
visibleRowCount = 20; |
|
664 |
rootVisible = true; |
|
665 |
selectionModel = new DefaultTreeSelectionModel(); |
|
666 |
cellRenderer = null; |
|
667 |
scrollsOnExpand = true; |
|
668 |
setOpaque(true); |
|
669 |
expandsSelectedPaths = true; |
|
670 |
updateUI(); |
|
671 |
setModel(newModel); |
|
672 |
} |
|
673 |
||
674 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
675 |
* Returns the L&F object that renders this component. |
2 | 676 |
* |
677 |
* @return the <code>TreeUI</code> object that renders this component |
|
678 |
*/ |
|
679 |
public TreeUI getUI() { |
|
680 |
return (TreeUI)ui; |
|
681 |
} |
|
682 |
||
683 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
684 |
* Sets the L&F object that renders this component. |
2 | 685 |
* <p> |
686 |
* This is a bound property. |
|
687 |
* |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
688 |
* @param ui the <code>TreeUI</code> L&F object |
2 | 689 |
* @see UIDefaults#getUI |
690 |
* @beaninfo |
|
691 |
* bound: true |
|
692 |
* hidden: true |
|
693 |
* attribute: visualUpdate true |
|
694 |
* description: The UI object that implements the Component's LookAndFeel. |
|
695 |
*/ |
|
696 |
public void setUI(TreeUI ui) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
697 |
if (this.ui != ui) { |
2 | 698 |
settingUI = true; |
699 |
uiTreeExpansionListener = null; |
|
700 |
try { |
|
701 |
super.setUI(ui); |
|
702 |
} |
|
703 |
finally { |
|
704 |
settingUI = false; |
|
705 |
} |
|
706 |
} |
|
707 |
} |
|
708 |
||
709 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
710 |
* Notification from the <code>UIManager</code> that the L&F has changed. |
2 | 711 |
* Replaces the current UI object with the latest version from the |
712 |
* <code>UIManager</code>. |
|
713 |
* |
|
714 |
* @see JComponent#updateUI |
|
715 |
*/ |
|
716 |
public void updateUI() { |
|
717 |
setUI((TreeUI)UIManager.getUI(this)); |
|
718 |
||
719 |
SwingUtilities.updateRendererOrEditorUI(getCellRenderer()); |
|
720 |
SwingUtilities.updateRendererOrEditorUI(getCellEditor()); |
|
721 |
} |
|
722 |
||
723 |
||
724 |
/** |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
725 |
* Returns the name of the L&F class that renders this component. |
2 | 726 |
* |
727 |
* @return the string "TreeUI" |
|
728 |
* @see JComponent#getUIClassID |
|
729 |
* @see UIDefaults#getUI |
|
730 |
*/ |
|
731 |
public String getUIClassID() { |
|
732 |
return uiClassID; |
|
733 |
} |
|
734 |
||
735 |
||
736 |
/** |
|
737 |
* Returns the current <code>TreeCellRenderer</code> |
|
738 |
* that is rendering each cell. |
|
739 |
* |
|
740 |
* @return the <code>TreeCellRenderer</code> that is rendering each cell |
|
741 |
*/ |
|
742 |
public TreeCellRenderer getCellRenderer() { |
|
743 |
return cellRenderer; |
|
744 |
} |
|
745 |
||
746 |
/** |
|
747 |
* Sets the <code>TreeCellRenderer</code> that will be used to |
|
748 |
* draw each cell. |
|
749 |
* <p> |
|
750 |
* This is a bound property. |
|
751 |
* |
|
752 |
* @param x the <code>TreeCellRenderer</code> that is to render each cell |
|
753 |
* @beaninfo |
|
754 |
* bound: true |
|
755 |
* description: The TreeCellRenderer that will be used to draw |
|
756 |
* each cell. |
|
757 |
*/ |
|
758 |
public void setCellRenderer(TreeCellRenderer x) { |
|
759 |
TreeCellRenderer oldValue = cellRenderer; |
|
760 |
||
761 |
cellRenderer = x; |
|
762 |
firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, cellRenderer); |
|
763 |
invalidate(); |
|
764 |
} |
|
765 |
||
766 |
/** |
|
767 |
* Determines whether the tree is editable. Fires a property |
|
768 |
* change event if the new setting is different from the existing |
|
769 |
* setting. |
|
770 |
* <p> |
|
771 |
* This is a bound property. |
|
772 |
* |
|
773 |
* @param flag a boolean value, true if the tree is editable |
|
774 |
* @beaninfo |
|
775 |
* bound: true |
|
776 |
* description: Whether the tree is editable. |
|
777 |
*/ |
|
778 |
public void setEditable(boolean flag) { |
|
779 |
boolean oldValue = this.editable; |
|
780 |
||
781 |
this.editable = flag; |
|
782 |
firePropertyChange(EDITABLE_PROPERTY, oldValue, flag); |
|
783 |
if (accessibleContext != null) { |
|
784 |
accessibleContext.firePropertyChange( |
|
785 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
786 |
(oldValue ? AccessibleState.EDITABLE : null), |
|
787 |
(flag ? AccessibleState.EDITABLE : null)); |
|
788 |
} |
|
789 |
} |
|
790 |
||
791 |
/** |
|
792 |
* Returns true if the tree is editable. |
|
793 |
* |
|
794 |
* @return true if the tree is editable |
|
795 |
*/ |
|
796 |
public boolean isEditable() { |
|
797 |
return editable; |
|
798 |
} |
|
799 |
||
800 |
/** |
|
801 |
* Sets the cell editor. A <code>null</code> value implies that the |
|
802 |
* tree cannot be edited. If this represents a change in the |
|
803 |
* <code>cellEditor</code>, the <code>propertyChange</code> |
|
804 |
* method is invoked on all listeners. |
|
805 |
* <p> |
|
806 |
* This is a bound property. |
|
807 |
* |
|
808 |
* @param cellEditor the <code>TreeCellEditor</code> to use |
|
809 |
* @beaninfo |
|
810 |
* bound: true |
|
811 |
* description: The cell editor. A null value implies the tree |
|
812 |
* cannot be edited. |
|
813 |
*/ |
|
814 |
public void setCellEditor(TreeCellEditor cellEditor) { |
|
815 |
TreeCellEditor oldEditor = this.cellEditor; |
|
816 |
||
817 |
this.cellEditor = cellEditor; |
|
818 |
firePropertyChange(CELL_EDITOR_PROPERTY, oldEditor, cellEditor); |
|
819 |
invalidate(); |
|
820 |
} |
|
821 |
||
822 |
/** |
|
823 |
* Returns the editor used to edit entries in the tree. |
|
824 |
* |
|
825 |
* @return the <code>TreeCellEditor</code> in use, |
|
826 |
* or <code>null</code> if the tree cannot be edited |
|
827 |
*/ |
|
828 |
public TreeCellEditor getCellEditor() { |
|
829 |
return cellEditor; |
|
830 |
} |
|
831 |
||
832 |
/** |
|
833 |
* Returns the <code>TreeModel</code> that is providing the data. |
|
834 |
* |
|
835 |
* @return the <code>TreeModel</code> that is providing the data |
|
836 |
*/ |
|
837 |
public TreeModel getModel() { |
|
838 |
return treeModel; |
|
839 |
} |
|
840 |
||
841 |
/** |
|
842 |
* Sets the <code>TreeModel</code> that will provide the data. |
|
843 |
* <p> |
|
844 |
* This is a bound property. |
|
845 |
* |
|
846 |
* @param newModel the <code>TreeModel</code> that is to provide the data |
|
847 |
* @beaninfo |
|
848 |
* bound: true |
|
849 |
* description: The TreeModel that will provide the data. |
|
850 |
*/ |
|
851 |
public void setModel(TreeModel newModel) { |
|
852 |
clearSelection(); |
|
853 |
||
854 |
TreeModel oldModel = treeModel; |
|
855 |
||
856 |
if(treeModel != null && treeModelListener != null) |
|
857 |
treeModel.removeTreeModelListener(treeModelListener); |
|
858 |
||
859 |
if (accessibleContext != null) { |
|
860 |
if (treeModel != null) { |
|
861 |
treeModel.removeTreeModelListener((TreeModelListener)accessibleContext); |
|
862 |
} |
|
863 |
if (newModel != null) { |
|
864 |
newModel.addTreeModelListener((TreeModelListener)accessibleContext); |
|
865 |
} |
|
866 |
} |
|
867 |
||
868 |
treeModel = newModel; |
|
869 |
clearToggledPaths(); |
|
870 |
if(treeModel != null) { |
|
871 |
if(treeModelListener == null) |
|
872 |
treeModelListener = createTreeModelListener(); |
|
873 |
if(treeModelListener != null) |
|
874 |
treeModel.addTreeModelListener(treeModelListener); |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
875 |
|
2 | 876 |
// Mark the root as expanded, if it isn't a leaf. |
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
877 |
Object treeRoot = treeModel.getRoot(); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
878 |
if(treeRoot != null && |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
879 |
!treeModel.isLeaf(treeRoot)) { |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
880 |
expandedState.put(new TreePath(treeRoot), |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
881 |
Boolean.TRUE); |
2 | 882 |
} |
883 |
} |
|
884 |
firePropertyChange(TREE_MODEL_PROPERTY, oldModel, treeModel); |
|
885 |
invalidate(); |
|
886 |
} |
|
887 |
||
888 |
/** |
|
889 |
* Returns true if the root node of the tree is displayed. |
|
890 |
* |
|
891 |
* @return true if the root node of the tree is displayed |
|
892 |
* @see #rootVisible |
|
893 |
*/ |
|
894 |
public boolean isRootVisible() { |
|
895 |
return rootVisible; |
|
896 |
} |
|
897 |
||
898 |
/** |
|
899 |
* Determines whether or not the root node from |
|
900 |
* the <code>TreeModel</code> is visible. |
|
901 |
* <p> |
|
902 |
* This is a bound property. |
|
903 |
* |
|
904 |
* @param rootVisible true if the root node of the tree is to be displayed |
|
905 |
* @see #rootVisible |
|
906 |
* @beaninfo |
|
907 |
* bound: true |
|
908 |
* description: Whether or not the root node |
|
909 |
* from the TreeModel is visible. |
|
910 |
*/ |
|
911 |
public void setRootVisible(boolean rootVisible) { |
|
912 |
boolean oldValue = this.rootVisible; |
|
913 |
||
914 |
this.rootVisible = rootVisible; |
|
915 |
firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, this.rootVisible); |
|
916 |
if (accessibleContext != null) { |
|
917 |
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange(); |
|
918 |
} |
|
919 |
} |
|
920 |
||
921 |
/** |
|
922 |
* Sets the value of the <code>showsRootHandles</code> property, |
|
923 |
* which specifies whether the node handles should be displayed. |
|
924 |
* The default value of this property depends on the constructor |
|
925 |
* used to create the <code>JTree</code>. |
|
926 |
* Some look and feels might not support handles; |
|
927 |
* they will ignore this property. |
|
928 |
* <p> |
|
929 |
* This is a bound property. |
|
930 |
* |
|
931 |
* @param newValue <code>true</code> if root handles should be displayed; |
|
932 |
* otherwise, <code>false</code> |
|
933 |
* @see #showsRootHandles |
|
934 |
* @see #getShowsRootHandles |
|
935 |
* @beaninfo |
|
936 |
* bound: true |
|
937 |
* description: Whether the node handles are to be |
|
938 |
* displayed. |
|
939 |
*/ |
|
940 |
public void setShowsRootHandles(boolean newValue) { |
|
941 |
boolean oldValue = showsRootHandles; |
|
942 |
TreeModel model = getModel(); |
|
943 |
||
944 |
showsRootHandles = newValue; |
|
945 |
showsRootHandlesSet = true; |
|
946 |
firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, |
|
947 |
showsRootHandles); |
|
948 |
if (accessibleContext != null) { |
|
949 |
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange(); |
|
950 |
} |
|
951 |
invalidate(); |
|
952 |
} |
|
953 |
||
954 |
/** |
|
955 |
* Returns the value of the <code>showsRootHandles</code> property. |
|
956 |
* |
|
957 |
* @return the value of the <code>showsRootHandles</code> property |
|
958 |
* @see #showsRootHandles |
|
959 |
*/ |
|
960 |
public boolean getShowsRootHandles() |
|
961 |
{ |
|
962 |
return showsRootHandles; |
|
963 |
} |
|
964 |
||
965 |
/** |
|
966 |
* Sets the height of each cell, in pixels. If the specified value |
|
967 |
* is less than or equal to zero the current cell renderer is |
|
968 |
* queried for each row's height. |
|
969 |
* <p> |
|
970 |
* This is a bound property. |
|
971 |
* |
|
972 |
* @param rowHeight the height of each cell, in pixels |
|
973 |
* @beaninfo |
|
974 |
* bound: true |
|
975 |
* description: The height of each cell. |
|
976 |
*/ |
|
977 |
public void setRowHeight(int rowHeight) |
|
978 |
{ |
|
979 |
int oldValue = this.rowHeight; |
|
980 |
||
981 |
this.rowHeight = rowHeight; |
|
982 |
rowHeightSet = true; |
|
983 |
firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, this.rowHeight); |
|
984 |
invalidate(); |
|
985 |
} |
|
986 |
||
987 |
/** |
|
988 |
* Returns the height of each row. If the returned value is less than |
|
989 |
* or equal to 0 the height for each row is determined by the |
|
990 |
* renderer. |
|
991 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
992 |
* @return the height of each row |
2 | 993 |
*/ |
994 |
public int getRowHeight() |
|
995 |
{ |
|
996 |
return rowHeight; |
|
997 |
} |
|
998 |
||
999 |
/** |
|
1000 |
* Returns true if the height of each display row is a fixed size. |
|
1001 |
* |
|
1002 |
* @return true if the height of each row is a fixed size |
|
1003 |
*/ |
|
1004 |
public boolean isFixedRowHeight() |
|
1005 |
{ |
|
1006 |
return (rowHeight > 0); |
|
1007 |
} |
|
1008 |
||
1009 |
/** |
|
1010 |
* Specifies whether the UI should use a large model. |
|
1011 |
* (Not all UIs will implement this.) Fires a property change |
|
1012 |
* for the LARGE_MODEL_PROPERTY. |
|
1013 |
* <p> |
|
1014 |
* This is a bound property. |
|
1015 |
* |
|
1016 |
* @param newValue true to suggest a large model to the UI |
|
1017 |
* @see #largeModel |
|
1018 |
* @beaninfo |
|
1019 |
* bound: true |
|
1020 |
* description: Whether the UI should use a |
|
1021 |
* large model. |
|
1022 |
*/ |
|
1023 |
public void setLargeModel(boolean newValue) { |
|
1024 |
boolean oldValue = largeModel; |
|
1025 |
||
1026 |
largeModel = newValue; |
|
1027 |
firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, newValue); |
|
1028 |
} |
|
1029 |
||
1030 |
/** |
|
1031 |
* Returns true if the tree is configured for a large model. |
|
1032 |
* |
|
1033 |
* @return true if a large model is suggested |
|
1034 |
* @see #largeModel |
|
1035 |
*/ |
|
1036 |
public boolean isLargeModel() { |
|
1037 |
return largeModel; |
|
1038 |
} |
|
1039 |
||
1040 |
/** |
|
1041 |
* Determines what happens when editing is interrupted by selecting |
|
1042 |
* another node in the tree, a change in the tree's data, or by some |
|
1043 |
* other means. Setting this property to <code>true</code> causes the |
|
1044 |
* changes to be automatically saved when editing is interrupted. |
|
1045 |
* <p> |
|
1046 |
* Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY. |
|
1047 |
* |
|
1048 |
* @param newValue true means that <code>stopCellEditing</code> is invoked |
|
1049 |
* when editing is interrupted, and data is saved; false means that |
|
1050 |
* <code>cancelCellEditing</code> is invoked, and changes are lost |
|
1051 |
* @beaninfo |
|
1052 |
* bound: true |
|
1053 |
* description: Determines what happens when editing is interrupted, |
|
1054 |
* selecting another node in the tree, a change in the |
|
1055 |
* tree's data, or some other means. |
|
1056 |
*/ |
|
1057 |
public void setInvokesStopCellEditing(boolean newValue) { |
|
1058 |
boolean oldValue = invokesStopCellEditing; |
|
1059 |
||
1060 |
invokesStopCellEditing = newValue; |
|
1061 |
firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue, |
|
1062 |
newValue); |
|
1063 |
} |
|
1064 |
||
1065 |
/** |
|
1066 |
* Returns the indicator that tells what happens when editing is |
|
1067 |
* interrupted. |
|
1068 |
* |
|
1069 |
* @return the indicator that tells what happens when editing is |
|
1070 |
* interrupted |
|
1071 |
* @see #setInvokesStopCellEditing |
|
1072 |
*/ |
|
1073 |
public boolean getInvokesStopCellEditing() { |
|
1074 |
return invokesStopCellEditing; |
|
1075 |
} |
|
1076 |
||
1077 |
/** |
|
1078 |
* Sets the <code>scrollsOnExpand</code> property, |
|
1079 |
* which determines whether the |
|
1080 |
* tree might scroll to show previously hidden children. |
|
1081 |
* If this property is <code>true</code> (the default), |
|
1082 |
* when a node expands |
|
1083 |
* the tree can use scrolling to make |
|
1084 |
* the maximum possible number of the node's descendants visible. |
|
1085 |
* In some look and feels, trees might not need to scroll when expanded; |
|
1086 |
* those look and feels will ignore this property. |
|
1087 |
* <p> |
|
1088 |
* This is a bound property. |
|
1089 |
* |
|
1090 |
* @param newValue <code>false</code> to disable scrolling on expansion; |
|
1091 |
* <code>true</code> to enable it |
|
1092 |
* @see #getScrollsOnExpand |
|
1093 |
* |
|
1094 |
* @beaninfo |
|
1095 |
* bound: true |
|
1096 |
* description: Indicates if a node descendant should be scrolled when expanded. |
|
1097 |
*/ |
|
1098 |
public void setScrollsOnExpand(boolean newValue) { |
|
1099 |
boolean oldValue = scrollsOnExpand; |
|
1100 |
||
1101 |
scrollsOnExpand = newValue; |
|
1102 |
scrollsOnExpandSet = true; |
|
1103 |
firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, |
|
1104 |
newValue); |
|
1105 |
} |
|
1106 |
||
1107 |
/** |
|
1108 |
* Returns the value of the <code>scrollsOnExpand</code> property. |
|
1109 |
* |
|
1110 |
* @return the value of the <code>scrollsOnExpand</code> property |
|
1111 |
*/ |
|
1112 |
public boolean getScrollsOnExpand() { |
|
1113 |
return scrollsOnExpand; |
|
1114 |
} |
|
1115 |
||
1116 |
/** |
|
1117 |
* Sets the number of mouse clicks before a node will expand or close. |
|
1118 |
* The default is two. |
|
1119 |
* <p> |
|
1120 |
* This is a bound property. |
|
1121 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
1122 |
* @param clickCount the number of mouse clicks to get a node expanded or closed |
2 | 1123 |
* @since 1.3 |
1124 |
* @beaninfo |
|
1125 |
* bound: true |
|
1126 |
* description: Number of clicks before a node will expand/collapse. |
|
1127 |
*/ |
|
1128 |
public void setToggleClickCount(int clickCount) { |
|
1129 |
int oldCount = toggleClickCount; |
|
1130 |
||
1131 |
toggleClickCount = clickCount; |
|
1132 |
firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldCount, |
|
1133 |
clickCount); |
|
1134 |
} |
|
1135 |
||
1136 |
/** |
|
1137 |
* Returns the number of mouse clicks needed to expand or close a node. |
|
1138 |
* |
|
1139 |
* @return number of mouse clicks before node is expanded |
|
1140 |
* @since 1.3 |
|
1141 |
*/ |
|
1142 |
public int getToggleClickCount() { |
|
1143 |
return toggleClickCount; |
|
1144 |
} |
|
1145 |
||
1146 |
/** |
|
1147 |
* Configures the <code>expandsSelectedPaths</code> property. If |
|
1148 |
* true, any time the selection is changed, either via the |
|
1149 |
* <code>TreeSelectionModel</code>, or the cover methods provided by |
|
1150 |
* <code>JTree</code>, the <code>TreePath</code>s parents will be |
|
1151 |
* expanded to make them visible (visible meaning the parent path is |
|
1152 |
* expanded, not necessarily in the visible rectangle of the |
|
1153 |
* <code>JTree</code>). If false, when the selection |
|
1154 |
* changes the nodes parent is not made visible (all its parents expanded). |
|
1155 |
* This is useful if you wish to have your selection model maintain paths |
|
1156 |
* that are not always visible (all parents expanded). |
|
1157 |
* <p> |
|
1158 |
* This is a bound property. |
|
1159 |
* |
|
1160 |
* @param newValue the new value for <code>expandsSelectedPaths</code> |
|
1161 |
* |
|
1162 |
* @since 1.3 |
|
1163 |
* @beaninfo |
|
1164 |
* bound: true |
|
1165 |
* description: Indicates whether changes to the selection should make |
|
1166 |
* the parent of the path visible. |
|
1167 |
*/ |
|
1168 |
public void setExpandsSelectedPaths(boolean newValue) { |
|
1169 |
boolean oldValue = expandsSelectedPaths; |
|
1170 |
||
1171 |
expandsSelectedPaths = newValue; |
|
1172 |
firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, |
|
1173 |
newValue); |
|
1174 |
} |
|
1175 |
||
1176 |
/** |
|
1177 |
* Returns the <code>expandsSelectedPaths</code> property. |
|
1178 |
* @return true if selection changes result in the parent path being |
|
1179 |
* expanded |
|
1180 |
* @since 1.3 |
|
1181 |
* @see #setExpandsSelectedPaths |
|
1182 |
*/ |
|
1183 |
public boolean getExpandsSelectedPaths() { |
|
1184 |
return expandsSelectedPaths; |
|
1185 |
} |
|
1186 |
||
1187 |
/** |
|
1188 |
* Turns on or off automatic drag handling. In order to enable automatic |
|
1189 |
* drag handling, this property should be set to {@code true}, and the |
|
1190 |
* tree's {@code TransferHandler} needs to be {@code non-null}. |
|
1191 |
* The default value of the {@code dragEnabled} property is {@code false}. |
|
1192 |
* <p> |
|
1193 |
* The job of honoring this property, and recognizing a user drag gesture, |
|
1194 |
* lies with the look and feel implementation, and in particular, the tree's |
|
1195 |
* {@code TreeUI}. When automatic drag handling is enabled, most look and |
|
1196 |
* feels (including those that subclass {@code BasicLookAndFeel}) begin a |
|
1197 |
* drag and drop operation whenever the user presses the mouse button over |
|
1198 |
* an item and then moves the mouse a few pixels. Setting this property to |
|
1199 |
* {@code true} can therefore have a subtle effect on how selections behave. |
|
1200 |
* <p> |
|
1201 |
* If a look and feel is used that ignores this property, you can still |
|
1202 |
* begin a drag and drop operation by calling {@code exportAsDrag} on the |
|
1203 |
* tree's {@code TransferHandler}. |
|
1204 |
* |
|
1205 |
* @param b whether or not to enable automatic drag handling |
|
1206 |
* @exception HeadlessException if |
|
1207 |
* <code>b</code> is <code>true</code> and |
|
1208 |
* <code>GraphicsEnvironment.isHeadless()</code> |
|
1209 |
* returns <code>true</code> |
|
1210 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
1211 |
* @see #getDragEnabled |
|
1212 |
* @see #setTransferHandler |
|
1213 |
* @see TransferHandler |
|
1214 |
* @since 1.4 |
|
1215 |
* |
|
1216 |
* @beaninfo |
|
1217 |
* description: determines whether automatic drag handling is enabled |
|
1218 |
* bound: false |
|
1219 |
*/ |
|
1220 |
public void setDragEnabled(boolean b) { |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1221 |
checkDragEnabled(b); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1222 |
dragEnabled = b; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1223 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1224 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1225 |
private static void checkDragEnabled(boolean b) { |
2 | 1226 |
if (b && GraphicsEnvironment.isHeadless()) { |
1227 |
throw new HeadlessException(); |
|
1228 |
} |
|
1229 |
} |
|
1230 |
||
1231 |
/** |
|
1232 |
* Returns whether or not automatic drag handling is enabled. |
|
1233 |
* |
|
1234 |
* @return the value of the {@code dragEnabled} property |
|
1235 |
* @see #setDragEnabled |
|
1236 |
* @since 1.4 |
|
1237 |
*/ |
|
1238 |
public boolean getDragEnabled() { |
|
1239 |
return dragEnabled; |
|
1240 |
} |
|
1241 |
||
1242 |
/** |
|
1243 |
* Sets the drop mode for this component. For backward compatibility, |
|
1244 |
* the default for this property is <code>DropMode.USE_SELECTION</code>. |
|
1245 |
* Usage of one of the other modes is recommended, however, for an |
|
1246 |
* improved user experience. <code>DropMode.ON</code>, for instance, |
|
1247 |
* offers similar behavior of showing items as selected, but does so without |
|
1248 |
* affecting the actual selection in the tree. |
|
1249 |
* <p> |
|
1250 |
* <code>JTree</code> supports the following drop modes: |
|
1251 |
* <ul> |
|
1252 |
* <li><code>DropMode.USE_SELECTION</code></li> |
|
1253 |
* <li><code>DropMode.ON</code></li> |
|
1254 |
* <li><code>DropMode.INSERT</code></li> |
|
1255 |
* <li><code>DropMode.ON_OR_INSERT</code></li> |
|
1256 |
* </ul> |
|
1257 |
* <p> |
|
1258 |
* The drop mode is only meaningful if this component has a |
|
1259 |
* <code>TransferHandler</code> that accepts drops. |
|
1260 |
* |
|
1261 |
* @param dropMode the drop mode to use |
|
1262 |
* @throws IllegalArgumentException if the drop mode is unsupported |
|
1263 |
* or <code>null</code> |
|
1264 |
* @see #getDropMode |
|
1265 |
* @see #getDropLocation |
|
1266 |
* @see #setTransferHandler |
|
1267 |
* @see TransferHandler |
|
1268 |
* @since 1.6 |
|
1269 |
*/ |
|
1270 |
public final void setDropMode(DropMode dropMode) { |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1271 |
checkDropMode(dropMode); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1272 |
this.dropMode = dropMode; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1273 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1274 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1275 |
private static void checkDropMode(DropMode dropMode) { |
2 | 1276 |
if (dropMode != null) { |
1277 |
switch (dropMode) { |
|
1278 |
case USE_SELECTION: |
|
1279 |
case ON: |
|
1280 |
case INSERT: |
|
1281 |
case ON_OR_INSERT: |
|
1282 |
return; |
|
1283 |
} |
|
1284 |
} |
|
1285 |
||
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1286 |
throw new IllegalArgumentException(dropMode + |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
1287 |
": Unsupported drop mode for tree"); |
2 | 1288 |
} |
1289 |
||
1290 |
/** |
|
1291 |
* Returns the drop mode for this component. |
|
1292 |
* |
|
1293 |
* @return the drop mode for this component |
|
1294 |
* @see #setDropMode |
|
1295 |
* @since 1.6 |
|
1296 |
*/ |
|
1297 |
public final DropMode getDropMode() { |
|
1298 |
return dropMode; |
|
1299 |
} |
|
1300 |
||
1301 |
/** |
|
1302 |
* Calculates a drop location in this component, representing where a |
|
1303 |
* drop at the given point should insert data. |
|
1304 |
* |
|
1305 |
* @param p the point to calculate a drop location for |
|
1306 |
* @return the drop location, or <code>null</code> |
|
1307 |
*/ |
|
1308 |
DropLocation dropLocationForPoint(Point p) { |
|
1309 |
DropLocation location = null; |
|
1310 |
||
1311 |
int row = getClosestRowForLocation(p.x, p.y); |
|
1312 |
Rectangle bounds = getRowBounds(row); |
|
1313 |
TreeModel model = getModel(); |
|
1314 |
Object root = (model == null) ? null : model.getRoot(); |
|
1315 |
TreePath rootPath = (root == null) ? null : new TreePath(root); |
|
1316 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1317 |
TreePath child; |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1318 |
TreePath parent; |
2 | 1319 |
boolean outside = row == -1 |
1320 |
|| p.y < bounds.y |
|
1321 |
|| p.y >= bounds.y + bounds.height; |
|
1322 |
||
1323 |
switch(dropMode) { |
|
1324 |
case USE_SELECTION: |
|
1325 |
case ON: |
|
1326 |
if (outside) { |
|
1327 |
location = new DropLocation(p, null, -1); |
|
1328 |
} else { |
|
1329 |
location = new DropLocation(p, getPathForRow(row), -1); |
|
1330 |
} |
|
1331 |
||
1332 |
break; |
|
1333 |
case INSERT: |
|
1334 |
case ON_OR_INSERT: |
|
1335 |
if (row == -1) { |
|
1336 |
if (root != null && !model.isLeaf(root) && isExpanded(rootPath)) { |
|
1337 |
location = new DropLocation(p, rootPath, 0); |
|
1338 |
} else { |
|
1339 |
location = new DropLocation(p, null, -1); |
|
1340 |
} |
|
1341 |
||
1342 |
break; |
|
1343 |
} |
|
1344 |
||
1345 |
boolean checkOn = dropMode == DropMode.ON_OR_INSERT |
|
1346 |
|| !model.isLeaf(getPathForRow(row).getLastPathComponent()); |
|
1347 |
||
1348 |
Section section = SwingUtilities2.liesInVertical(bounds, p, checkOn); |
|
1349 |
if(section == LEADING) { |
|
1350 |
child = getPathForRow(row); |
|
1351 |
parent = child.getParentPath(); |
|
1352 |
} else if (section == TRAILING) { |
|
1353 |
int index = row + 1; |
|
1354 |
if (index >= getRowCount()) { |
|
1355 |
if (model.isLeaf(root) || !isExpanded(rootPath)) { |
|
1356 |
location = new DropLocation(p, null, -1); |
|
1357 |
} else { |
|
1358 |
parent = rootPath; |
|
1359 |
index = model.getChildCount(root); |
|
1360 |
location = new DropLocation(p, parent, index); |
|
1361 |
} |
|
1362 |
||
1363 |
break; |
|
1364 |
} |
|
1365 |
||
1366 |
child = getPathForRow(index); |
|
1367 |
parent = child.getParentPath(); |
|
1368 |
} else { |
|
1369 |
assert checkOn; |
|
1370 |
location = new DropLocation(p, getPathForRow(row), -1); |
|
1371 |
break; |
|
1372 |
} |
|
1373 |
||
1374 |
if (parent != null) { |
|
1375 |
location = new DropLocation(p, parent, |
|
1376 |
model.getIndexOfChild(parent.getLastPathComponent(), |
|
1377 |
child.getLastPathComponent())); |
|
1378 |
} else if (checkOn || !model.isLeaf(root)) { |
|
1379 |
location = new DropLocation(p, rootPath, -1); |
|
1380 |
} else { |
|
1381 |
location = new DropLocation(p, null, -1); |
|
1382 |
} |
|
1383 |
||
1384 |
break; |
|
1385 |
default: |
|
1386 |
assert false : "Unexpected drop mode"; |
|
1387 |
} |
|
1388 |
||
1389 |
if (outside || row != expandRow) { |
|
1390 |
cancelDropTimer(); |
|
1391 |
} |
|
1392 |
||
1393 |
if (!outside && row != expandRow) { |
|
1394 |
if (isCollapsed(row)) { |
|
1395 |
expandRow = row; |
|
1396 |
startDropTimer(); |
|
1397 |
} |
|
1398 |
} |
|
1399 |
||
1400 |
return location; |
|
1401 |
} |
|
1402 |
||
1403 |
/** |
|
1404 |
* Called to set or clear the drop location during a DnD operation. |
|
1405 |
* In some cases, the component may need to use it's internal selection |
|
1406 |
* temporarily to indicate the drop location. To help facilitate this, |
|
1407 |
* this method returns and accepts as a parameter a state object. |
|
1408 |
* This state object can be used to store, and later restore, the selection |
|
1409 |
* state. Whatever this method returns will be passed back to it in |
|
1410 |
* future calls, as the state parameter. If it wants the DnD system to |
|
1411 |
* continue storing the same state, it must pass it back every time. |
|
1412 |
* Here's how this is used: |
|
1413 |
* <p> |
|
1414 |
* Let's say that on the first call to this method the component decides |
|
1415 |
* to save some state (because it is about to use the selection to show |
|
1416 |
* a drop index). It can return a state object to the caller encapsulating |
|
1417 |
* any saved selection state. On a second call, let's say the drop location |
|
1418 |
* is being changed to something else. The component doesn't need to |
|
1419 |
* restore anything yet, so it simply passes back the same state object |
|
1420 |
* to have the DnD system continue storing it. Finally, let's say this |
|
1421 |
* method is messaged with <code>null</code>. This means DnD |
|
1422 |
* is finished with this component for now, meaning it should restore |
|
1423 |
* state. At this point, it can use the state parameter to restore |
|
1424 |
* said state, and of course return <code>null</code> since there's |
|
1425 |
* no longer anything to store. |
|
1426 |
* |
|
1427 |
* @param location the drop location (as calculated by |
|
1428 |
* <code>dropLocationForPoint</code>) or <code>null</code> |
|
1429 |
* if there's no longer a valid drop location |
|
1430 |
* @param state the state object saved earlier for this component, |
|
1431 |
* or <code>null</code> |
|
1432 |
* @param forDrop whether or not the method is being called because an |
|
1433 |
* actual drop occurred |
|
1434 |
* @return any saved state for this component, or <code>null</code> if none |
|
1435 |
*/ |
|
1436 |
Object setDropLocation(TransferHandler.DropLocation location, |
|
1437 |
Object state, |
|
1438 |
boolean forDrop) { |
|
1439 |
||
1440 |
Object retVal = null; |
|
1441 |
DropLocation treeLocation = (DropLocation)location; |
|
1442 |
||
1443 |
if (dropMode == DropMode.USE_SELECTION) { |
|
1444 |
if (treeLocation == null) { |
|
1445 |
if (!forDrop && state != null) { |
|
1446 |
setSelectionPaths(((TreePath[][])state)[0]); |
|
1447 |
setAnchorSelectionPath(((TreePath[][])state)[1][0]); |
|
1448 |
setLeadSelectionPath(((TreePath[][])state)[1][1]); |
|
1449 |
} |
|
1450 |
} else { |
|
1451 |
if (dropLocation == null) { |
|
1452 |
TreePath[] paths = getSelectionPaths(); |
|
1453 |
if (paths == null) { |
|
1454 |
paths = new TreePath[0]; |
|
1455 |
} |
|
1456 |
||
1457 |
retVal = new TreePath[][] {paths, |
|
1458 |
{getAnchorSelectionPath(), getLeadSelectionPath()}}; |
|
1459 |
} else { |
|
1460 |
retVal = state; |
|
1461 |
} |
|
1462 |
||
1463 |
setSelectionPath(treeLocation.getPath()); |
|
1464 |
} |
|
1465 |
} |
|
1466 |
||
1467 |
DropLocation old = dropLocation; |
|
1468 |
dropLocation = treeLocation; |
|
1469 |
firePropertyChange("dropLocation", old, dropLocation); |
|
1470 |
||
1471 |
return retVal; |
|
1472 |
} |
|
1473 |
||
1474 |
/** |
|
1475 |
* Called to indicate to this component that DnD is done. |
|
1476 |
* Allows for us to cancel the expand timer. |
|
1477 |
*/ |
|
1478 |
void dndDone() { |
|
1479 |
cancelDropTimer(); |
|
1480 |
dropTimer = null; |
|
1481 |
} |
|
1482 |
||
1483 |
/** |
|
1484 |
* Returns the location that this component should visually indicate |
|
1485 |
* as the drop location during a DnD operation over the component, |
|
1486 |
* or {@code null} if no location is to currently be shown. |
|
1487 |
* <p> |
|
1488 |
* This method is not meant for querying the drop location |
|
1489 |
* from a {@code TransferHandler}, as the drop location is only |
|
1490 |
* set after the {@code TransferHandler}'s <code>canImport</code> |
|
1491 |
* has returned and has allowed for the location to be shown. |
|
1492 |
* <p> |
|
1493 |
* When this property changes, a property change event with |
|
1494 |
* name "dropLocation" is fired by the component. |
|
1495 |
* |
|
1496 |
* @return the drop location |
|
1497 |
* @see #setDropMode |
|
1498 |
* @see TransferHandler#canImport(TransferHandler.TransferSupport) |
|
1499 |
* @since 1.6 |
|
1500 |
*/ |
|
1501 |
public final DropLocation getDropLocation() { |
|
1502 |
return dropLocation; |
|
1503 |
} |
|
1504 |
||
1505 |
private void startDropTimer() { |
|
1506 |
if (dropTimer == null) { |
|
1507 |
dropTimer = new TreeTimer(); |
|
1508 |
} |
|
1509 |
dropTimer.start(); |
|
1510 |
} |
|
1511 |
||
1512 |
private void cancelDropTimer() { |
|
1513 |
if (dropTimer != null && dropTimer.isRunning()) { |
|
1514 |
expandRow = -1; |
|
1515 |
dropTimer.stop(); |
|
1516 |
} |
|
1517 |
} |
|
1518 |
||
1519 |
/** |
|
1520 |
* Returns <code>isEditable</code>. This is invoked from the UI before |
|
1521 |
* editing begins to insure that the given path can be edited. This |
|
1522 |
* is provided as an entry point for subclassers to add filtered |
|
1523 |
* editing without having to resort to creating a new editor. |
|
1524 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
1525 |
* @param path a {@code TreePath} identifying a node |
2 | 1526 |
* @return true if every parent node and the node itself is editable |
1527 |
* @see #isEditable |
|
1528 |
*/ |
|
1529 |
public boolean isPathEditable(TreePath path) { |
|
1530 |
return isEditable(); |
|
1531 |
} |
|
1532 |
||
1533 |
/** |
|
1534 |
* Overrides <code>JComponent</code>'s <code>getToolTipText</code> |
|
1535 |
* method in order to allow |
|
1536 |
* renderer's tips to be used if it has text set. |
|
1537 |
* <p> |
|
1538 |
* NOTE: For <code>JTree</code> to properly display tooltips of its |
|
1539 |
* renderers, <code>JTree</code> must be a registered component with the |
|
1540 |
* <code>ToolTipManager</code>. This can be done by invoking |
|
1541 |
* <code>ToolTipManager.sharedInstance().registerComponent(tree)</code>. |
|
1542 |
* This is not done automatically! |
|
1543 |
* |
|
1544 |
* @param event the <code>MouseEvent</code> that initiated the |
|
1545 |
* <code>ToolTip</code> display |
|
1546 |
* @return a string containing the tooltip or <code>null</code> |
|
1547 |
* if <code>event</code> is null |
|
1548 |
*/ |
|
1549 |
public String getToolTipText(MouseEvent event) { |
|
1550 |
String tip = null; |
|
1551 |
||
1552 |
if(event != null) { |
|
1553 |
Point p = event.getPoint(); |
|
1554 |
int selRow = getRowForLocation(p.x, p.y); |
|
1555 |
TreeCellRenderer r = getCellRenderer(); |
|
1556 |
||
1557 |
if(selRow != -1 && r != null) { |
|
1558 |
TreePath path = getPathForRow(selRow); |
|
1559 |
Object lastPath = path.getLastPathComponent(); |
|
1560 |
Component rComponent = r.getTreeCellRendererComponent |
|
1561 |
(this, lastPath, isRowSelected(selRow), |
|
1562 |
isExpanded(selRow), getModel().isLeaf(lastPath), selRow, |
|
1563 |
true); |
|
1564 |
||
1565 |
if(rComponent instanceof JComponent) { |
|
1566 |
MouseEvent newEvent; |
|
1567 |
Rectangle pathBounds = getPathBounds(path); |
|
1568 |
||
1569 |
p.translate(-pathBounds.x, -pathBounds.y); |
|
1570 |
newEvent = new MouseEvent(rComponent, event.getID(), |
|
1571 |
event.getWhen(), |
|
1572 |
event.getModifiers(), |
|
1573 |
p.x, p.y, |
|
1574 |
event.getXOnScreen(), |
|
1575 |
event.getYOnScreen(), |
|
1576 |
event.getClickCount(), |
|
1577 |
event.isPopupTrigger(), |
|
1578 |
MouseEvent.NOBUTTON); |
|
1579 |
||
1580 |
tip = ((JComponent)rComponent).getToolTipText(newEvent); |
|
1581 |
} |
|
1582 |
} |
|
1583 |
} |
|
1584 |
// No tip from the renderer get our own tip |
|
1585 |
if (tip == null) { |
|
1586 |
tip = getToolTipText(); |
|
1587 |
} |
|
1588 |
return tip; |
|
1589 |
} |
|
1590 |
||
1591 |
/** |
|
1592 |
* Called by the renderers to convert the specified value to |
|
1593 |
* text. This implementation returns <code>value.toString</code>, ignoring |
|
1594 |
* all other arguments. To control the conversion, subclass this |
|
1595 |
* method and use any of the arguments you need. |
|
1596 |
* |
|
1597 |
* @param value the <code>Object</code> to convert to text |
|
1598 |
* @param selected true if the node is selected |
|
1599 |
* @param expanded true if the node is expanded |
|
1600 |
* @param leaf true if the node is a leaf node |
|
1601 |
* @param row an integer specifying the node's display row, where 0 is |
|
1602 |
* the first row in the display |
|
1603 |
* @param hasFocus true if the node has the focus |
|
1604 |
* @return the <code>String</code> representation of the node's value |
|
1605 |
*/ |
|
1606 |
public String convertValueToText(Object value, boolean selected, |
|
1607 |
boolean expanded, boolean leaf, int row, |
|
1608 |
boolean hasFocus) { |
|
1609 |
if(value != null) { |
|
1610 |
String sValue = value.toString(); |
|
1611 |
if (sValue != null) { |
|
1612 |
return sValue; |
|
1613 |
} |
|
1614 |
} |
|
1615 |
return ""; |
|
1616 |
} |
|
1617 |
||
1618 |
// |
|
1619 |
// The following are convenience methods that get forwarded to the |
|
1620 |
// current TreeUI. |
|
1621 |
// |
|
1622 |
||
1623 |
/** |
|
1624 |
* Returns the number of viewable nodes. A node is viewable if all of its |
|
1625 |
* parents are expanded. The root is only included in this count if |
|
1626 |
* {@code isRootVisible()} is {@code true}. This returns {@code 0} if |
|
1627 |
* the UI has not been set. |
|
1628 |
* |
|
1629 |
* @return the number of viewable nodes |
|
1630 |
*/ |
|
1631 |
public int getRowCount() { |
|
1632 |
TreeUI tree = getUI(); |
|
1633 |
||
1634 |
if(tree != null) |
|
1635 |
return tree.getRowCount(this); |
|
1636 |
return 0; |
|
1637 |
} |
|
1638 |
||
1639 |
/** |
|
1640 |
* Selects the node identified by the specified path. If any |
|
1641 |
* component of the path is hidden (under a collapsed node), and |
|
1642 |
* <code>getExpandsSelectedPaths</code> is true it is |
|
1643 |
* exposed (made viewable). |
|
1644 |
* |
|
1645 |
* @param path the <code>TreePath</code> specifying the node to select |
|
1646 |
*/ |
|
1647 |
public void setSelectionPath(TreePath path) { |
|
1648 |
getSelectionModel().setSelectionPath(path); |
|
1649 |
} |
|
1650 |
||
1651 |
/** |
|
1652 |
* Selects the nodes identified by the specified array of paths. |
|
1653 |
* If any component in any of the paths is hidden (under a collapsed |
|
1654 |
* node), and <code>getExpandsSelectedPaths</code> is true |
|
1655 |
* it is exposed (made viewable). |
|
1656 |
* |
|
1657 |
* @param paths an array of <code>TreePath</code> objects that specifies |
|
1658 |
* the nodes to select |
|
1659 |
*/ |
|
1660 |
public void setSelectionPaths(TreePath[] paths) { |
|
1661 |
getSelectionModel().setSelectionPaths(paths); |
|
1662 |
} |
|
1663 |
||
1664 |
/** |
|
1665 |
* Sets the path identifies as the lead. The lead may not be selected. |
|
1666 |
* The lead is not maintained by <code>JTree</code>, |
|
1667 |
* rather the UI will update it. |
|
1668 |
* <p> |
|
1669 |
* This is a bound property. |
|
1670 |
* |
|
1671 |
* @param newPath the new lead path |
|
1672 |
* @since 1.3 |
|
1673 |
* @beaninfo |
|
1674 |
* bound: true |
|
1675 |
* description: Lead selection path |
|
1676 |
*/ |
|
1677 |
public void setLeadSelectionPath(TreePath newPath) { |
|
1678 |
TreePath oldValue = leadPath; |
|
1679 |
||
1680 |
leadPath = newPath; |
|
1681 |
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath); |
|
24187
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1682 |
|
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1683 |
// Fire the active descendant property change here since the |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1684 |
// leadPath got set, this is triggered both in case node |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1685 |
// selection changed and node focus changed |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1686 |
if (accessibleContext != null){ |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1687 |
((AccessibleJTree)accessibleContext). |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1688 |
fireActiveDescendantPropertyChange(oldValue, newPath); |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
1689 |
} |
2 | 1690 |
} |
1691 |
||
1692 |
/** |
|
1693 |
* Sets the path identified as the anchor. |
|
1694 |
* The anchor is not maintained by <code>JTree</code>, rather the UI will |
|
1695 |
* update it. |
|
1696 |
* <p> |
|
1697 |
* This is a bound property. |
|
1698 |
* |
|
1699 |
* @param newPath the new anchor path |
|
1700 |
* @since 1.3 |
|
1701 |
* @beaninfo |
|
1702 |
* bound: true |
|
1703 |
* description: Anchor selection path |
|
1704 |
*/ |
|
1705 |
public void setAnchorSelectionPath(TreePath newPath) { |
|
1706 |
TreePath oldValue = anchorPath; |
|
1707 |
||
1708 |
anchorPath = newPath; |
|
1709 |
firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath); |
|
1710 |
} |
|
1711 |
||
1712 |
/** |
|
1713 |
* Selects the node at the specified row in the display. |
|
1714 |
* |
|
1715 |
* @param row the row to select, where 0 is the first row in |
|
1716 |
* the display |
|
1717 |
*/ |
|
1718 |
public void setSelectionRow(int row) { |
|
1719 |
int[] rows = { row }; |
|
1720 |
||
1721 |
setSelectionRows(rows); |
|
1722 |
} |
|
1723 |
||
1724 |
/** |
|
1725 |
* Selects the nodes corresponding to each of the specified rows |
|
1726 |
* in the display. If a particular element of <code>rows</code> is |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
1727 |
* < 0 or >= <code>getRowCount</code>, it will be ignored. |
2 | 1728 |
* If none of the elements |
1729 |
* in <code>rows</code> are valid rows, the selection will |
|
1730 |
* be cleared. That is it will be as if <code>clearSelection</code> |
|
1731 |
* was invoked. |
|
1732 |
* |
|
1733 |
* @param rows an array of ints specifying the rows to select, |
|
1734 |
* where 0 indicates the first row in the display |
|
1735 |
*/ |
|
1736 |
public void setSelectionRows(int[] rows) { |
|
1737 |
TreeUI ui = getUI(); |
|
1738 |
||
1739 |
if(ui != null && rows != null) { |
|
1740 |
int numRows = rows.length; |
|
1741 |
TreePath[] paths = new TreePath[numRows]; |
|
1742 |
||
1743 |
for(int counter = 0; counter < numRows; counter++) { |
|
1744 |
paths[counter] = ui.getPathForRow(this, rows[counter]); |
|
1745 |
} |
|
1746 |
setSelectionPaths(paths); |
|
1747 |
} |
|
1748 |
} |
|
1749 |
||
1750 |
/** |
|
1751 |
* Adds the node identified by the specified <code>TreePath</code> |
|
1752 |
* to the current selection. If any component of the path isn't |
|
1753 |
* viewable, and <code>getExpandsSelectedPaths</code> is true it is |
|
1754 |
* made viewable. |
|
1755 |
* <p> |
|
1756 |
* Note that <code>JTree</code> does not allow duplicate nodes to |
|
1757 |
* exist as children under the same parent -- each sibling must be |
|
1758 |
* a unique object. |
|
1759 |
* |
|
1760 |
* @param path the <code>TreePath</code> to add |
|
1761 |
*/ |
|
1762 |
public void addSelectionPath(TreePath path) { |
|
1763 |
getSelectionModel().addSelectionPath(path); |
|
1764 |
} |
|
1765 |
||
1766 |
/** |
|
1767 |
* Adds each path in the array of paths to the current selection. If |
|
1768 |
* any component of any of the paths isn't viewable and |
|
1769 |
* <code>getExpandsSelectedPaths</code> is true, it is |
|
1770 |
* made viewable. |
|
1771 |
* <p> |
|
1772 |
* Note that <code>JTree</code> does not allow duplicate nodes to |
|
1773 |
* exist as children under the same parent -- each sibling must be |
|
1774 |
* a unique object. |
|
1775 |
* |
|
1776 |
* @param paths an array of <code>TreePath</code> objects that specifies |
|
1777 |
* the nodes to add |
|
1778 |
*/ |
|
1779 |
public void addSelectionPaths(TreePath[] paths) { |
|
1780 |
getSelectionModel().addSelectionPaths(paths); |
|
1781 |
} |
|
1782 |
||
1783 |
/** |
|
1784 |
* Adds the path at the specified row to the current selection. |
|
1785 |
* |
|
1786 |
* @param row an integer specifying the row of the node to add, |
|
1787 |
* where 0 is the first row in the display |
|
1788 |
*/ |
|
1789 |
public void addSelectionRow(int row) { |
|
1790 |
int[] rows = { row }; |
|
1791 |
||
1792 |
addSelectionRows(rows); |
|
1793 |
} |
|
1794 |
||
1795 |
/** |
|
1796 |
* Adds the paths at each of the specified rows to the current selection. |
|
1797 |
* |
|
1798 |
* @param rows an array of ints specifying the rows to add, |
|
1799 |
* where 0 indicates the first row in the display |
|
1800 |
*/ |
|
1801 |
public void addSelectionRows(int[] rows) { |
|
1802 |
TreeUI ui = getUI(); |
|
1803 |
||
1804 |
if(ui != null && rows != null) { |
|
1805 |
int numRows = rows.length; |
|
1806 |
TreePath[] paths = new TreePath[numRows]; |
|
1807 |
||
1808 |
for(int counter = 0; counter < numRows; counter++) |
|
1809 |
paths[counter] = ui.getPathForRow(this, rows[counter]); |
|
1810 |
addSelectionPaths(paths); |
|
1811 |
} |
|
1812 |
} |
|
1813 |
||
1814 |
/** |
|
1815 |
* Returns the last path component of the selected path. This is |
|
1816 |
* a convenience method for |
|
1817 |
* {@code getSelectionModel().getSelectionPath().getLastPathComponent()}. |
|
1818 |
* This is typically only useful if the selection has one path. |
|
1819 |
* |
|
1820 |
* @return the last path component of the selected path, or |
|
1821 |
* <code>null</code> if nothing is selected |
|
1822 |
* @see TreePath#getLastPathComponent |
|
1823 |
*/ |
|
1824 |
public Object getLastSelectedPathComponent() { |
|
1825 |
TreePath selPath = getSelectionModel().getSelectionPath(); |
|
1826 |
||
1827 |
if(selPath != null) |
|
1828 |
return selPath.getLastPathComponent(); |
|
1829 |
return null; |
|
1830 |
} |
|
1831 |
||
1832 |
/** |
|
1833 |
* Returns the path identified as the lead. |
|
1834 |
* @return path identified as the lead |
|
1835 |
*/ |
|
1836 |
public TreePath getLeadSelectionPath() { |
|
1837 |
return leadPath; |
|
1838 |
} |
|
1839 |
||
1840 |
/** |
|
1841 |
* Returns the path identified as the anchor. |
|
1842 |
* @return path identified as the anchor |
|
1843 |
* @since 1.3 |
|
1844 |
*/ |
|
1845 |
public TreePath getAnchorSelectionPath() { |
|
1846 |
return anchorPath; |
|
1847 |
} |
|
1848 |
||
1849 |
/** |
|
1850 |
* Returns the path to the first selected node. |
|
1851 |
* |
|
1852 |
* @return the <code>TreePath</code> for the first selected node, |
|
1853 |
* or <code>null</code> if nothing is currently selected |
|
1854 |
*/ |
|
1855 |
public TreePath getSelectionPath() { |
|
1856 |
return getSelectionModel().getSelectionPath(); |
|
1857 |
} |
|
1858 |
||
1859 |
/** |
|
1860 |
* Returns the paths of all selected values. |
|
1861 |
* |
|
1862 |
* @return an array of <code>TreePath</code> objects indicating the selected |
|
1863 |
* nodes, or <code>null</code> if nothing is currently selected |
|
1864 |
*/ |
|
1865 |
public TreePath[] getSelectionPaths() { |
|
10878
978071ed312e
7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents:
7668
diff
changeset
|
1866 |
TreePath[] selectionPaths = getSelectionModel().getSelectionPaths(); |
978071ed312e
7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents:
7668
diff
changeset
|
1867 |
|
978071ed312e
7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents:
7668
diff
changeset
|
1868 |
return (selectionPaths != null && selectionPaths.length > 0) ? selectionPaths : null; |
2 | 1869 |
} |
1870 |
||
1871 |
/** |
|
1872 |
* Returns all of the currently selected rows. This method is simply |
|
1873 |
* forwarded to the <code>TreeSelectionModel</code>. |
|
1874 |
* If nothing is selected <code>null</code> or an empty array will |
|
1875 |
* be returned, based on the <code>TreeSelectionModel</code> |
|
1876 |
* implementation. |
|
1877 |
* |
|
1878 |
* @return an array of integers that identifies all currently selected rows |
|
1879 |
* where 0 is the first row in the display |
|
1880 |
*/ |
|
1881 |
public int[] getSelectionRows() { |
|
1882 |
return getSelectionModel().getSelectionRows(); |
|
1883 |
} |
|
1884 |
||
1885 |
/** |
|
1886 |
* Returns the number of nodes selected. |
|
1887 |
* |
|
1888 |
* @return the number of nodes selected |
|
1889 |
*/ |
|
1890 |
public int getSelectionCount() { |
|
1891 |
return selectionModel.getSelectionCount(); |
|
1892 |
} |
|
1893 |
||
1894 |
/** |
|
1895 |
* Returns the smallest selected row. If the selection is empty, or |
|
1896 |
* none of the selected paths are viewable, {@code -1} is returned. |
|
1897 |
* |
|
1898 |
* @return the smallest selected row |
|
1899 |
*/ |
|
1900 |
public int getMinSelectionRow() { |
|
1901 |
return getSelectionModel().getMinSelectionRow(); |
|
1902 |
} |
|
1903 |
||
1904 |
/** |
|
1905 |
* Returns the largest selected row. If the selection is empty, or |
|
1906 |
* none of the selected paths are viewable, {@code -1} is returned. |
|
1907 |
* |
|
1908 |
* @return the largest selected row |
|
1909 |
*/ |
|
1910 |
public int getMaxSelectionRow() { |
|
1911 |
return getSelectionModel().getMaxSelectionRow(); |
|
1912 |
} |
|
1913 |
||
1914 |
/** |
|
1915 |
* Returns the row index corresponding to the lead path. |
|
1916 |
* |
|
1917 |
* @return an integer giving the row index of the lead path, |
|
1918 |
* where 0 is the first row in the display; or -1 |
|
1919 |
* if <code>leadPath</code> is <code>null</code> |
|
1920 |
*/ |
|
1921 |
public int getLeadSelectionRow() { |
|
1922 |
TreePath leadPath = getLeadSelectionPath(); |
|
1923 |
||
1924 |
if (leadPath != null) { |
|
1925 |
return getRowForPath(leadPath); |
|
1926 |
} |
|
1927 |
return -1; |
|
1928 |
} |
|
1929 |
||
1930 |
/** |
|
1931 |
* Returns true if the item identified by the path is currently selected. |
|
1932 |
* |
|
1933 |
* @param path a <code>TreePath</code> identifying a node |
|
1934 |
* @return true if the node is selected |
|
1935 |
*/ |
|
1936 |
public boolean isPathSelected(TreePath path) { |
|
1937 |
return getSelectionModel().isPathSelected(path); |
|
1938 |
} |
|
1939 |
||
1940 |
/** |
|
1941 |
* Returns true if the node identified by row is selected. |
|
1942 |
* |
|
1943 |
* @param row an integer specifying a display row, where 0 is the first |
|
1944 |
* row in the display |
|
1945 |
* @return true if the node is selected |
|
1946 |
*/ |
|
1947 |
public boolean isRowSelected(int row) { |
|
1948 |
return getSelectionModel().isRowSelected(row); |
|
1949 |
} |
|
1950 |
||
1951 |
/** |
|
1952 |
* Returns an <code>Enumeration</code> of the descendants of the |
|
1953 |
* path <code>parent</code> that |
|
1954 |
* are currently expanded. If <code>parent</code> is not currently |
|
1955 |
* expanded, this will return <code>null</code>. |
|
1956 |
* If you expand/collapse nodes while |
|
1957 |
* iterating over the returned <code>Enumeration</code> |
|
1958 |
* this may not return all |
|
1959 |
* the expanded paths, or may return paths that are no longer expanded. |
|
1960 |
* |
|
1961 |
* @param parent the path which is to be examined |
|
1962 |
* @return an <code>Enumeration</code> of the descendents of |
|
1963 |
* <code>parent</code>, or <code>null</code> if |
|
1964 |
* <code>parent</code> is not currently expanded |
|
1965 |
*/ |
|
1966 |
public Enumeration<TreePath> getExpandedDescendants(TreePath parent) { |
|
1967 |
if(!isExpanded(parent)) |
|
1968 |
return null; |
|
1969 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1970 |
Enumeration<TreePath> toggledPaths = expandedState.keys(); |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1971 |
Vector<TreePath> elements = null; |
2 | 1972 |
TreePath path; |
1973 |
Object value; |
|
1974 |
||
1975 |
if(toggledPaths != null) { |
|
1976 |
while(toggledPaths.hasMoreElements()) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1977 |
path = toggledPaths.nextElement(); |
2 | 1978 |
value = expandedState.get(path); |
1979 |
// Add the path if it is expanded, a descendant of parent, |
|
1980 |
// and it is visible (all parents expanded). This is rather |
|
1981 |
// expensive! |
|
1982 |
if(path != parent && value != null && |
|
1983 |
((Boolean)value).booleanValue() && |
|
1984 |
parent.isDescendant(path) && isVisible(path)) { |
|
1985 |
if (elements == null) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
1986 |
elements = new Vector<TreePath>(); |
2 | 1987 |
} |
1988 |
elements.addElement(path); |
|
1989 |
} |
|
1990 |
} |
|
1991 |
} |
|
1992 |
if (elements == null) { |
|
1993 |
Set<TreePath> empty = Collections.emptySet(); |
|
1994 |
return Collections.enumeration(empty); |
|
1995 |
} |
|
1996 |
return elements.elements(); |
|
1997 |
} |
|
1998 |
||
1999 |
/** |
|
2000 |
* Returns true if the node identified by the path has ever been |
|
2001 |
* expanded. |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2002 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2003 |
* @param path a {@code TreePath} identifying a node |
2 | 2004 |
* @return true if the <code>path</code> has ever been expanded |
2005 |
*/ |
|
2006 |
public boolean hasBeenExpanded(TreePath path) { |
|
2007 |
return (path != null && expandedState.get(path) != null); |
|
2008 |
} |
|
2009 |
||
2010 |
/** |
|
2011 |
* Returns true if the node identified by the path is currently expanded, |
|
2012 |
* |
|
2013 |
* @param path the <code>TreePath</code> specifying the node to check |
|
2014 |
* @return false if any of the nodes in the node's path are collapsed, |
|
2015 |
* true if all nodes in the path are expanded |
|
2016 |
*/ |
|
2017 |
public boolean isExpanded(TreePath path) { |
|
5950
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2018 |
|
2 | 2019 |
if(path == null) |
2020 |
return false; |
|
5950
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2021 |
Object value; |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2022 |
|
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2023 |
do{ |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2024 |
value = expandedState.get(path); |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2025 |
if(value == null || !((Boolean)value).booleanValue()) |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2026 |
return false; |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2027 |
} while( (path=path.getParentPath())!=null ); |
4beeac5abfed
6684401: JTree isExpanded should not call itself recursively
alexp
parents:
5506
diff
changeset
|
2028 |
|
2 | 2029 |
return true; |
2030 |
} |
|
2031 |
||
2032 |
/** |
|
2033 |
* Returns true if the node at the specified display row is currently |
|
2034 |
* expanded. |
|
2035 |
* |
|
2036 |
* @param row the row to check, where 0 is the first row in the |
|
2037 |
* display |
|
2038 |
* @return true if the node is currently expanded, otherwise false |
|
2039 |
*/ |
|
2040 |
public boolean isExpanded(int row) { |
|
2041 |
TreeUI tree = getUI(); |
|
2042 |
||
2043 |
if(tree != null) { |
|
2044 |
TreePath path = tree.getPathForRow(this, row); |
|
2045 |
||
2046 |
if(path != null) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
2047 |
Boolean value = expandedState.get(path); |
2 | 2048 |
|
2049 |
return (value != null && value.booleanValue()); |
|
2050 |
} |
|
2051 |
} |
|
2052 |
return false; |
|
2053 |
} |
|
2054 |
||
2055 |
/** |
|
2056 |
* Returns true if the value identified by path is currently collapsed, |
|
2057 |
* this will return false if any of the values in path are currently |
|
2058 |
* not being displayed. |
|
2059 |
* |
|
2060 |
* @param path the <code>TreePath</code> to check |
|
2061 |
* @return true if any of the nodes in the node's path are collapsed, |
|
2062 |
* false if all nodes in the path are expanded |
|
2063 |
*/ |
|
2064 |
public boolean isCollapsed(TreePath path) { |
|
2065 |
return !isExpanded(path); |
|
2066 |
} |
|
2067 |
||
2068 |
/** |
|
2069 |
* Returns true if the node at the specified display row is collapsed. |
|
2070 |
* |
|
2071 |
* @param row the row to check, where 0 is the first row in the |
|
2072 |
* display |
|
2073 |
* @return true if the node is currently collapsed, otherwise false |
|
2074 |
*/ |
|
2075 |
public boolean isCollapsed(int row) { |
|
2076 |
return !isExpanded(row); |
|
2077 |
} |
|
2078 |
||
2079 |
/** |
|
2080 |
* Ensures that the node identified by path is currently viewable. |
|
2081 |
* |
|
2082 |
* @param path the <code>TreePath</code> to make visible |
|
2083 |
*/ |
|
2084 |
public void makeVisible(TreePath path) { |
|
2085 |
if(path != null) { |
|
2086 |
TreePath parentPath = path.getParentPath(); |
|
2087 |
||
2088 |
if(parentPath != null) { |
|
2089 |
expandPath(parentPath); |
|
2090 |
} |
|
2091 |
} |
|
2092 |
} |
|
2093 |
||
2094 |
/** |
|
2095 |
* Returns true if the value identified by path is currently viewable, |
|
2096 |
* which means it is either the root or all of its parents are expanded. |
|
2097 |
* Otherwise, this method returns false. |
|
2098 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2099 |
* @param path {@code TreePath} identifying a node |
2 | 2100 |
* @return true if the node is viewable, otherwise false |
2101 |
*/ |
|
2102 |
public boolean isVisible(TreePath path) { |
|
2103 |
if(path != null) { |
|
2104 |
TreePath parentPath = path.getParentPath(); |
|
2105 |
||
2106 |
if(parentPath != null) |
|
2107 |
return isExpanded(parentPath); |
|
2108 |
// Root. |
|
2109 |
return true; |
|
2110 |
} |
|
2111 |
return false; |
|
2112 |
} |
|
2113 |
||
2114 |
/** |
|
2115 |
* Returns the <code>Rectangle</code> that the specified node will be drawn |
|
2116 |
* into. Returns <code>null</code> if any component in the path is hidden |
|
2117 |
* (under a collapsed parent). |
|
2118 |
* <p> |
|
2119 |
* Note:<br> |
|
2120 |
* This method returns a valid rectangle, even if the specified |
|
2121 |
* node is not currently displayed. |
|
2122 |
* |
|
2123 |
* @param path the <code>TreePath</code> identifying the node |
|
2124 |
* @return the <code>Rectangle</code> the node is drawn in, |
|
2125 |
* or <code>null</code> |
|
2126 |
*/ |
|
2127 |
public Rectangle getPathBounds(TreePath path) { |
|
2128 |
TreeUI tree = getUI(); |
|
2129 |
||
2130 |
if(tree != null) |
|
2131 |
return tree.getPathBounds(this, path); |
|
2132 |
return null; |
|
2133 |
} |
|
2134 |
||
2135 |
/** |
|
2136 |
* Returns the <code>Rectangle</code> that the node at the specified row is |
|
2137 |
* drawn in. |
|
2138 |
* |
|
2139 |
* @param row the row to be drawn, where 0 is the first row in the |
|
2140 |
* display |
|
2141 |
* @return the <code>Rectangle</code> the node is drawn in |
|
2142 |
*/ |
|
2143 |
public Rectangle getRowBounds(int row) { |
|
2144 |
return getPathBounds(getPathForRow(row)); |
|
2145 |
} |
|
2146 |
||
2147 |
/** |
|
2148 |
* Makes sure all the path components in path are expanded (except |
|
2149 |
* for the last path component) and scrolls so that the |
|
2150 |
* node identified by the path is displayed. Only works when this |
|
2151 |
* <code>JTree</code> is contained in a <code>JScrollPane</code>. |
|
2152 |
* |
|
2153 |
* @param path the <code>TreePath</code> identifying the node to |
|
2154 |
* bring into view |
|
2155 |
*/ |
|
2156 |
public void scrollPathToVisible(TreePath path) { |
|
2157 |
if(path != null) { |
|
2158 |
makeVisible(path); |
|
2159 |
||
2160 |
Rectangle bounds = getPathBounds(path); |
|
2161 |
||
2162 |
if(bounds != null) { |
|
2163 |
scrollRectToVisible(bounds); |
|
2164 |
if (accessibleContext != null) { |
|
2165 |
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange(); |
|
2166 |
} |
|
2167 |
} |
|
2168 |
} |
|
2169 |
} |
|
2170 |
||
2171 |
/** |
|
2172 |
* Scrolls the item identified by row until it is displayed. The minimum |
|
2173 |
* of amount of scrolling necessary to bring the row into view |
|
2174 |
* is performed. Only works when this <code>JTree</code> is contained in a |
|
2175 |
* <code>JScrollPane</code>. |
|
2176 |
* |
|
2177 |
* @param row an integer specifying the row to scroll, where 0 is the |
|
2178 |
* first row in the display |
|
2179 |
*/ |
|
2180 |
public void scrollRowToVisible(int row) { |
|
2181 |
scrollPathToVisible(getPathForRow(row)); |
|
2182 |
} |
|
2183 |
||
2184 |
/** |
|
2185 |
* Returns the path for the specified row. If <code>row</code> is |
|
2186 |
* not visible, or a {@code TreeUI} has not been set, <code>null</code> |
|
2187 |
* is returned. |
|
2188 |
* |
|
2189 |
* @param row an integer specifying a row |
|
2190 |
* @return the <code>TreePath</code> to the specified node, |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
2191 |
* <code>null</code> if <code>row < 0</code> |
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
2192 |
* or <code>row >= getRowCount()</code> |
2 | 2193 |
*/ |
2194 |
public TreePath getPathForRow(int row) { |
|
2195 |
TreeUI tree = getUI(); |
|
2196 |
||
2197 |
if(tree != null) |
|
2198 |
return tree.getPathForRow(this, row); |
|
2199 |
return null; |
|
2200 |
} |
|
2201 |
||
2202 |
/** |
|
2203 |
* Returns the row that displays the node identified by the specified |
|
2204 |
* path. |
|
2205 |
* |
|
2206 |
* @param path the <code>TreePath</code> identifying a node |
|
2207 |
* @return an integer specifying the display row, where 0 is the first |
|
2208 |
* row in the display, or -1 if any of the elements in path |
|
2209 |
* are hidden under a collapsed parent. |
|
2210 |
*/ |
|
2211 |
public int getRowForPath(TreePath path) { |
|
2212 |
TreeUI tree = getUI(); |
|
2213 |
||
2214 |
if(tree != null) |
|
2215 |
return tree.getRowForPath(this, path); |
|
2216 |
return -1; |
|
2217 |
} |
|
2218 |
||
2219 |
/** |
|
2220 |
* Ensures that the node identified by the specified path is |
|
2221 |
* expanded and viewable. If the last item in the path is a |
|
2222 |
* leaf, this will have no effect. |
|
2223 |
* |
|
2224 |
* @param path the <code>TreePath</code> identifying a node |
|
2225 |
*/ |
|
2226 |
public void expandPath(TreePath path) { |
|
2227 |
// Only expand if not leaf! |
|
2228 |
TreeModel model = getModel(); |
|
2229 |
||
2230 |
if(path != null && model != null && |
|
2231 |
!model.isLeaf(path.getLastPathComponent())) { |
|
2232 |
setExpandedState(path, true); |
|
2233 |
} |
|
2234 |
} |
|
2235 |
||
2236 |
/** |
|
2237 |
* Ensures that the node in the specified row is expanded and |
|
2238 |
* viewable. |
|
2239 |
* <p> |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
2240 |
* If <code>row</code> is < 0 or >= <code>getRowCount</code> this |
2 | 2241 |
* will have no effect. |
2242 |
* |
|
2243 |
* @param row an integer specifying a display row, where 0 is the |
|
2244 |
* first row in the display |
|
2245 |
*/ |
|
2246 |
public void expandRow(int row) { |
|
2247 |
expandPath(getPathForRow(row)); |
|
2248 |
} |
|
2249 |
||
2250 |
/** |
|
2251 |
* Ensures that the node identified by the specified path is |
|
2252 |
* collapsed and viewable. |
|
2253 |
* |
|
2254 |
* @param path the <code>TreePath</code> identifying a node |
|
2255 |
*/ |
|
2256 |
public void collapsePath(TreePath path) { |
|
2257 |
setExpandedState(path, false); |
|
2258 |
} |
|
2259 |
||
2260 |
/** |
|
2261 |
* Ensures that the node in the specified row is collapsed. |
|
2262 |
* <p> |
|
20157
cafca01a8e28
8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents:
18133
diff
changeset
|
2263 |
* If <code>row</code> is < 0 or >= <code>getRowCount</code> this |
2 | 2264 |
* will have no effect. |
2265 |
* |
|
2266 |
* @param row an integer specifying a display row, where 0 is the |
|
2267 |
* first row in the display |
|
2268 |
*/ |
|
2269 |
public void collapseRow(int row) { |
|
2270 |
collapsePath(getPathForRow(row)); |
|
2271 |
} |
|
2272 |
||
2273 |
/** |
|
2274 |
* Returns the path for the node at the specified location. |
|
2275 |
* |
|
2276 |
* @param x an integer giving the number of pixels horizontally from |
|
2277 |
* the left edge of the display area, minus any left margin |
|
2278 |
* @param y an integer giving the number of pixels vertically from |
|
2279 |
* the top of the display area, minus any top margin |
|
2280 |
* @return the <code>TreePath</code> for the node at that location |
|
2281 |
*/ |
|
2282 |
public TreePath getPathForLocation(int x, int y) { |
|
2283 |
TreePath closestPath = getClosestPathForLocation(x, y); |
|
2284 |
||
2285 |
if(closestPath != null) { |
|
2286 |
Rectangle pathBounds = getPathBounds(closestPath); |
|
2287 |
||
2288 |
if(pathBounds != null && |
|
2289 |
x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) && |
|
2290 |
y >= pathBounds.y && y < (pathBounds.y + pathBounds.height)) |
|
2291 |
return closestPath; |
|
2292 |
} |
|
2293 |
return null; |
|
2294 |
} |
|
2295 |
||
2296 |
/** |
|
2297 |
* Returns the row for the specified location. |
|
2298 |
* |
|
2299 |
* @param x an integer giving the number of pixels horizontally from |
|
2300 |
* the left edge of the display area, minus any left margin |
|
2301 |
* @param y an integer giving the number of pixels vertically from |
|
2302 |
* the top of the display area, minus any top margin |
|
2303 |
* @return the row corresponding to the location, or -1 if the |
|
2304 |
* location is not within the bounds of a displayed cell |
|
2305 |
* @see #getClosestRowForLocation |
|
2306 |
*/ |
|
2307 |
public int getRowForLocation(int x, int y) { |
|
2308 |
return getRowForPath(getPathForLocation(x, y)); |
|
2309 |
} |
|
2310 |
||
2311 |
/** |
|
2312 |
* Returns the path to the node that is closest to x,y. If |
|
2313 |
* no nodes are currently viewable, or there is no model, returns |
|
2314 |
* <code>null</code>, otherwise it always returns a valid path. To test if |
|
2315 |
* the node is exactly at x, y, get the node's bounds and |
|
2316 |
* test x, y against that. |
|
2317 |
* |
|
2318 |
* @param x an integer giving the number of pixels horizontally from |
|
2319 |
* the left edge of the display area, minus any left margin |
|
2320 |
* @param y an integer giving the number of pixels vertically from |
|
2321 |
* the top of the display area, minus any top margin |
|
2322 |
* @return the <code>TreePath</code> for the node closest to that location, |
|
2323 |
* <code>null</code> if nothing is viewable or there is no model |
|
2324 |
* |
|
2325 |
* @see #getPathForLocation |
|
2326 |
* @see #getPathBounds |
|
2327 |
*/ |
|
2328 |
public TreePath getClosestPathForLocation(int x, int y) { |
|
2329 |
TreeUI tree = getUI(); |
|
2330 |
||
2331 |
if(tree != null) |
|
2332 |
return tree.getClosestPathForLocation(this, x, y); |
|
2333 |
return null; |
|
2334 |
} |
|
2335 |
||
2336 |
/** |
|
2337 |
* Returns the row to the node that is closest to x,y. If no nodes |
|
2338 |
* are viewable or there is no model, returns -1. Otherwise, |
|
2339 |
* it always returns a valid row. To test if the returned object is |
|
2340 |
* exactly at x, y, get the bounds for the node at the returned |
|
2341 |
* row and test x, y against that. |
|
2342 |
* |
|
2343 |
* @param x an integer giving the number of pixels horizontally from |
|
2344 |
* the left edge of the display area, minus any left margin |
|
2345 |
* @param y an integer giving the number of pixels vertically from |
|
2346 |
* the top of the display area, minus any top margin |
|
2347 |
* @return the row closest to the location, -1 if nothing is |
|
2348 |
* viewable or there is no model |
|
2349 |
* |
|
2350 |
* @see #getRowForLocation |
|
2351 |
* @see #getRowBounds |
|
2352 |
*/ |
|
2353 |
public int getClosestRowForLocation(int x, int y) { |
|
2354 |
return getRowForPath(getClosestPathForLocation(x, y)); |
|
2355 |
} |
|
2356 |
||
2357 |
/** |
|
2358 |
* Returns true if the tree is being edited. The item that is being |
|
2359 |
* edited can be obtained using <code>getSelectionPath</code>. |
|
2360 |
* |
|
2361 |
* @return true if the user is currently editing a node |
|
2362 |
* @see #getSelectionPath |
|
2363 |
*/ |
|
2364 |
public boolean isEditing() { |
|
2365 |
TreeUI tree = getUI(); |
|
2366 |
||
2367 |
if(tree != null) |
|
2368 |
return tree.isEditing(this); |
|
2369 |
return false; |
|
2370 |
} |
|
2371 |
||
2372 |
/** |
|
2373 |
* Ends the current editing session. |
|
2374 |
* (The <code>DefaultTreeCellEditor</code> |
|
2375 |
* object saves any edits that are currently in progress on a cell. |
|
2376 |
* Other implementations may operate differently.) |
|
2377 |
* Has no effect if the tree isn't being edited. |
|
2378 |
* <blockquote> |
|
2379 |
* <b>Note:</b><br> |
|
2380 |
* To make edit-saves automatic whenever the user changes |
|
2381 |
* their position in the tree, use {@link #setInvokesStopCellEditing}. |
|
2382 |
* </blockquote> |
|
2383 |
* |
|
2384 |
* @return true if editing was in progress and is now stopped, |
|
2385 |
* false if editing was not in progress |
|
2386 |
*/ |
|
2387 |
public boolean stopEditing() { |
|
2388 |
TreeUI tree = getUI(); |
|
2389 |
||
2390 |
if(tree != null) |
|
2391 |
return tree.stopEditing(this); |
|
2392 |
return false; |
|
2393 |
} |
|
2394 |
||
2395 |
/** |
|
2396 |
* Cancels the current editing session. Has no effect if the |
|
2397 |
* tree isn't being edited. |
|
2398 |
*/ |
|
2399 |
public void cancelEditing() { |
|
2400 |
TreeUI tree = getUI(); |
|
2401 |
||
2402 |
if(tree != null) |
|
2403 |
tree.cancelEditing(this); |
|
2404 |
} |
|
2405 |
||
2406 |
/** |
|
2407 |
* Selects the node identified by the specified path and initiates |
|
2408 |
* editing. The edit-attempt fails if the <code>CellEditor</code> |
|
2409 |
* does not allow |
|
2410 |
* editing for the specified item. |
|
2411 |
* |
|
2412 |
* @param path the <code>TreePath</code> identifying a node |
|
2413 |
*/ |
|
2414 |
public void startEditingAtPath(TreePath path) { |
|
2415 |
TreeUI tree = getUI(); |
|
2416 |
||
2417 |
if(tree != null) |
|
2418 |
tree.startEditingAtPath(this, path); |
|
2419 |
} |
|
2420 |
||
2421 |
/** |
|
2422 |
* Returns the path to the element that is currently being edited. |
|
2423 |
* |
|
2424 |
* @return the <code>TreePath</code> for the node being edited |
|
2425 |
*/ |
|
2426 |
public TreePath getEditingPath() { |
|
2427 |
TreeUI tree = getUI(); |
|
2428 |
||
2429 |
if(tree != null) |
|
2430 |
return tree.getEditingPath(this); |
|
2431 |
return null; |
|
2432 |
} |
|
2433 |
||
2434 |
// |
|
2435 |
// Following are primarily convenience methods for mapping from |
|
2436 |
// row based selections to path selections. Sometimes it is |
|
2437 |
// easier to deal with these than paths (mouse downs, key downs |
|
2438 |
// usually just deal with index based selections). |
|
2439 |
// Since row based selections require a UI many of these won't work |
|
2440 |
// without one. |
|
2441 |
// |
|
2442 |
||
2443 |
/** |
|
2444 |
* Sets the tree's selection model. When a <code>null</code> value is |
|
2445 |
* specified an empty |
|
2446 |
* <code>selectionModel</code> is used, which does not allow selections. |
|
2447 |
* <p> |
|
2448 |
* This is a bound property. |
|
2449 |
* |
|
2450 |
* @param selectionModel the <code>TreeSelectionModel</code> to use, |
|
2451 |
* or <code>null</code> to disable selections |
|
2452 |
* @see TreeSelectionModel |
|
2453 |
* @beaninfo |
|
2454 |
* bound: true |
|
2455 |
* description: The tree's selection model. |
|
2456 |
*/ |
|
2457 |
public void setSelectionModel(TreeSelectionModel selectionModel) { |
|
2458 |
if(selectionModel == null) |
|
2459 |
selectionModel = EmptySelectionModel.sharedInstance(); |
|
2460 |
||
2461 |
TreeSelectionModel oldValue = this.selectionModel; |
|
2462 |
||
2463 |
if (this.selectionModel != null && selectionRedirector != null) { |
|
2464 |
this.selectionModel.removeTreeSelectionListener |
|
2465 |
(selectionRedirector); |
|
2466 |
} |
|
2467 |
if (accessibleContext != null) { |
|
2468 |
this.selectionModel.removeTreeSelectionListener((TreeSelectionListener)accessibleContext); |
|
2469 |
selectionModel.addTreeSelectionListener((TreeSelectionListener)accessibleContext); |
|
2470 |
} |
|
2471 |
||
2472 |
this.selectionModel = selectionModel; |
|
2473 |
if (selectionRedirector != null) { |
|
2474 |
this.selectionModel.addTreeSelectionListener(selectionRedirector); |
|
2475 |
} |
|
2476 |
firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, |
|
2477 |
this.selectionModel); |
|
2478 |
||
2479 |
if (accessibleContext != null) { |
|
2480 |
accessibleContext.firePropertyChange( |
|
2481 |
AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, |
|
2482 |
Boolean.valueOf(false), Boolean.valueOf(true)); |
|
2483 |
} |
|
2484 |
} |
|
2485 |
||
2486 |
/** |
|
2487 |
* Returns the model for selections. This should always return a |
|
2488 |
* non-<code>null</code> value. If you don't want to allow anything |
|
2489 |
* to be selected |
|
2490 |
* set the selection model to <code>null</code>, which forces an empty |
|
2491 |
* selection model to be used. |
|
2492 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2493 |
* @return the model for selections |
2 | 2494 |
* @see #setSelectionModel |
2495 |
*/ |
|
2496 |
public TreeSelectionModel getSelectionModel() { |
|
2497 |
return selectionModel; |
|
2498 |
} |
|
2499 |
||
2500 |
/** |
|
2501 |
* Returns the paths (inclusive) between the specified rows. If |
|
2502 |
* the specified indices are within the viewable set of rows, or |
|
2503 |
* bound the viewable set of rows, then the indices are |
|
2504 |
* constrained by the viewable set of rows. If the specified |
|
2505 |
* indices are not within the viewable set of rows, or do not |
|
2506 |
* bound the viewable set of rows, then an empty array is |
|
2507 |
* returned. For example, if the row count is {@code 10}, and this |
|
2508 |
* method is invoked with {@code -1, 20}, then the specified |
|
2509 |
* indices are constrained to the viewable set of rows, and this is |
|
2510 |
* treated as if invoked with {@code 0, 9}. On the other hand, if |
|
2511 |
* this were invoked with {@code -10, -1}, then the specified |
|
2512 |
* indices do not bound the viewable set of rows, and an empty |
|
2513 |
* array is returned. |
|
2514 |
* <p> |
|
2515 |
* The parameters are not order dependent. That is, {@code |
|
2516 |
* getPathBetweenRows(x, y)} is equivalent to |
|
2517 |
* {@code getPathBetweenRows(y, x)}. |
|
2518 |
* <p> |
|
2519 |
* An empty array is returned if the row count is {@code 0}, or |
|
2520 |
* the specified indices do not bound the viewable set of rows. |
|
2521 |
* |
|
2522 |
* @param index0 the first index in the range |
|
2523 |
* @param index1 the last index in the range |
|
2524 |
* @return the paths (inclusive) between the specified row indices |
|
2525 |
*/ |
|
2526 |
protected TreePath[] getPathBetweenRows(int index0, int index1) { |
|
2527 |
TreeUI tree = getUI(); |
|
2528 |
if (tree != null) { |
|
2529 |
int rowCount = getRowCount(); |
|
2530 |
if (rowCount > 0 && !((index0 < 0 && index1 < 0) || |
|
2531 |
(index0 >= rowCount && index1 >= rowCount))){ |
|
2532 |
index0 = Math.min(rowCount - 1, Math.max(index0, 0)); |
|
2533 |
index1 = Math.min(rowCount - 1, Math.max(index1, 0)); |
|
2534 |
int minIndex = Math.min(index0, index1); |
|
2535 |
int maxIndex = Math.max(index0, index1); |
|
2536 |
TreePath[] selection = new TreePath[ |
|
2537 |
maxIndex - minIndex + 1]; |
|
2538 |
for(int counter = minIndex; counter <= maxIndex; counter++) { |
|
2539 |
selection[counter - minIndex] = |
|
2540 |
tree.getPathForRow(this, counter); |
|
2541 |
} |
|
2542 |
return selection; |
|
2543 |
} |
|
2544 |
} |
|
2545 |
return new TreePath[0]; |
|
2546 |
} |
|
2547 |
||
2548 |
/** |
|
2549 |
* Selects the rows in the specified interval (inclusive). If |
|
2550 |
* the specified indices are within the viewable set of rows, or bound |
|
2551 |
* the viewable set of rows, then the specified rows are constrained by |
|
2552 |
* the viewable set of rows. If the specified indices are not within the |
|
2553 |
* viewable set of rows, or do not bound the viewable set of rows, then |
|
2554 |
* the selection is cleared. For example, if the row count is {@code |
|
2555 |
* 10}, and this method is invoked with {@code -1, 20}, then the |
|
2556 |
* specified indices bounds the viewable range, and this is treated as |
|
2557 |
* if invoked with {@code 0, 9}. On the other hand, if this were |
|
2558 |
* invoked with {@code -10, -1}, then the specified indices do not |
|
2559 |
* bound the viewable set of rows, and the selection is cleared. |
|
2560 |
* <p> |
|
2561 |
* The parameters are not order dependent. That is, {@code |
|
2562 |
* setSelectionInterval(x, y)} is equivalent to |
|
2563 |
* {@code setSelectionInterval(y, x)}. |
|
2564 |
* |
|
2565 |
* @param index0 the first index in the range to select |
|
2566 |
* @param index1 the last index in the range to select |
|
2567 |
*/ |
|
2568 |
public void setSelectionInterval(int index0, int index1) { |
|
2569 |
TreePath[] paths = getPathBetweenRows(index0, index1); |
|
2570 |
||
2571 |
this.getSelectionModel().setSelectionPaths(paths); |
|
2572 |
} |
|
2573 |
||
2574 |
/** |
|
2575 |
* Adds the specified rows (inclusive) to the selection. If the |
|
2576 |
* specified indices are within the viewable set of rows, or bound |
|
2577 |
* the viewable set of rows, then the specified indices are |
|
2578 |
* constrained by the viewable set of rows. If the indices are not |
|
2579 |
* within the viewable set of rows, or do not bound the viewable |
|
2580 |
* set of rows, then the selection is unchanged. For example, if |
|
2581 |
* the row count is {@code 10}, and this method is invoked with |
|
2582 |
* {@code -1, 20}, then the specified indices bounds the viewable |
|
2583 |
* range, and this is treated as if invoked with {@code 0, 9}. On |
|
2584 |
* the other hand, if this were invoked with {@code -10, -1}, then |
|
2585 |
* the specified indices do not bound the viewable set of rows, |
|
2586 |
* and the selection is unchanged. |
|
2587 |
* <p> |
|
2588 |
* The parameters are not order dependent. That is, {@code |
|
2589 |
* addSelectionInterval(x, y)} is equivalent to |
|
2590 |
* {@code addSelectionInterval(y, x)}. |
|
2591 |
* |
|
2592 |
* @param index0 the first index in the range to add to the selection |
|
2593 |
* @param index1 the last index in the range to add to the selection |
|
2594 |
*/ |
|
2595 |
public void addSelectionInterval(int index0, int index1) { |
|
2596 |
TreePath[] paths = getPathBetweenRows(index0, index1); |
|
2597 |
||
2598 |
if (paths != null && paths.length > 0) { |
|
2599 |
this.getSelectionModel().addSelectionPaths(paths); |
|
2600 |
} |
|
2601 |
} |
|
2602 |
||
2603 |
/** |
|
2604 |
* Removes the specified rows (inclusive) from the selection. If |
|
2605 |
* the specified indices are within the viewable set of rows, or bound |
|
2606 |
* the viewable set of rows, then the specified indices are constrained by |
|
2607 |
* the viewable set of rows. If the specified indices are not within the |
|
2608 |
* viewable set of rows, or do not bound the viewable set of rows, then |
|
2609 |
* the selection is unchanged. For example, if the row count is {@code |
|
2610 |
* 10}, and this method is invoked with {@code -1, 20}, then the |
|
2611 |
* specified range bounds the viewable range, and this is treated as |
|
2612 |
* if invoked with {@code 0, 9}. On the other hand, if this were |
|
2613 |
* invoked with {@code -10, -1}, then the specified range does not |
|
2614 |
* bound the viewable set of rows, and the selection is unchanged. |
|
2615 |
* <p> |
|
2616 |
* The parameters are not order dependent. That is, {@code |
|
2617 |
* removeSelectionInterval(x, y)} is equivalent to |
|
2618 |
* {@code removeSelectionInterval(y, x)}. |
|
2619 |
* |
|
2620 |
* @param index0 the first row to remove from the selection |
|
2621 |
* @param index1 the last row to remove from the selection |
|
2622 |
*/ |
|
2623 |
public void removeSelectionInterval(int index0, int index1) { |
|
2624 |
TreePath[] paths = getPathBetweenRows(index0, index1); |
|
2625 |
||
2626 |
if (paths != null && paths.length > 0) { |
|
2627 |
this.getSelectionModel().removeSelectionPaths(paths); |
|
2628 |
} |
|
2629 |
} |
|
2630 |
||
2631 |
/** |
|
2632 |
* Removes the node identified by the specified path from the current |
|
2633 |
* selection. |
|
2634 |
* |
|
2635 |
* @param path the <code>TreePath</code> identifying a node |
|
2636 |
*/ |
|
2637 |
public void removeSelectionPath(TreePath path) { |
|
2638 |
this.getSelectionModel().removeSelectionPath(path); |
|
2639 |
} |
|
2640 |
||
2641 |
/** |
|
2642 |
* Removes the nodes identified by the specified paths from the |
|
2643 |
* current selection. |
|
2644 |
* |
|
2645 |
* @param paths an array of <code>TreePath</code> objects that |
|
2646 |
* specifies the nodes to remove |
|
2647 |
*/ |
|
2648 |
public void removeSelectionPaths(TreePath[] paths) { |
|
2649 |
this.getSelectionModel().removeSelectionPaths(paths); |
|
2650 |
} |
|
2651 |
||
2652 |
/** |
|
2653 |
* Removes the row at the index <code>row</code> from the current |
|
2654 |
* selection. |
|
2655 |
* |
|
2656 |
* @param row the row to remove |
|
2657 |
*/ |
|
2658 |
public void removeSelectionRow(int row) { |
|
2659 |
int[] rows = { row }; |
|
2660 |
||
2661 |
removeSelectionRows(rows); |
|
2662 |
} |
|
2663 |
||
2664 |
/** |
|
2665 |
* Removes the rows that are selected at each of the specified |
|
2666 |
* rows. |
|
2667 |
* |
|
2668 |
* @param rows an array of ints specifying display rows, where 0 is |
|
2669 |
* the first row in the display |
|
2670 |
*/ |
|
2671 |
public void removeSelectionRows(int[] rows) { |
|
2672 |
TreeUI ui = getUI(); |
|
2673 |
||
2674 |
if(ui != null && rows != null) { |
|
2675 |
int numRows = rows.length; |
|
2676 |
TreePath[] paths = new TreePath[numRows]; |
|
2677 |
||
2678 |
for(int counter = 0; counter < numRows; counter++) |
|
2679 |
paths[counter] = ui.getPathForRow(this, rows[counter]); |
|
2680 |
removeSelectionPaths(paths); |
|
2681 |
} |
|
2682 |
} |
|
2683 |
||
2684 |
/** |
|
2685 |
* Clears the selection. |
|
2686 |
*/ |
|
2687 |
public void clearSelection() { |
|
2688 |
getSelectionModel().clearSelection(); |
|
2689 |
} |
|
2690 |
||
2691 |
/** |
|
2692 |
* Returns true if the selection is currently empty. |
|
2693 |
* |
|
2694 |
* @return true if the selection is currently empty |
|
2695 |
*/ |
|
2696 |
public boolean isSelectionEmpty() { |
|
2697 |
return getSelectionModel().isSelectionEmpty(); |
|
2698 |
} |
|
2699 |
||
2700 |
/** |
|
2701 |
* Adds a listener for <code>TreeExpansion</code> events. |
|
2702 |
* |
|
2703 |
* @param tel a TreeExpansionListener that will be notified when |
|
2704 |
* a tree node is expanded or collapsed (a "negative |
|
2705 |
* expansion") |
|
2706 |
*/ |
|
2707 |
public void addTreeExpansionListener(TreeExpansionListener tel) { |
|
2708 |
if (settingUI) { |
|
2709 |
uiTreeExpansionListener = tel; |
|
2710 |
} |
|
2711 |
listenerList.add(TreeExpansionListener.class, tel); |
|
2712 |
} |
|
2713 |
||
2714 |
/** |
|
2715 |
* Removes a listener for <code>TreeExpansion</code> events. |
|
2716 |
* |
|
2717 |
* @param tel the <code>TreeExpansionListener</code> to remove |
|
2718 |
*/ |
|
2719 |
public void removeTreeExpansionListener(TreeExpansionListener tel) { |
|
2720 |
listenerList.remove(TreeExpansionListener.class, tel); |
|
2721 |
if (uiTreeExpansionListener == tel) { |
|
2722 |
uiTreeExpansionListener = null; |
|
2723 |
} |
|
2724 |
} |
|
2725 |
||
2726 |
/** |
|
2727 |
* Returns an array of all the <code>TreeExpansionListener</code>s added |
|
2728 |
* to this JTree with addTreeExpansionListener(). |
|
2729 |
* |
|
2730 |
* @return all of the <code>TreeExpansionListener</code>s added or an empty |
|
2731 |
* array if no listeners have been added |
|
2732 |
* @since 1.4 |
|
2733 |
*/ |
|
2734 |
public TreeExpansionListener[] getTreeExpansionListeners() { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
2735 |
return listenerList.getListeners(TreeExpansionListener.class); |
2 | 2736 |
} |
2737 |
||
2738 |
/** |
|
2739 |
* Adds a listener for <code>TreeWillExpand</code> events. |
|
2740 |
* |
|
2741 |
* @param tel a <code>TreeWillExpandListener</code> that will be notified |
|
2742 |
* when a tree node will be expanded or collapsed (a "negative |
|
2743 |
* expansion") |
|
2744 |
*/ |
|
2745 |
public void addTreeWillExpandListener(TreeWillExpandListener tel) { |
|
2746 |
listenerList.add(TreeWillExpandListener.class, tel); |
|
2747 |
} |
|
2748 |
||
2749 |
/** |
|
2750 |
* Removes a listener for <code>TreeWillExpand</code> events. |
|
2751 |
* |
|
2752 |
* @param tel the <code>TreeWillExpandListener</code> to remove |
|
2753 |
*/ |
|
2754 |
public void removeTreeWillExpandListener(TreeWillExpandListener tel) { |
|
2755 |
listenerList.remove(TreeWillExpandListener.class, tel); |
|
2756 |
} |
|
2757 |
||
2758 |
/** |
|
2759 |
* Returns an array of all the <code>TreeWillExpandListener</code>s added |
|
2760 |
* to this JTree with addTreeWillExpandListener(). |
|
2761 |
* |
|
2762 |
* @return all of the <code>TreeWillExpandListener</code>s added or an empty |
|
2763 |
* array if no listeners have been added |
|
2764 |
* @since 1.4 |
|
2765 |
*/ |
|
2766 |
public TreeWillExpandListener[] getTreeWillExpandListeners() { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
2767 |
return listenerList.getListeners(TreeWillExpandListener.class); |
2 | 2768 |
} |
2769 |
||
2770 |
/** |
|
2771 |
* Notifies all listeners that have registered interest for |
|
2772 |
* notification on this event type. The event instance |
|
2773 |
* is lazily created using the <code>path</code> parameter. |
|
2774 |
* |
|
2775 |
* @param path the <code>TreePath</code> indicating the node that was |
|
2776 |
* expanded |
|
2777 |
* @see EventListenerList |
|
2778 |
*/ |
|
2779 |
public void fireTreeExpanded(TreePath path) { |
|
2780 |
// Guaranteed to return a non-null array |
|
2781 |
Object[] listeners = listenerList.getListenerList(); |
|
2782 |
TreeExpansionEvent e = null; |
|
2783 |
if (uiTreeExpansionListener != null) { |
|
2784 |
e = new TreeExpansionEvent(this, path); |
|
2785 |
uiTreeExpansionListener.treeExpanded(e); |
|
2786 |
} |
|
2787 |
// Process the listeners last to first, notifying |
|
2788 |
// those that are interested in this event |
|
2789 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
2790 |
if (listeners[i]==TreeExpansionListener.class && |
|
2791 |
listeners[i + 1] != uiTreeExpansionListener) { |
|
2792 |
// Lazily create the event: |
|
2793 |
if (e == null) |
|
2794 |
e = new TreeExpansionEvent(this, path); |
|
2795 |
((TreeExpansionListener)listeners[i+1]). |
|
2796 |
treeExpanded(e); |
|
2797 |
} |
|
2798 |
} |
|
2799 |
} |
|
2800 |
||
2801 |
/** |
|
2802 |
* Notifies all listeners that have registered interest for |
|
2803 |
* notification on this event type. The event instance |
|
2804 |
* is lazily created using the <code>path</code> parameter. |
|
2805 |
* |
|
2806 |
* @param path the <code>TreePath</code> indicating the node that was |
|
2807 |
* collapsed |
|
2808 |
* @see EventListenerList |
|
2809 |
*/ |
|
2810 |
public void fireTreeCollapsed(TreePath path) { |
|
2811 |
// Guaranteed to return a non-null array |
|
2812 |
Object[] listeners = listenerList.getListenerList(); |
|
2813 |
TreeExpansionEvent e = null; |
|
2814 |
if (uiTreeExpansionListener != null) { |
|
2815 |
e = new TreeExpansionEvent(this, path); |
|
2816 |
uiTreeExpansionListener.treeCollapsed(e); |
|
2817 |
} |
|
2818 |
// Process the listeners last to first, notifying |
|
2819 |
// those that are interested in this event |
|
2820 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
2821 |
if (listeners[i]==TreeExpansionListener.class && |
|
2822 |
listeners[i + 1] != uiTreeExpansionListener) { |
|
2823 |
// Lazily create the event: |
|
2824 |
if (e == null) |
|
2825 |
e = new TreeExpansionEvent(this, path); |
|
2826 |
((TreeExpansionListener)listeners[i+1]). |
|
2827 |
treeCollapsed(e); |
|
2828 |
} |
|
2829 |
} |
|
2830 |
} |
|
2831 |
||
2832 |
/** |
|
2833 |
* Notifies all listeners that have registered interest for |
|
2834 |
* notification on this event type. The event instance |
|
2835 |
* is lazily created using the <code>path</code> parameter. |
|
2836 |
* |
|
2837 |
* @param path the <code>TreePath</code> indicating the node that was |
|
2838 |
* expanded |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2839 |
* @throws ExpandVetoException if the expansion is prevented from occurring |
2 | 2840 |
* @see EventListenerList |
2841 |
*/ |
|
2842 |
public void fireTreeWillExpand(TreePath path) throws ExpandVetoException { |
|
2843 |
// Guaranteed to return a non-null array |
|
2844 |
Object[] listeners = listenerList.getListenerList(); |
|
2845 |
TreeExpansionEvent e = null; |
|
2846 |
// Process the listeners last to first, notifying |
|
2847 |
// those that are interested in this event |
|
2848 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
2849 |
if (listeners[i]==TreeWillExpandListener.class) { |
|
2850 |
// Lazily create the event: |
|
2851 |
if (e == null) |
|
2852 |
e = new TreeExpansionEvent(this, path); |
|
2853 |
((TreeWillExpandListener)listeners[i+1]). |
|
2854 |
treeWillExpand(e); |
|
2855 |
} |
|
2856 |
} |
|
2857 |
} |
|
2858 |
||
2859 |
/** |
|
2860 |
* Notifies all listeners that have registered interest for |
|
2861 |
* notification on this event type. The event instance |
|
2862 |
* is lazily created using the <code>path</code> parameter. |
|
2863 |
* |
|
2864 |
* @param path the <code>TreePath</code> indicating the node that was |
|
2865 |
* expanded |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
2866 |
* @throws ExpandVetoException if the collapse is prevented from occurring |
2 | 2867 |
* @see EventListenerList |
2868 |
*/ |
|
2869 |
public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException { |
|
2870 |
// Guaranteed to return a non-null array |
|
2871 |
Object[] listeners = listenerList.getListenerList(); |
|
2872 |
TreeExpansionEvent e = null; |
|
2873 |
// Process the listeners last to first, notifying |
|
2874 |
// those that are interested in this event |
|
2875 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
2876 |
if (listeners[i]==TreeWillExpandListener.class) { |
|
2877 |
// Lazily create the event: |
|
2878 |
if (e == null) |
|
2879 |
e = new TreeExpansionEvent(this, path); |
|
2880 |
((TreeWillExpandListener)listeners[i+1]). |
|
2881 |
treeWillCollapse(e); |
|
2882 |
} |
|
2883 |
} |
|
2884 |
} |
|
2885 |
||
2886 |
/** |
|
2887 |
* Adds a listener for <code>TreeSelection</code> events. |
|
2888 |
* |
|
2889 |
* @param tsl the <code>TreeSelectionListener</code> that will be notified |
|
2890 |
* when a node is selected or deselected (a "negative |
|
2891 |
* selection") |
|
2892 |
*/ |
|
2893 |
public void addTreeSelectionListener(TreeSelectionListener tsl) { |
|
2894 |
listenerList.add(TreeSelectionListener.class,tsl); |
|
2895 |
if(listenerList.getListenerCount(TreeSelectionListener.class) != 0 |
|
2896 |
&& selectionRedirector == null) { |
|
2897 |
selectionRedirector = new TreeSelectionRedirector(); |
|
2898 |
selectionModel.addTreeSelectionListener(selectionRedirector); |
|
2899 |
} |
|
2900 |
} |
|
2901 |
||
2902 |
/** |
|
2903 |
* Removes a <code>TreeSelection</code> listener. |
|
2904 |
* |
|
2905 |
* @param tsl the <code>TreeSelectionListener</code> to remove |
|
2906 |
*/ |
|
2907 |
public void removeTreeSelectionListener(TreeSelectionListener tsl) { |
|
2908 |
listenerList.remove(TreeSelectionListener.class,tsl); |
|
2909 |
if(listenerList.getListenerCount(TreeSelectionListener.class) == 0 |
|
2910 |
&& selectionRedirector != null) { |
|
2911 |
selectionModel.removeTreeSelectionListener |
|
2912 |
(selectionRedirector); |
|
2913 |
selectionRedirector = null; |
|
2914 |
} |
|
2915 |
} |
|
2916 |
||
2917 |
/** |
|
2918 |
* Returns an array of all the <code>TreeSelectionListener</code>s added |
|
2919 |
* to this JTree with addTreeSelectionListener(). |
|
2920 |
* |
|
2921 |
* @return all of the <code>TreeSelectionListener</code>s added or an empty |
|
2922 |
* array if no listeners have been added |
|
2923 |
* @since 1.4 |
|
2924 |
*/ |
|
2925 |
public TreeSelectionListener[] getTreeSelectionListeners() { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
2926 |
return listenerList.getListeners(TreeSelectionListener.class); |
2 | 2927 |
} |
2928 |
||
2929 |
/** |
|
2930 |
* Notifies all listeners that have registered interest for |
|
2931 |
* notification on this event type. |
|
2932 |
* |
|
2933 |
* @param e the <code>TreeSelectionEvent</code> to be fired; |
|
2934 |
* generated by the |
|
2935 |
* <code>TreeSelectionModel</code> |
|
2936 |
* when a node is selected or deselected |
|
2937 |
* @see EventListenerList |
|
2938 |
*/ |
|
2939 |
protected void fireValueChanged(TreeSelectionEvent e) { |
|
2940 |
// Guaranteed to return a non-null array |
|
2941 |
Object[] listeners = listenerList.getListenerList(); |
|
2942 |
// Process the listeners last to first, notifying |
|
2943 |
// those that are interested in this event |
|
2944 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
2945 |
// TreeSelectionEvent e = null; |
|
2946 |
if (listeners[i]==TreeSelectionListener.class) { |
|
2947 |
// Lazily create the event: |
|
2948 |
// if (e == null) |
|
2949 |
// e = new ListSelectionEvent(this, firstIndex, lastIndex); |
|
2950 |
((TreeSelectionListener)listeners[i+1]).valueChanged(e); |
|
2951 |
} |
|
2952 |
} |
|
2953 |
} |
|
2954 |
||
2955 |
/** |
|
2956 |
* Sent when the tree has changed enough that we need to resize |
|
2957 |
* the bounds, but not enough that we need to remove the |
|
2958 |
* expanded node set (e.g nodes were expanded or collapsed, or |
|
2959 |
* nodes were inserted into the tree). You should never have to |
|
2960 |
* invoke this, the UI will invoke this as it needs to. |
|
2961 |
*/ |
|
2962 |
public void treeDidChange() { |
|
2963 |
revalidate(); |
|
2964 |
repaint(); |
|
2965 |
} |
|
2966 |
||
2967 |
/** |
|
2968 |
* Sets the number of rows that are to be displayed. |
|
2969 |
* This will only work if the tree is contained in a |
|
2970 |
* <code>JScrollPane</code>, |
|
2971 |
* and will adjust the preferred size and size of that scrollpane. |
|
2972 |
* <p> |
|
2973 |
* This is a bound property. |
|
2974 |
* |
|
2975 |
* @param newCount the number of rows to display |
|
2976 |
* @beaninfo |
|
2977 |
* bound: true |
|
2978 |
* description: The number of rows that are to be displayed. |
|
2979 |
*/ |
|
2980 |
public void setVisibleRowCount(int newCount) { |
|
2981 |
int oldCount = visibleRowCount; |
|
2982 |
||
2983 |
visibleRowCount = newCount; |
|
2984 |
firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount, |
|
2985 |
visibleRowCount); |
|
2986 |
invalidate(); |
|
2987 |
if (accessibleContext != null) { |
|
2988 |
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange(); |
|
2989 |
} |
|
2990 |
} |
|
2991 |
||
2992 |
/** |
|
2993 |
* Returns the number of rows that are displayed in the display area. |
|
2994 |
* |
|
2995 |
* @return the number of rows displayed |
|
2996 |
*/ |
|
2997 |
public int getVisibleRowCount() { |
|
2998 |
return visibleRowCount; |
|
2999 |
} |
|
3000 |
||
3001 |
/** |
|
3002 |
* Expands the root path, assuming the current TreeModel has been set. |
|
3003 |
*/ |
|
3004 |
private void expandRoot() { |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3005 |
TreeModel model = getModel(); |
2 | 3006 |
if(model != null && model.getRoot() != null) { |
3007 |
expandPath(new TreePath(model.getRoot())); |
|
3008 |
} |
|
3009 |
} |
|
3010 |
||
3011 |
/** |
|
3012 |
* Returns the TreePath to the next tree element that |
|
3013 |
* begins with a prefix. To handle the conversion of a |
|
3014 |
* <code>TreePath</code> into a String, <code>convertValueToText</code> |
|
3015 |
* is used. |
|
3016 |
* |
|
3017 |
* @param prefix the string to test for a match |
|
3018 |
* @param startingRow the row for starting the search |
|
3019 |
* @param bias the search direction, either |
|
3020 |
* Position.Bias.Forward or Position.Bias.Backward. |
|
3021 |
* @return the TreePath of the next tree element that |
|
3022 |
* starts with the prefix; otherwise null |
|
3023 |
* @exception IllegalArgumentException if prefix is null |
|
3024 |
* or startingRow is out of bounds |
|
3025 |
* @since 1.4 |
|
3026 |
*/ |
|
3027 |
public TreePath getNextMatch(String prefix, int startingRow, |
|
3028 |
Position.Bias bias) { |
|
3029 |
||
3030 |
int max = getRowCount(); |
|
3031 |
if (prefix == null) { |
|
3032 |
throw new IllegalArgumentException(); |
|
3033 |
} |
|
3034 |
if (startingRow < 0 || startingRow >= max) { |
|
3035 |
throw new IllegalArgumentException(); |
|
3036 |
} |
|
3037 |
prefix = prefix.toUpperCase(); |
|
3038 |
||
3039 |
// start search from the next/previous element froom the |
|
3040 |
// selected element |
|
3041 |
int increment = (bias == Position.Bias.Forward) ? 1 : -1; |
|
3042 |
int row = startingRow; |
|
3043 |
do { |
|
3044 |
TreePath path = getPathForRow(row); |
|
3045 |
String text = convertValueToText( |
|
3046 |
path.getLastPathComponent(), isRowSelected(row), |
|
3047 |
isExpanded(row), true, row, false); |
|
3048 |
||
3049 |
if (text.toUpperCase().startsWith(prefix)) { |
|
3050 |
return path; |
|
3051 |
} |
|
3052 |
row = (row + increment + max) % max; |
|
3053 |
} while (row != startingRow); |
|
3054 |
return null; |
|
3055 |
} |
|
3056 |
||
3057 |
// Serialization support. |
|
3058 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3059 |
Vector<Object> values = new Vector<Object>(); |
2 | 3060 |
|
3061 |
s.defaultWriteObject(); |
|
3062 |
// Save the cellRenderer, if its Serializable. |
|
3063 |
if(cellRenderer != null && cellRenderer instanceof Serializable) { |
|
3064 |
values.addElement("cellRenderer"); |
|
3065 |
values.addElement(cellRenderer); |
|
3066 |
} |
|
3067 |
// Save the cellEditor, if its Serializable. |
|
3068 |
if(cellEditor != null && cellEditor instanceof Serializable) { |
|
3069 |
values.addElement("cellEditor"); |
|
3070 |
values.addElement(cellEditor); |
|
3071 |
} |
|
3072 |
// Save the treeModel, if its Serializable. |
|
3073 |
if(treeModel != null && treeModel instanceof Serializable) { |
|
3074 |
values.addElement("treeModel"); |
|
3075 |
values.addElement(treeModel); |
|
3076 |
} |
|
3077 |
// Save the selectionModel, if its Serializable. |
|
3078 |
if(selectionModel != null && selectionModel instanceof Serializable) { |
|
3079 |
values.addElement("selectionModel"); |
|
3080 |
values.addElement(selectionModel); |
|
3081 |
} |
|
3082 |
||
3083 |
Object expandedData = getArchivableExpandedState(); |
|
3084 |
||
3085 |
if(expandedData != null) { |
|
3086 |
values.addElement("expandedState"); |
|
3087 |
values.addElement(expandedData); |
|
3088 |
} |
|
3089 |
||
3090 |
s.writeObject(values); |
|
3091 |
if (getUIClassID().equals(uiClassID)) { |
|
3092 |
byte count = JComponent.getWriteObjCounter(this); |
|
3093 |
JComponent.setWriteObjCounter(this, --count); |
|
3094 |
if (count == 0 && ui != null) { |
|
3095 |
ui.installUI(this); |
|
3096 |
} |
|
3097 |
} |
|
3098 |
} |
|
3099 |
||
3100 |
private void readObject(ObjectInputStream s) |
|
3101 |
throws IOException, ClassNotFoundException { |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3102 |
ObjectInputStream.GetField f = s.readFields(); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3103 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3104 |
rootVisible = f.get("rootVisible", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3105 |
rowHeight = f.get("rowHeight", 0); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3106 |
rowHeightSet = f.get("rowHeightSet", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3107 |
showsRootHandles = f.get("showsRootHandles", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3108 |
showsRootHandlesSet = f.get("showsRootHandlesSet", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3109 |
editable = f.get("editable", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3110 |
largeModel = f.get("largeModel", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3111 |
visibleRowCount = f.get("visibleRowCount", 0); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3112 |
invokesStopCellEditing = f.get("invokesStopCellEditing", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3113 |
scrollsOnExpand = f.get("scrollsOnExpand", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3114 |
scrollsOnExpandSet = f.get("scrollsOnExpandSet", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3115 |
toggleClickCount = f.get("toggleClickCount", 0); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3116 |
leadPath = (TreePath) f.get("leadPath", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3117 |
anchorPath = (TreePath) f.get("anchorPath", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3118 |
expandsSelectedPaths = f.get("expandsSelectedPaths", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3119 |
settingUI = f.get("settingUI", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3120 |
boolean newDragEnabled = f.get("dragEnabled", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3121 |
checkDragEnabled(newDragEnabled); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3122 |
dragEnabled = newDragEnabled; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3123 |
DropMode newDropMode = (DropMode) f.get("dropMode", |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3124 |
DropMode.USE_SELECTION); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3125 |
checkDropMode(newDropMode); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3126 |
dropMode = newDropMode; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3127 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3128 |
expandRow = f.get("expandRow", -1); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
3129 |
dropTimer = (TreeTimer) f.get("dropTimer", null); |
2 | 3130 |
|
3131 |
// Create an instance of expanded state. |
|
3132 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3133 |
expandedState = new Hashtable<TreePath, Boolean>(); |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3134 |
|
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3135 |
expandedStack = new Stack<Stack<TreePath>>(); |
2 | 3136 |
|
11268 | 3137 |
Vector<?> values = (Vector)s.readObject(); |
2 | 3138 |
int indexCounter = 0; |
3139 |
int maxCounter = values.size(); |
|
3140 |
||
3141 |
if(indexCounter < maxCounter && values.elementAt(indexCounter). |
|
3142 |
equals("cellRenderer")) { |
|
3143 |
cellRenderer = (TreeCellRenderer)values.elementAt(++indexCounter); |
|
3144 |
indexCounter++; |
|
3145 |
} |
|
3146 |
if(indexCounter < maxCounter && values.elementAt(indexCounter). |
|
3147 |
equals("cellEditor")) { |
|
3148 |
cellEditor = (TreeCellEditor)values.elementAt(++indexCounter); |
|
3149 |
indexCounter++; |
|
3150 |
} |
|
3151 |
if(indexCounter < maxCounter && values.elementAt(indexCounter). |
|
3152 |
equals("treeModel")) { |
|
3153 |
treeModel = (TreeModel)values.elementAt(++indexCounter); |
|
3154 |
indexCounter++; |
|
3155 |
} |
|
3156 |
if(indexCounter < maxCounter && values.elementAt(indexCounter). |
|
3157 |
equals("selectionModel")) { |
|
3158 |
selectionModel = (TreeSelectionModel)values.elementAt(++indexCounter); |
|
3159 |
indexCounter++; |
|
3160 |
} |
|
3161 |
if(indexCounter < maxCounter && values.elementAt(indexCounter). |
|
3162 |
equals("expandedState")) { |
|
3163 |
unarchiveExpandedState(values.elementAt(++indexCounter)); |
|
3164 |
indexCounter++; |
|
3165 |
} |
|
3166 |
// Reinstall the redirector. |
|
3167 |
if(listenerList.getListenerCount(TreeSelectionListener.class) != 0) { |
|
3168 |
selectionRedirector = new TreeSelectionRedirector(); |
|
3169 |
selectionModel.addTreeSelectionListener(selectionRedirector); |
|
3170 |
} |
|
3171 |
// Listener to TreeModel. |
|
3172 |
if(treeModel != null) { |
|
3173 |
treeModelListener = createTreeModelListener(); |
|
3174 |
if(treeModelListener != null) |
|
3175 |
treeModel.addTreeModelListener(treeModelListener); |
|
3176 |
} |
|
3177 |
} |
|
3178 |
||
3179 |
/** |
|
3180 |
* Returns an object that can be archived indicating what nodes are |
|
3181 |
* expanded and what aren't. The objects from the model are NOT |
|
3182 |
* written out. |
|
3183 |
*/ |
|
3184 |
private Object getArchivableExpandedState() { |
|
3185 |
TreeModel model = getModel(); |
|
3186 |
||
3187 |
if(model != null) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3188 |
Enumeration<TreePath> paths = expandedState.keys(); |
2 | 3189 |
|
3190 |
if(paths != null) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3191 |
Vector<Object> state = new Vector<Object>(); |
2 | 3192 |
|
3193 |
while(paths.hasMoreElements()) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3194 |
TreePath path = paths.nextElement(); |
2 | 3195 |
Object archivePath; |
3196 |
||
3197 |
try { |
|
3198 |
archivePath = getModelIndexsForPath(path); |
|
3199 |
} catch (Error error) { |
|
3200 |
archivePath = null; |
|
3201 |
} |
|
3202 |
if(archivePath != null) { |
|
3203 |
state.addElement(archivePath); |
|
3204 |
state.addElement(expandedState.get(path)); |
|
3205 |
} |
|
3206 |
} |
|
3207 |
return state; |
|
3208 |
} |
|
3209 |
} |
|
3210 |
return null; |
|
3211 |
} |
|
3212 |
||
3213 |
/** |
|
3214 |
* Updates the expanded state of nodes in the tree based on the |
|
3215 |
* previously archived state <code>state</code>. |
|
3216 |
*/ |
|
3217 |
private void unarchiveExpandedState(Object state) { |
|
3218 |
if(state instanceof Vector) { |
|
11268 | 3219 |
Vector<?> paths = (Vector)state; |
2 | 3220 |
|
3221 |
for(int counter = paths.size() - 1; counter >= 0; counter--) { |
|
3222 |
Boolean eState = (Boolean)paths.elementAt(counter--); |
|
3223 |
TreePath path; |
|
3224 |
||
3225 |
try { |
|
3226 |
path = getPathForIndexs((int[])paths.elementAt(counter)); |
|
3227 |
if(path != null) |
|
3228 |
expandedState.put(path, eState); |
|
3229 |
} catch (Error error) {} |
|
3230 |
} |
|
3231 |
} |
|
3232 |
} |
|
3233 |
||
3234 |
/** |
|
3235 |
* Returns an array of integers specifying the indexs of the |
|
3236 |
* components in the <code>path</code>. If <code>path</code> is |
|
3237 |
* the root, this will return an empty array. If <code>path</code> |
|
3238 |
* is <code>null</code>, <code>null</code> will be returned. |
|
3239 |
*/ |
|
3240 |
private int[] getModelIndexsForPath(TreePath path) { |
|
3241 |
if(path != null) { |
|
3242 |
TreeModel model = getModel(); |
|
3243 |
int count = path.getPathCount(); |
|
3244 |
int[] indexs = new int[count - 1]; |
|
3245 |
Object parent = model.getRoot(); |
|
3246 |
||
3247 |
for(int counter = 1; counter < count; counter++) { |
|
3248 |
indexs[counter - 1] = model.getIndexOfChild |
|
3249 |
(parent, path.getPathComponent(counter)); |
|
3250 |
parent = path.getPathComponent(counter); |
|
3251 |
if(indexs[counter - 1] < 0) |
|
3252 |
return null; |
|
3253 |
} |
|
3254 |
return indexs; |
|
3255 |
} |
|
3256 |
return null; |
|
3257 |
} |
|
3258 |
||
3259 |
/** |
|
3260 |
* Returns a <code>TreePath</code> created by obtaining the children |
|
3261 |
* for each of the indices in <code>indexs</code>. If <code>indexs</code> |
|
3262 |
* or the <code>TreeModel</code> is <code>null</code>, it will return |
|
3263 |
* <code>null</code>. |
|
3264 |
*/ |
|
3265 |
private TreePath getPathForIndexs(int[] indexs) { |
|
3266 |
if(indexs == null) |
|
3267 |
return null; |
|
3268 |
||
3269 |
TreeModel model = getModel(); |
|
3270 |
||
3271 |
if(model == null) |
|
3272 |
return null; |
|
3273 |
||
3274 |
int count = indexs.length; |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3275 |
|
2 | 3276 |
Object parent = model.getRoot(); |
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3277 |
if (parent == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3278 |
return null; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3279 |
|
2 | 3280 |
TreePath parentPath = new TreePath(parent); |
3281 |
for(int counter = 0; counter < count; counter++) { |
|
3282 |
parent = model.getChild(parent, indexs[counter]); |
|
3283 |
if(parent == null) |
|
3284 |
return null; |
|
3285 |
parentPath = parentPath.pathByAddingChild(parent); |
|
3286 |
} |
|
3287 |
return parentPath; |
|
3288 |
} |
|
3289 |
||
3290 |
/** |
|
3291 |
* <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code> |
|
3292 |
* that does not allow anything to be selected. |
|
3293 |
* <p> |
|
3294 |
* <strong>Warning:</strong> |
|
3295 |
* Serialized objects of this class will not be compatible with |
|
3296 |
* future Swing releases. The current serialization support is |
|
3297 |
* appropriate for short term storage or RMI between applications running |
|
3298 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 3299 |
* of all JavaBeans™ |
2 | 3300 |
* has been added to the <code>java.beans</code> package. |
3301 |
* Please see {@link java.beans.XMLEncoder}. |
|
3302 |
*/ |
|
11268 | 3303 |
@SuppressWarnings("serial") |
2 | 3304 |
protected static class EmptySelectionModel extends |
3305 |
DefaultTreeSelectionModel |
|
3306 |
{ |
|
3307 |
/** |
|
3308 |
* The single instance of {@code EmptySelectionModel}. |
|
3309 |
*/ |
|
3310 |
protected static final EmptySelectionModel sharedInstance = |
|
3311 |
new EmptySelectionModel(); |
|
3312 |
||
3313 |
/** |
|
3314 |
* Returns the single instance of {@code EmptySelectionModel}. |
|
3315 |
* |
|
3316 |
* @return single instance of {@code EmptySelectionModel} |
|
3317 |
*/ |
|
3318 |
static public EmptySelectionModel sharedInstance() { |
|
3319 |
return sharedInstance; |
|
3320 |
} |
|
3321 |
||
3322 |
/** |
|
3323 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3324 |
* does not allow a selection. |
|
3325 |
* |
|
3326 |
* @param paths the paths to select; this is ignored |
|
3327 |
*/ |
|
3328 |
public void setSelectionPaths(TreePath[] paths) {} |
|
3329 |
||
3330 |
/** |
|
3331 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3332 |
* does not allow a selection. |
|
3333 |
* |
|
3334 |
* @param paths the paths to add to the selection; this is ignored |
|
3335 |
*/ |
|
3336 |
public void addSelectionPaths(TreePath[] paths) {} |
|
3337 |
||
3338 |
/** |
|
3339 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3340 |
* does not allow a selection. |
|
3341 |
* |
|
3342 |
* @param paths the paths to remove; this is ignored |
|
3343 |
*/ |
|
3344 |
public void removeSelectionPaths(TreePath[] paths) {} |
|
3345 |
||
3346 |
/** |
|
3347 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3348 |
* does not allow a selection. |
|
3349 |
* |
|
3350 |
* @param mode the selection mode; this is ignored |
|
3351 |
* @since 1.7 |
|
3352 |
*/ |
|
3353 |
public void setSelectionMode(int mode) { |
|
3354 |
} |
|
3355 |
||
3356 |
/** |
|
3357 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3358 |
* does not allow a selection. |
|
3359 |
* |
|
3360 |
* @param mapper the {@code RowMapper} instance; this is ignored |
|
3361 |
* @since 1.7 |
|
3362 |
*/ |
|
3363 |
public void setRowMapper(RowMapper mapper) { |
|
3364 |
} |
|
3365 |
||
3366 |
/** |
|
3367 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3368 |
* does not allow a selection. |
|
3369 |
* |
|
3370 |
* @param listener the listener to add; this is ignored |
|
3371 |
* @since 1.7 |
|
3372 |
*/ |
|
3373 |
public void addTreeSelectionListener(TreeSelectionListener listener) { |
|
3374 |
} |
|
3375 |
||
3376 |
/** |
|
3377 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3378 |
* does not allow a selection. |
|
3379 |
* |
|
3380 |
* @param listener the listener to remove; this is ignored |
|
3381 |
* @since 1.7 |
|
3382 |
*/ |
|
3383 |
public void removeTreeSelectionListener( |
|
3384 |
TreeSelectionListener listener) { |
|
3385 |
} |
|
3386 |
||
3387 |
/** |
|
3388 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3389 |
* does not allow a selection. |
|
3390 |
* |
|
3391 |
* @param listener the listener to add; this is ignored |
|
3392 |
* @since 1.7 |
|
3393 |
*/ |
|
3394 |
public void addPropertyChangeListener( |
|
3395 |
PropertyChangeListener listener) { |
|
3396 |
} |
|
3397 |
||
3398 |
/** |
|
3399 |
* This is overriden to do nothing; {@code EmptySelectionModel} |
|
3400 |
* does not allow a selection. |
|
3401 |
* |
|
3402 |
* @param listener the listener to remove; this is ignored |
|
3403 |
* @since 1.7 |
|
3404 |
*/ |
|
3405 |
public void removePropertyChangeListener( |
|
3406 |
PropertyChangeListener listener) { |
|
3407 |
} |
|
3408 |
} |
|
3409 |
||
3410 |
||
3411 |
/** |
|
3412 |
* Handles creating a new <code>TreeSelectionEvent</code> with the |
|
3413 |
* <code>JTree</code> as the |
|
3414 |
* source and passing it off to all the listeners. |
|
3415 |
* <p> |
|
3416 |
* <strong>Warning:</strong> |
|
3417 |
* Serialized objects of this class will not be compatible with |
|
3418 |
* future Swing releases. The current serialization support is |
|
3419 |
* appropriate for short term storage or RMI between applications running |
|
3420 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 3421 |
* of all JavaBeans™ |
2 | 3422 |
* has been added to the <code>java.beans</code> package. |
3423 |
* Please see {@link java.beans.XMLEncoder}. |
|
3424 |
*/ |
|
11268 | 3425 |
@SuppressWarnings("serial") |
2 | 3426 |
protected class TreeSelectionRedirector implements Serializable, |
3427 |
TreeSelectionListener |
|
3428 |
{ |
|
3429 |
/** |
|
3430 |
* Invoked by the <code>TreeSelectionModel</code> when the |
|
3431 |
* selection changes. |
|
3432 |
* |
|
3433 |
* @param e the <code>TreeSelectionEvent</code> generated by the |
|
3434 |
* <code>TreeSelectionModel</code> |
|
3435 |
*/ |
|
3436 |
public void valueChanged(TreeSelectionEvent e) { |
|
3437 |
TreeSelectionEvent newE; |
|
3438 |
||
3439 |
newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this); |
|
3440 |
fireValueChanged(newE); |
|
3441 |
} |
|
3442 |
} // End of class JTree.TreeSelectionRedirector |
|
3443 |
||
3444 |
// |
|
3445 |
// Scrollable interface |
|
3446 |
// |
|
3447 |
||
3448 |
/** |
|
3449 |
* Returns the preferred display size of a <code>JTree</code>. The height is |
|
3450 |
* determined from <code>getVisibleRowCount</code> and the width |
|
3451 |
* is the current preferred width. |
|
3452 |
* |
|
3453 |
* @return a <code>Dimension</code> object containing the preferred size |
|
3454 |
*/ |
|
3455 |
public Dimension getPreferredScrollableViewportSize() { |
|
3456 |
int width = getPreferredSize().width; |
|
3457 |
int visRows = getVisibleRowCount(); |
|
3458 |
int height = -1; |
|
3459 |
||
3460 |
if(isFixedRowHeight()) |
|
3461 |
height = visRows * getRowHeight(); |
|
3462 |
else { |
|
3463 |
TreeUI ui = getUI(); |
|
3464 |
||
3465 |
if (ui != null && visRows > 0) { |
|
3466 |
int rc = ui.getRowCount(this); |
|
3467 |
||
3468 |
if (rc >= visRows) { |
|
3469 |
Rectangle bounds = getRowBounds(visRows - 1); |
|
3470 |
if (bounds != null) { |
|
3471 |
height = bounds.y + bounds.height; |
|
3472 |
} |
|
3473 |
} |
|
3474 |
else if (rc > 0) { |
|
3475 |
Rectangle bounds = getRowBounds(0); |
|
3476 |
if (bounds != null) { |
|
3477 |
height = bounds.height * visRows; |
|
3478 |
} |
|
3479 |
} |
|
3480 |
} |
|
3481 |
if (height == -1) { |
|
3482 |
height = 16 * visRows; |
|
3483 |
} |
|
3484 |
} |
|
3485 |
return new Dimension(width, height); |
|
3486 |
} |
|
3487 |
||
3488 |
/** |
|
3489 |
* Returns the amount to increment when scrolling. The amount is |
|
3490 |
* the height of the first displayed row that isn't completely in view |
|
3491 |
* or, if it is totally displayed, the height of the next row in the |
|
3492 |
* scrolling direction. |
|
3493 |
* |
|
3494 |
* @param visibleRect the view area visible within the viewport |
|
3495 |
* @param orientation either <code>SwingConstants.VERTICAL</code> |
|
3496 |
* or <code>SwingConstants.HORIZONTAL</code> |
|
3497 |
* @param direction less than zero to scroll up/left, |
|
3498 |
* greater than zero for down/right |
|
3499 |
* @return the "unit" increment for scrolling in the specified direction |
|
3500 |
* @see JScrollBar#setUnitIncrement(int) |
|
3501 |
*/ |
|
3502 |
public int getScrollableUnitIncrement(Rectangle visibleRect, |
|
3503 |
int orientation, int direction) { |
|
3504 |
if(orientation == SwingConstants.VERTICAL) { |
|
3505 |
Rectangle rowBounds; |
|
3506 |
int firstIndex = getClosestRowForLocation |
|
3507 |
(0, visibleRect.y); |
|
3508 |
||
3509 |
if(firstIndex != -1) { |
|
3510 |
rowBounds = getRowBounds(firstIndex); |
|
3511 |
if(rowBounds.y != visibleRect.y) { |
|
3512 |
if(direction < 0) { |
|
3513 |
// UP |
|
3514 |
return Math.max(0, (visibleRect.y - rowBounds.y)); |
|
3515 |
} |
|
3516 |
return (rowBounds.y + rowBounds.height - visibleRect.y); |
|
3517 |
} |
|
3518 |
if(direction < 0) { // UP |
|
3519 |
if(firstIndex != 0) { |
|
3520 |
rowBounds = getRowBounds(firstIndex - 1); |
|
3521 |
return rowBounds.height; |
|
3522 |
} |
|
3523 |
} |
|
3524 |
else { |
|
3525 |
return rowBounds.height; |
|
3526 |
} |
|
3527 |
} |
|
3528 |
return 0; |
|
3529 |
} |
|
3530 |
return 4; |
|
3531 |
} |
|
3532 |
||
3533 |
||
3534 |
/** |
|
3535 |
* Returns the amount for a block increment, which is the height or |
|
3536 |
* width of <code>visibleRect</code>, based on <code>orientation</code>. |
|
3537 |
* |
|
3538 |
* @param visibleRect the view area visible within the viewport |
|
3539 |
* @param orientation either <code>SwingConstants.VERTICAL</code> |
|
3540 |
* or <code>SwingConstants.HORIZONTAL</code> |
|
3541 |
* @param direction less than zero to scroll up/left, |
|
3542 |
* greater than zero for down/right. |
|
3543 |
* @return the "block" increment for scrolling in the specified direction |
|
3544 |
* @see JScrollBar#setBlockIncrement(int) |
|
3545 |
*/ |
|
3546 |
public int getScrollableBlockIncrement(Rectangle visibleRect, |
|
3547 |
int orientation, int direction) { |
|
3548 |
return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : |
|
3549 |
visibleRect.width; |
|
3550 |
} |
|
3551 |
||
3552 |
/** |
|
3553 |
* Returns false to indicate that the width of the viewport does not |
|
3554 |
* determine the width of the table, unless the preferred width of |
|
3555 |
* the tree is smaller than the viewports width. In other words: |
|
3556 |
* ensure that the tree is never smaller than its viewport. |
|
3557 |
* |
|
3558 |
* @return whether the tree should track the width of the viewport |
|
3559 |
* @see Scrollable#getScrollableTracksViewportWidth |
|
3560 |
*/ |
|
3561 |
public boolean getScrollableTracksViewportWidth() { |
|
5449 | 3562 |
Container parent = SwingUtilities.getUnwrappedParent(this); |
3563 |
if (parent instanceof JViewport) { |
|
3564 |
return parent.getWidth() > getPreferredSize().width; |
|
2 | 3565 |
} |
3566 |
return false; |
|
3567 |
} |
|
3568 |
||
3569 |
/** |
|
3570 |
* Returns false to indicate that the height of the viewport does not |
|
3571 |
* determine the height of the table, unless the preferred height |
|
3572 |
* of the tree is smaller than the viewports height. In other words: |
|
3573 |
* ensure that the tree is never smaller than its viewport. |
|
3574 |
* |
|
3575 |
* @return whether the tree should track the height of the viewport |
|
3576 |
* @see Scrollable#getScrollableTracksViewportHeight |
|
3577 |
*/ |
|
3578 |
public boolean getScrollableTracksViewportHeight() { |
|
5449 | 3579 |
Container parent = SwingUtilities.getUnwrappedParent(this); |
3580 |
if (parent instanceof JViewport) { |
|
3581 |
return parent.getHeight() > getPreferredSize().height; |
|
2 | 3582 |
} |
3583 |
return false; |
|
3584 |
} |
|
3585 |
||
3586 |
/** |
|
3587 |
* Sets the expanded state of this <code>JTree</code>. |
|
3588 |
* If <code>state</code> is |
|
3589 |
* true, all parents of <code>path</code> and path are marked as |
|
3590 |
* expanded. If <code>state</code> is false, all parents of |
|
3591 |
* <code>path</code> are marked EXPANDED, but <code>path</code> itself |
|
3592 |
* is marked collapsed.<p> |
|
3593 |
* This will fail if a <code>TreeWillExpandListener</code> vetos it. |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3594 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3595 |
* @param path a {@code TreePath} identifying a node |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3596 |
* @param state if {@code true}, all parents of @{code path} and path are marked as expanded. |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3597 |
* Otherwise, all parents of {@code path} are marked EXPANDED, |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3598 |
* but {@code path} itself is marked collapsed. |
2 | 3599 |
*/ |
3600 |
protected void setExpandedState(TreePath path, boolean state) { |
|
3601 |
if(path != null) { |
|
3602 |
// Make sure all parents of path are expanded. |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3603 |
Stack<TreePath> stack; |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3604 |
TreePath parentPath = path.getParentPath(); |
2 | 3605 |
|
3606 |
if (expandedStack.size() == 0) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3607 |
stack = new Stack<TreePath>(); |
2 | 3608 |
} |
3609 |
else { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3610 |
stack = expandedStack.pop(); |
2 | 3611 |
} |
3612 |
||
3613 |
try { |
|
3614 |
while(parentPath != null) { |
|
3615 |
if(isExpanded(parentPath)) { |
|
3616 |
parentPath = null; |
|
3617 |
} |
|
3618 |
else { |
|
3619 |
stack.push(parentPath); |
|
3620 |
parentPath = parentPath.getParentPath(); |
|
3621 |
} |
|
3622 |
} |
|
3623 |
for(int counter = stack.size() - 1; counter >= 0; counter--) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3624 |
parentPath = stack.pop(); |
2 | 3625 |
if(!isExpanded(parentPath)) { |
3626 |
try { |
|
3627 |
fireTreeWillExpand(parentPath); |
|
3628 |
} catch (ExpandVetoException eve) { |
|
3629 |
// Expand vetoed! |
|
3630 |
return; |
|
3631 |
} |
|
3632 |
expandedState.put(parentPath, Boolean.TRUE); |
|
3633 |
fireTreeExpanded(parentPath); |
|
3634 |
if (accessibleContext != null) { |
|
3635 |
((AccessibleJTree)accessibleContext). |
|
3636 |
fireVisibleDataPropertyChange(); |
|
3637 |
} |
|
3638 |
} |
|
3639 |
} |
|
3640 |
} |
|
3641 |
finally { |
|
3642 |
if (expandedStack.size() < TEMP_STACK_SIZE) { |
|
3643 |
stack.removeAllElements(); |
|
3644 |
expandedStack.push(stack); |
|
3645 |
} |
|
3646 |
} |
|
3647 |
if(!state) { |
|
3648 |
// collapse last path. |
|
3649 |
Object cValue = expandedState.get(path); |
|
3650 |
||
3651 |
if(cValue != null && ((Boolean)cValue).booleanValue()) { |
|
3652 |
try { |
|
3653 |
fireTreeWillCollapse(path); |
|
3654 |
} |
|
3655 |
catch (ExpandVetoException eve) { |
|
3656 |
return; |
|
3657 |
} |
|
3658 |
expandedState.put(path, Boolean.FALSE); |
|
3659 |
fireTreeCollapsed(path); |
|
3660 |
if (removeDescendantSelectedPaths(path, false) && |
|
3661 |
!isPathSelected(path)) { |
|
3662 |
// A descendant was selected, select the parent. |
|
3663 |
addSelectionPath(path); |
|
3664 |
} |
|
3665 |
if (accessibleContext != null) { |
|
3666 |
((AccessibleJTree)accessibleContext). |
|
3667 |
fireVisibleDataPropertyChange(); |
|
3668 |
} |
|
3669 |
} |
|
3670 |
} |
|
3671 |
else { |
|
3672 |
// Expand last path. |
|
3673 |
Object cValue = expandedState.get(path); |
|
3674 |
||
3675 |
if(cValue == null || !((Boolean)cValue).booleanValue()) { |
|
3676 |
try { |
|
3677 |
fireTreeWillExpand(path); |
|
3678 |
} |
|
3679 |
catch (ExpandVetoException eve) { |
|
3680 |
return; |
|
3681 |
} |
|
3682 |
expandedState.put(path, Boolean.TRUE); |
|
3683 |
fireTreeExpanded(path); |
|
3684 |
if (accessibleContext != null) { |
|
3685 |
((AccessibleJTree)accessibleContext). |
|
3686 |
fireVisibleDataPropertyChange(); |
|
3687 |
} |
|
3688 |
} |
|
3689 |
} |
|
3690 |
} |
|
3691 |
} |
|
3692 |
||
3693 |
/** |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3694 |
* Returns an {@code Enumeration} of {@code TreePaths} |
2 | 3695 |
* that have been expanded that |
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3696 |
* are descendants of {@code parent}. |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3697 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3698 |
* @param parent a path |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3699 |
* @return the {@code Enumeration} of {@code TreePaths} |
2 | 3700 |
*/ |
3701 |
protected Enumeration<TreePath> |
|
3702 |
getDescendantToggledPaths(TreePath parent) |
|
3703 |
{ |
|
3704 |
if(parent == null) |
|
3705 |
return null; |
|
3706 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3707 |
Vector<TreePath> descendants = new Vector<TreePath>(); |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3708 |
Enumeration<TreePath> nodes = expandedState.keys(); |
2 | 3709 |
|
3710 |
while(nodes.hasMoreElements()) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3711 |
TreePath path = nodes.nextElement(); |
2 | 3712 |
if(parent.isDescendant(path)) |
3713 |
descendants.addElement(path); |
|
3714 |
} |
|
3715 |
return descendants.elements(); |
|
3716 |
} |
|
3717 |
||
3718 |
/** |
|
3719 |
* Removes any descendants of the <code>TreePaths</code> in |
|
3720 |
* <code>toRemove</code> |
|
3721 |
* that have been expanded. |
|
3722 |
* |
|
3723 |
* @param toRemove an enumeration of the paths to remove; a value of |
|
3724 |
* {@code null} is ignored |
|
3725 |
* @throws ClassCastException if {@code toRemove} contains an |
|
3726 |
* element that is not a {@code TreePath}; {@code null} |
|
3727 |
* values are ignored |
|
3728 |
*/ |
|
3729 |
protected void |
|
3730 |
removeDescendantToggledPaths(Enumeration<TreePath> toRemove) |
|
3731 |
{ |
|
3732 |
if(toRemove != null) { |
|
3733 |
while(toRemove.hasMoreElements()) { |
|
11268 | 3734 |
Enumeration<?> descendants = getDescendantToggledPaths |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
3735 |
(toRemove.nextElement()); |
2 | 3736 |
|
3737 |
if(descendants != null) { |
|
3738 |
while(descendants.hasMoreElements()) { |
|
3739 |
expandedState.remove(descendants.nextElement()); |
|
3740 |
} |
|
3741 |
} |
|
3742 |
} |
|
3743 |
} |
|
3744 |
} |
|
3745 |
||
3746 |
/** |
|
3747 |
* Clears the cache of toggled tree paths. This does NOT send out |
|
3748 |
* any <code>TreeExpansionListener</code> events. |
|
3749 |
*/ |
|
3750 |
protected void clearToggledPaths() { |
|
3751 |
expandedState.clear(); |
|
3752 |
} |
|
3753 |
||
3754 |
/** |
|
3755 |
* Creates and returns an instance of <code>TreeModelHandler</code>. |
|
3756 |
* The returned |
|
3757 |
* object is responsible for updating the expanded state when the |
|
3758 |
* <code>TreeModel</code> changes. |
|
3759 |
* <p> |
|
3760 |
* For more information on what expanded state means, see the |
|
3761 |
* <a href=#jtree_description>JTree description</a> above. |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3762 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3763 |
* @return the instance of {@code TreeModelHandler} |
2 | 3764 |
*/ |
3765 |
protected TreeModelListener createTreeModelListener() { |
|
3766 |
return new TreeModelHandler(); |
|
3767 |
} |
|
3768 |
||
3769 |
/** |
|
3770 |
* Removes any paths in the selection that are descendants of |
|
3771 |
* <code>path</code>. If <code>includePath</code> is true and |
|
3772 |
* <code>path</code> is selected, it will be removed from the selection. |
|
3773 |
* |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3774 |
* @param path a path |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3775 |
* @param includePath is {@code true} and {@code path} is selected, |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3776 |
* it will be removed from the selection. |
2 | 3777 |
* @return true if a descendant was selected |
3778 |
* @since 1.3 |
|
3779 |
*/ |
|
3780 |
protected boolean removeDescendantSelectedPaths(TreePath path, |
|
3781 |
boolean includePath) { |
|
3782 |
TreePath[] toRemove = getDescendantSelectedPaths(path, includePath); |
|
3783 |
||
3784 |
if (toRemove != null) { |
|
3785 |
getSelectionModel().removeSelectionPaths(toRemove); |
|
3786 |
return true; |
|
3787 |
} |
|
3788 |
return false; |
|
3789 |
} |
|
3790 |
||
3791 |
/** |
|
3792 |
* Returns an array of paths in the selection that are descendants of |
|
3793 |
* <code>path</code>. The returned array may contain <code>null</code>s. |
|
3794 |
*/ |
|
3795 |
private TreePath[] getDescendantSelectedPaths(TreePath path, |
|
3796 |
boolean includePath) { |
|
3797 |
TreeSelectionModel sm = getSelectionModel(); |
|
3798 |
TreePath[] selPaths = (sm != null) ? sm.getSelectionPaths() : |
|
3799 |
null; |
|
3800 |
||
3801 |
if(selPaths != null) { |
|
3802 |
boolean shouldRemove = false; |
|
3803 |
||
3804 |
for(int counter = selPaths.length - 1; counter >= 0; counter--) { |
|
3805 |
if(selPaths[counter] != null && |
|
3806 |
path.isDescendant(selPaths[counter]) && |
|
3807 |
(!path.equals(selPaths[counter]) || includePath)) |
|
3808 |
shouldRemove = true; |
|
3809 |
else |
|
3810 |
selPaths[counter] = null; |
|
3811 |
} |
|
3812 |
if(!shouldRemove) { |
|
3813 |
selPaths = null; |
|
3814 |
} |
|
3815 |
return selPaths; |
|
3816 |
} |
|
3817 |
return null; |
|
3818 |
} |
|
3819 |
||
3820 |
/** |
|
3821 |
* Removes any paths from the selection model that are descendants of |
|
3822 |
* the nodes identified by in <code>e</code>. |
|
3823 |
*/ |
|
3824 |
void removeDescendantSelectedPaths(TreeModelEvent e) { |
|
18133
41b4b144eaff
8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents:
11268
diff
changeset
|
3825 |
TreePath pPath = SwingUtilities2.getTreePath(e, getModel()); |
2 | 3826 |
Object[] oldChildren = e.getChildren(); |
3827 |
TreeSelectionModel sm = getSelectionModel(); |
|
3828 |
||
3829 |
if (sm != null && pPath != null && oldChildren != null && |
|
3830 |
oldChildren.length > 0) { |
|
3831 |
for (int counter = oldChildren.length - 1; counter >= 0; |
|
3832 |
counter--) { |
|
3833 |
// Might be better to call getDescendantSelectedPaths |
|
3834 |
// numerous times, then push to the model. |
|
3835 |
removeDescendantSelectedPaths(pPath.pathByAddingChild |
|
3836 |
(oldChildren[counter]), true); |
|
3837 |
} |
|
3838 |
} |
|
3839 |
} |
|
3840 |
||
3841 |
||
3842 |
/** |
|
3843 |
* Listens to the model and updates the <code>expandedState</code> |
|
3844 |
* accordingly when nodes are removed, or changed. |
|
3845 |
*/ |
|
3846 |
protected class TreeModelHandler implements TreeModelListener { |
|
3847 |
public void treeNodesChanged(TreeModelEvent e) { } |
|
3848 |
||
3849 |
public void treeNodesInserted(TreeModelEvent e) { } |
|
3850 |
||
3851 |
public void treeStructureChanged(TreeModelEvent e) { |
|
3852 |
if(e == null) |
|
3853 |
return; |
|
3854 |
||
3855 |
// NOTE: If I change this to NOT remove the descendants |
|
3856 |
// and update BasicTreeUIs treeStructureChanged method |
|
3857 |
// to update descendants in response to a treeStructureChanged |
|
3858 |
// event, all the children of the event won't collapse! |
|
18133
41b4b144eaff
8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents:
11268
diff
changeset
|
3859 |
TreePath parent = SwingUtilities2.getTreePath(e, getModel()); |
2 | 3860 |
|
3861 |
if(parent == null) |
|
3862 |
return; |
|
3863 |
||
3864 |
if (parent.getPathCount() == 1) { |
|
3865 |
// New root, remove everything! |
|
3866 |
clearToggledPaths(); |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3867 |
|
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3868 |
Object treeRoot = treeModel.getRoot(); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3869 |
|
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3870 |
if(treeRoot != null && |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
3871 |
!treeModel.isLeaf(treeRoot)) { |
2 | 3872 |
// Mark the root as expanded, if it isn't a leaf. |
3873 |
expandedState.put(parent, Boolean.TRUE); |
|
3874 |
} |
|
3875 |
} |
|
3876 |
else if(expandedState.get(parent) != null) { |
|
3877 |
Vector<TreePath> toRemove = new Vector<TreePath>(1); |
|
3878 |
boolean isExpanded = isExpanded(parent); |
|
3879 |
||
3880 |
toRemove.addElement(parent); |
|
3881 |
removeDescendantToggledPaths(toRemove.elements()); |
|
3882 |
if(isExpanded) { |
|
3883 |
TreeModel model = getModel(); |
|
3884 |
||
3885 |
if(model == null || model.isLeaf |
|
3886 |
(parent.getLastPathComponent())) |
|
3887 |
collapsePath(parent); |
|
3888 |
else |
|
3889 |
expandedState.put(parent, Boolean.TRUE); |
|
3890 |
} |
|
3891 |
} |
|
3892 |
removeDescendantSelectedPaths(parent, false); |
|
3893 |
} |
|
3894 |
||
3895 |
public void treeNodesRemoved(TreeModelEvent e) { |
|
3896 |
if(e == null) |
|
3897 |
return; |
|
3898 |
||
18133
41b4b144eaff
8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents:
11268
diff
changeset
|
3899 |
TreePath parent = SwingUtilities2.getTreePath(e, getModel()); |
2 | 3900 |
Object[] children = e.getChildren(); |
3901 |
||
3902 |
if(children == null) |
|
3903 |
return; |
|
3904 |
||
3905 |
TreePath rPath; |
|
3906 |
Vector<TreePath> toRemove |
|
3907 |
= new Vector<TreePath>(Math.max(1, children.length)); |
|
3908 |
||
3909 |
for(int counter = children.length - 1; counter >= 0; counter--) { |
|
3910 |
rPath = parent.pathByAddingChild(children[counter]); |
|
3911 |
if(expandedState.get(rPath) != null) |
|
3912 |
toRemove.addElement(rPath); |
|
3913 |
} |
|
3914 |
if(toRemove.size() > 0) |
|
3915 |
removeDescendantToggledPaths(toRemove.elements()); |
|
3916 |
||
3917 |
TreeModel model = getModel(); |
|
3918 |
||
3919 |
if(model == null || model.isLeaf(parent.getLastPathComponent())) |
|
3920 |
expandedState.remove(parent); |
|
3921 |
||
3922 |
removeDescendantSelectedPaths(e); |
|
3923 |
} |
|
3924 |
} |
|
3925 |
||
3926 |
||
3927 |
/** |
|
3928 |
* <code>DynamicUtilTreeNode</code> can wrap |
|
3929 |
* vectors/hashtables/arrays/strings and |
|
3930 |
* create the appropriate children tree nodes as necessary. It is |
|
3931 |
* dynamic in that it will only create the children as necessary. |
|
3932 |
* <p> |
|
3933 |
* <strong>Warning:</strong> |
|
3934 |
* Serialized objects of this class will not be compatible with |
|
3935 |
* future Swing releases. The current serialization support is |
|
3936 |
* appropriate for short term storage or RMI between applications running |
|
3937 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 3938 |
* of all JavaBeans™ |
2 | 3939 |
* has been added to the <code>java.beans</code> package. |
3940 |
* Please see {@link java.beans.XMLEncoder}. |
|
3941 |
*/ |
|
11268 | 3942 |
@SuppressWarnings("serial") |
2 | 3943 |
public static class DynamicUtilTreeNode extends DefaultMutableTreeNode { |
3944 |
/** |
|
3945 |
* Does the this <code>JTree</code> have children? |
|
3946 |
* This property is currently not implemented. |
|
3947 |
*/ |
|
3948 |
protected boolean hasChildren; |
|
3949 |
/** Value to create children with. */ |
|
3950 |
protected Object childValue; |
|
3951 |
/** Have the children been loaded yet? */ |
|
3952 |
protected boolean loadedChildren; |
|
3953 |
||
3954 |
/** |
|
3955 |
* Adds to parent all the children in <code>children</code>. |
|
3956 |
* If <code>children</code> is an array or vector all of its |
|
3957 |
* elements are added is children, otherwise if <code>children</code> |
|
3958 |
* is a hashtable all the key/value pairs are added in the order |
|
3959 |
* <code>Enumeration</code> returns them. |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3960 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3961 |
* @param parent the parent node |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
3962 |
* @param children the children |
2 | 3963 |
*/ |
3964 |
public static void createChildren(DefaultMutableTreeNode parent, |
|
3965 |
Object children) { |
|
3966 |
if(children instanceof Vector) { |
|
11268 | 3967 |
Vector<?> childVector = (Vector)children; |
2 | 3968 |
|
3969 |
for(int counter = 0, maxCounter = childVector.size(); |
|
3970 |
counter < maxCounter; counter++) |
|
3971 |
parent.add(new DynamicUtilTreeNode |
|
3972 |
(childVector.elementAt(counter), |
|
3973 |
childVector.elementAt(counter))); |
|
3974 |
} |
|
3975 |
else if(children instanceof Hashtable) { |
|
11268 | 3976 |
Hashtable<?,?> childHT = (Hashtable)children; |
3977 |
Enumeration<?> keys = childHT.keys(); |
|
2 | 3978 |
Object aKey; |
3979 |
||
3980 |
while(keys.hasMoreElements()) { |
|
3981 |
aKey = keys.nextElement(); |
|
3982 |
parent.add(new DynamicUtilTreeNode(aKey, |
|
3983 |
childHT.get(aKey))); |
|
3984 |
} |
|
3985 |
} |
|
3986 |
else if(children instanceof Object[]) { |
|
3987 |
Object[] childArray = (Object[])children; |
|
3988 |
||
3989 |
for(int counter = 0, maxCounter = childArray.length; |
|
3990 |
counter < maxCounter; counter++) |
|
3991 |
parent.add(new DynamicUtilTreeNode(childArray[counter], |
|
3992 |
childArray[counter])); |
|
3993 |
} |
|
3994 |
} |
|
3995 |
||
3996 |
/** |
|
3997 |
* Creates a node with the specified object as its value and |
|
3998 |
* with the specified children. For the node to allow children, |
|
3999 |
* the children-object must be an array of objects, a |
|
4000 |
* <code>Vector</code>, or a <code>Hashtable</code> -- even |
|
4001 |
* if empty. Otherwise, the node is not |
|
4002 |
* allowed to have children. |
|
4003 |
* |
|
4004 |
* @param value the <code>Object</code> that is the value for the |
|
4005 |
* new node |
|
4006 |
* @param children an array of <code>Object</code>s, a |
|
4007 |
* <code>Vector</code>, or a <code>Hashtable</code> |
|
4008 |
* used to create the child nodes; if any other |
|
4009 |
* object is specified, or if the value is |
|
4010 |
* <code>null</code>, |
|
4011 |
* then the node is not allowed to have children |
|
4012 |
*/ |
|
4013 |
public DynamicUtilTreeNode(Object value, Object children) { |
|
4014 |
super(value); |
|
4015 |
loadedChildren = false; |
|
4016 |
childValue = children; |
|
4017 |
if(children != null) { |
|
4018 |
if(children instanceof Vector) |
|
4019 |
setAllowsChildren(true); |
|
4020 |
else if(children instanceof Hashtable) |
|
4021 |
setAllowsChildren(true); |
|
4022 |
else if(children instanceof Object[]) |
|
4023 |
setAllowsChildren(true); |
|
4024 |
else |
|
4025 |
setAllowsChildren(false); |
|
4026 |
} |
|
4027 |
else |
|
4028 |
setAllowsChildren(false); |
|
4029 |
} |
|
4030 |
||
4031 |
/** |
|
4032 |
* Returns true if this node allows children. Whether the node |
|
4033 |
* allows children depends on how it was created. |
|
4034 |
* |
|
4035 |
* @return true if this node allows children, false otherwise |
|
21982 | 4036 |
* @see JTree.DynamicUtilTreeNode |
2 | 4037 |
*/ |
4038 |
public boolean isLeaf() { |
|
4039 |
return !getAllowsChildren(); |
|
4040 |
} |
|
4041 |
||
4042 |
/** |
|
4043 |
* Returns the number of child nodes. |
|
4044 |
* |
|
4045 |
* @return the number of child nodes |
|
4046 |
*/ |
|
4047 |
public int getChildCount() { |
|
4048 |
if(!loadedChildren) |
|
4049 |
loadChildren(); |
|
4050 |
return super.getChildCount(); |
|
4051 |
} |
|
4052 |
||
4053 |
/** |
|
4054 |
* Loads the children based on <code>childValue</code>. |
|
4055 |
* If <code>childValue</code> is a <code>Vector</code> |
|
4056 |
* or array each element is added as a child, |
|
4057 |
* if <code>childValue</code> is a <code>Hashtable</code> |
|
4058 |
* each key/value pair is added in the order that |
|
4059 |
* <code>Enumeration</code> returns the keys. |
|
4060 |
*/ |
|
4061 |
protected void loadChildren() { |
|
4062 |
loadedChildren = true; |
|
4063 |
createChildren(this, childValue); |
|
4064 |
} |
|
4065 |
||
4066 |
/** |
|
4067 |
* Subclassed to load the children, if necessary. |
|
4068 |
*/ |
|
4069 |
public TreeNode getChildAt(int index) { |
|
4070 |
if(!loadedChildren) |
|
4071 |
loadChildren(); |
|
4072 |
return super.getChildAt(index); |
|
4073 |
} |
|
4074 |
||
4075 |
/** |
|
4076 |
* Subclassed to load the children, if necessary. |
|
4077 |
*/ |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
25201
diff
changeset
|
4078 |
public Enumeration<TreeNode> children() { |
2 | 4079 |
if(!loadedChildren) |
4080 |
loadChildren(); |
|
4081 |
return super.children(); |
|
4082 |
} |
|
4083 |
} |
|
4084 |
||
4085 |
void setUIProperty(String propertyName, Object value) { |
|
4086 |
if (propertyName == "rowHeight") { |
|
4087 |
if (!rowHeightSet) { |
|
4088 |
setRowHeight(((Number)value).intValue()); |
|
4089 |
rowHeightSet = false; |
|
4090 |
} |
|
4091 |
} else if (propertyName == "scrollsOnExpand") { |
|
4092 |
if (!scrollsOnExpandSet) { |
|
4093 |
setScrollsOnExpand(((Boolean)value).booleanValue()); |
|
4094 |
scrollsOnExpandSet = false; |
|
4095 |
} |
|
4096 |
} else if (propertyName == "showsRootHandles") { |
|
4097 |
if (!showsRootHandlesSet) { |
|
4098 |
setShowsRootHandles(((Boolean)value).booleanValue()); |
|
4099 |
showsRootHandlesSet = false; |
|
4100 |
} |
|
4101 |
} else { |
|
4102 |
super.setUIProperty(propertyName, value); |
|
4103 |
} |
|
4104 |
} |
|
4105 |
||
4106 |
||
4107 |
/** |
|
4108 |
* Returns a string representation of this <code>JTree</code>. |
|
4109 |
* This method |
|
4110 |
* is intended to be used only for debugging purposes, and the |
|
4111 |
* content and format of the returned string may vary between |
|
4112 |
* implementations. The returned string may be empty but may not |
|
4113 |
* be <code>null</code>. |
|
4114 |
* |
|
4115 |
* @return a string representation of this <code>JTree</code>. |
|
4116 |
*/ |
|
4117 |
protected String paramString() { |
|
4118 |
String rootVisibleString = (rootVisible ? |
|
4119 |
"true" : "false"); |
|
4120 |
String showsRootHandlesString = (showsRootHandles ? |
|
4121 |
"true" : "false"); |
|
4122 |
String editableString = (editable ? |
|
4123 |
"true" : "false"); |
|
4124 |
String largeModelString = (largeModel ? |
|
4125 |
"true" : "false"); |
|
4126 |
String invokesStopCellEditingString = (invokesStopCellEditing ? |
|
4127 |
"true" : "false"); |
|
4128 |
String scrollsOnExpandString = (scrollsOnExpand ? |
|
4129 |
"true" : "false"); |
|
4130 |
||
4131 |
return super.paramString() + |
|
4132 |
",editable=" + editableString + |
|
4133 |
",invokesStopCellEditing=" + invokesStopCellEditingString + |
|
4134 |
",largeModel=" + largeModelString + |
|
4135 |
",rootVisible=" + rootVisibleString + |
|
4136 |
",rowHeight=" + rowHeight + |
|
4137 |
",scrollsOnExpand=" + scrollsOnExpandString + |
|
4138 |
",showsRootHandles=" + showsRootHandlesString + |
|
4139 |
",toggleClickCount=" + toggleClickCount + |
|
4140 |
",visibleRowCount=" + visibleRowCount; |
|
4141 |
} |
|
4142 |
||
4143 |
///////////////// |
|
4144 |
// Accessibility support |
|
4145 |
//////////////// |
|
4146 |
||
4147 |
/** |
|
4148 |
* Gets the AccessibleContext associated with this JTree. |
|
4149 |
* For JTrees, the AccessibleContext takes the form of an |
|
4150 |
* AccessibleJTree. |
|
4151 |
* A new AccessibleJTree instance is created if necessary. |
|
4152 |
* |
|
4153 |
* @return an AccessibleJTree that serves as the |
|
4154 |
* AccessibleContext of this JTree |
|
4155 |
*/ |
|
4156 |
public AccessibleContext getAccessibleContext() { |
|
4157 |
if (accessibleContext == null) { |
|
4158 |
accessibleContext = new AccessibleJTree(); |
|
4159 |
} |
|
4160 |
return accessibleContext; |
|
4161 |
} |
|
4162 |
||
4163 |
/** |
|
4164 |
* This class implements accessibility support for the |
|
4165 |
* <code>JTree</code> class. It provides an implementation of the |
|
4166 |
* Java Accessibility API appropriate to tree user-interface elements. |
|
4167 |
* <p> |
|
4168 |
* <strong>Warning:</strong> |
|
4169 |
* Serialized objects of this class will not be compatible with |
|
4170 |
* future Swing releases. The current serialization support is |
|
4171 |
* appropriate for short term storage or RMI between applications running |
|
4172 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 4173 |
* of all JavaBeans™ |
2 | 4174 |
* has been added to the <code>java.beans</code> package. |
4175 |
* Please see {@link java.beans.XMLEncoder}. |
|
4176 |
*/ |
|
11268 | 4177 |
@SuppressWarnings("serial") |
2 | 4178 |
protected class AccessibleJTree extends AccessibleJComponent |
4179 |
implements AccessibleSelection, TreeSelectionListener, |
|
4180 |
TreeModelListener, TreeExpansionListener { |
|
4181 |
||
4182 |
TreePath leadSelectionPath; |
|
4183 |
Accessible leadSelectionAccessible; |
|
4184 |
||
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4185 |
/** |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4186 |
* Constructs {@code AccessibleJTree} |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4187 |
*/ |
2 | 4188 |
public AccessibleJTree() { |
4189 |
// Add a tree model listener for JTree |
|
4190 |
TreeModel model = JTree.this.getModel(); |
|
4191 |
if (model != null) { |
|
4192 |
model.addTreeModelListener(this); |
|
4193 |
} |
|
4194 |
JTree.this.addTreeExpansionListener(this); |
|
4195 |
JTree.this.addTreeSelectionListener(this); |
|
4196 |
leadSelectionPath = JTree.this.getLeadSelectionPath(); |
|
4197 |
leadSelectionAccessible = (leadSelectionPath != null) |
|
4198 |
? new AccessibleJTreeNode(JTree.this, |
|
4199 |
leadSelectionPath, |
|
4200 |
JTree.this) |
|
4201 |
: null; |
|
4202 |
} |
|
4203 |
||
4204 |
/** |
|
4205 |
* Tree Selection Listener value change method. Used to fire the |
|
4206 |
* property change |
|
4207 |
* |
|
4208 |
* @param e ListSelectionEvent |
|
4209 |
* |
|
4210 |
*/ |
|
4211 |
public void valueChanged(TreeSelectionEvent e) { |
|
24187
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4212 |
firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4213 |
Boolean.valueOf(false), Boolean.valueOf(true)); |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4214 |
} |
2 | 4215 |
|
4216 |
/** |
|
4217 |
* Fire a visible data property change notification. |
|
4218 |
* A 'visible' data property is one that represents |
|
4219 |
* something about the way the component appears on the |
|
4220 |
* display, where that appearance isn't bound to any other |
|
4221 |
* property. It notifies screen readers that the visual |
|
4222 |
* appearance of the component has changed, so they can |
|
4223 |
* notify the user. |
|
4224 |
*/ |
|
4225 |
public void fireVisibleDataPropertyChange() { |
|
4226 |
firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, |
|
4227 |
Boolean.valueOf(false), Boolean.valueOf(true)); |
|
4228 |
} |
|
4229 |
||
4230 |
// Fire the visible data changes for the model changes. |
|
4231 |
||
4232 |
/** |
|
4233 |
* Tree Model Node change notification. |
|
4234 |
* |
|
4235 |
* @param e a Tree Model event |
|
4236 |
*/ |
|
4237 |
public void treeNodesChanged(TreeModelEvent e) { |
|
4238 |
fireVisibleDataPropertyChange(); |
|
4239 |
} |
|
4240 |
||
4241 |
/** |
|
4242 |
* Tree Model Node change notification. |
|
4243 |
* |
|
4244 |
* @param e a Tree node insertion event |
|
4245 |
*/ |
|
4246 |
public void treeNodesInserted(TreeModelEvent e) { |
|
4247 |
fireVisibleDataPropertyChange(); |
|
4248 |
} |
|
4249 |
||
4250 |
/** |
|
4251 |
* Tree Model Node change notification. |
|
4252 |
* |
|
4253 |
* @param e a Tree node(s) removal event |
|
4254 |
*/ |
|
4255 |
public void treeNodesRemoved(TreeModelEvent e) { |
|
4256 |
fireVisibleDataPropertyChange(); |
|
4257 |
} |
|
4258 |
||
4259 |
/** |
|
4260 |
* Tree Model structure change change notification. |
|
4261 |
* |
|
4262 |
* @param e a Tree Model event |
|
4263 |
*/ |
|
4264 |
public void treeStructureChanged(TreeModelEvent e) { |
|
4265 |
fireVisibleDataPropertyChange(); |
|
4266 |
} |
|
4267 |
||
4268 |
/** |
|
4269 |
* Tree Collapsed notification. |
|
4270 |
* |
|
4271 |
* @param e a TreeExpansionEvent |
|
4272 |
*/ |
|
4273 |
public void treeCollapsed(TreeExpansionEvent e) { |
|
4274 |
fireVisibleDataPropertyChange(); |
|
4275 |
TreePath path = e.getPath(); |
|
4276 |
if (path != null) { |
|
4277 |
// Set parent to null so AccessibleJTreeNode computes |
|
4278 |
// its parent. |
|
4279 |
AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this, |
|
4280 |
path, |
|
4281 |
null); |
|
4282 |
PropertyChangeEvent pce = new PropertyChangeEvent(node, |
|
4283 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
4284 |
AccessibleState.EXPANDED, |
|
4285 |
AccessibleState.COLLAPSED); |
|
4286 |
firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
4287 |
null, pce); |
|
4288 |
} |
|
4289 |
} |
|
4290 |
||
4291 |
/** |
|
4292 |
* Tree Model Expansion notification. |
|
4293 |
* |
|
4294 |
* @param e a Tree node insertion event |
|
4295 |
*/ |
|
4296 |
public void treeExpanded(TreeExpansionEvent e) { |
|
4297 |
fireVisibleDataPropertyChange(); |
|
4298 |
TreePath path = e.getPath(); |
|
4299 |
if (path != null) { |
|
4300 |
// TIGER - 4839971 |
|
4301 |
// Set parent to null so AccessibleJTreeNode computes |
|
4302 |
// its parent. |
|
4303 |
AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this, |
|
4304 |
path, |
|
4305 |
null); |
|
4306 |
PropertyChangeEvent pce = new PropertyChangeEvent(node, |
|
4307 |
AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
4308 |
AccessibleState.COLLAPSED, |
|
4309 |
AccessibleState.EXPANDED); |
|
4310 |
firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, |
|
4311 |
null, pce); |
|
4312 |
} |
|
4313 |
} |
|
4314 |
||
24187
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4315 |
/** |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4316 |
* Fire an active descendant property change notification. |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4317 |
* The active descendant is used for objects such as list, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4318 |
* tree, and table, which may have transient children. |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4319 |
* It notifies screen readers the active child of the component |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4320 |
* has been changed so user can be notified from there. |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4321 |
* |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4322 |
* @param oldPath - lead path of previous active child |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4323 |
* @param newPath - lead path of current active child |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4324 |
* |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4325 |
*/ |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4326 |
void fireActiveDescendantPropertyChange(TreePath oldPath, TreePath newPath){ |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4327 |
if(oldPath != newPath){ |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4328 |
Accessible oldLSA = (oldPath != null) |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4329 |
? new AccessibleJTreeNode(JTree.this, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4330 |
oldPath, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4331 |
null) |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4332 |
: null; |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4333 |
|
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4334 |
Accessible newLSA = (newPath != null) |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4335 |
? new AccessibleJTreeNode(JTree.this, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4336 |
newPath, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4337 |
null) |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4338 |
: null; |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4339 |
firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4340 |
oldLSA, newLSA); |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4341 |
} |
971bf0a51f75
8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents:
23010
diff
changeset
|
4342 |
} |
2 | 4343 |
|
4344 |
private AccessibleContext getCurrentAccessibleContext() { |
|
4345 |
Component c = getCurrentComponent(); |
|
4346 |
if (c instanceof Accessible) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
4347 |
return c.getAccessibleContext(); |
2 | 4348 |
} else { |
4349 |
return null; |
|
4350 |
} |
|
4351 |
} |
|
4352 |
||
4353 |
private Component getCurrentComponent() { |
|
4354 |
// is the object visible? |
|
4355 |
// if so, get row, selected, focus & leaf state, |
|
4356 |
// and then get the renderer component and return it |
|
4357 |
TreeModel model = JTree.this.getModel(); |
|
4358 |
if (model == null) { |
|
4359 |
return null; |
|
4360 |
} |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4361 |
|
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4362 |
Object treeRoot = model.getRoot(); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4363 |
if (treeRoot == null) { |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4364 |
return null; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4365 |
} |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4366 |
TreePath path = new TreePath(treeRoot); |
2 | 4367 |
if (JTree.this.isVisible(path)) { |
4368 |
TreeCellRenderer r = JTree.this.getCellRenderer(); |
|
4369 |
TreeUI ui = JTree.this.getUI(); |
|
4370 |
if (ui != null) { |
|
4371 |
int row = ui.getRowForPath(JTree.this, path); |
|
4372 |
int lsr = JTree.this.getLeadSelectionRow(); |
|
4373 |
boolean hasFocus = JTree.this.isFocusOwner() |
|
4374 |
&& (lsr == row); |
|
4375 |
boolean selected = JTree.this.isPathSelected(path); |
|
4376 |
boolean expanded = JTree.this.isExpanded(path); |
|
4377 |
||
4378 |
return r.getTreeCellRendererComponent(JTree.this, |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4379 |
treeRoot, selected, expanded, |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4380 |
model.isLeaf(treeRoot), row, hasFocus); |
2 | 4381 |
} |
4382 |
} |
|
4383 |
return null; |
|
4384 |
} |
|
4385 |
||
4386 |
// Overridden methods from AccessibleJComponent |
|
4387 |
||
4388 |
/** |
|
4389 |
* Get the role of this object. |
|
4390 |
* |
|
4391 |
* @return an instance of AccessibleRole describing the role of the |
|
4392 |
* object |
|
4393 |
* @see AccessibleRole |
|
4394 |
*/ |
|
4395 |
public AccessibleRole getAccessibleRole() { |
|
4396 |
return AccessibleRole.TREE; |
|
4397 |
} |
|
4398 |
||
4399 |
/** |
|
4400 |
* Returns the <code>Accessible</code> child, if one exists, |
|
4401 |
* contained at the local coordinate <code>Point</code>. |
|
4402 |
* Otherwise returns <code>null</code>. |
|
4403 |
* |
|
4404 |
* @param p point in local coordinates of this <code>Accessible</code> |
|
4405 |
* @return the <code>Accessible</code>, if it exists, |
|
4406 |
* at the specified location; else <code>null</code> |
|
4407 |
*/ |
|
4408 |
public Accessible getAccessibleAt(Point p) { |
|
4409 |
TreePath path = getClosestPathForLocation(p.x, p.y); |
|
4410 |
if (path != null) { |
|
4411 |
// JTree.this is NOT the parent; parent will get computed later |
|
4412 |
return new AccessibleJTreeNode(JTree.this, path, null); |
|
4413 |
} else { |
|
4414 |
return null; |
|
4415 |
} |
|
4416 |
} |
|
4417 |
||
4418 |
/** |
|
4419 |
* Returns the number of top-level children nodes of this |
|
4420 |
* JTree. Each of these nodes may in turn have children nodes. |
|
4421 |
* |
|
4422 |
* @return the number of accessible children nodes in the tree. |
|
4423 |
*/ |
|
4424 |
public int getAccessibleChildrenCount() { |
|
4425 |
TreeModel model = JTree.this.getModel(); |
|
4426 |
if (model == null) { |
|
4427 |
return 0; |
|
4428 |
} |
|
4429 |
if (isRootVisible()) { |
|
4430 |
return 1; // the root node |
|
4431 |
} |
|
4432 |
||
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4433 |
Object treeRoot = model.getRoot(); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4434 |
if (treeRoot == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4435 |
return 0; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4436 |
|
2 | 4437 |
// return the root's first set of children count |
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4438 |
return model.getChildCount(treeRoot); |
2 | 4439 |
} |
4440 |
||
4441 |
/** |
|
4442 |
* Return the nth Accessible child of the object. |
|
4443 |
* |
|
4444 |
* @param i zero-based index of child |
|
4445 |
* @return the nth Accessible child of the object |
|
4446 |
*/ |
|
4447 |
public Accessible getAccessibleChild(int i) { |
|
4448 |
TreeModel model = JTree.this.getModel(); |
|
4449 |
if (model == null) { |
|
4450 |
return null; |
|
4451 |
} |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4452 |
|
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4453 |
Object treeRoot = model.getRoot(); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4454 |
if (treeRoot == null) { |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4455 |
return null; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4456 |
} |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4457 |
|
2 | 4458 |
if (isRootVisible()) { |
4459 |
if (i == 0) { // return the root node Accessible |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4460 |
Object[] objPath = { treeRoot }; |
2 | 4461 |
TreePath path = new TreePath(objPath); |
4462 |
return new AccessibleJTreeNode(JTree.this, path, JTree.this); |
|
4463 |
} else { |
|
4464 |
return null; |
|
4465 |
} |
|
4466 |
} |
|
4467 |
||
4468 |
// return Accessible for one of root's child nodes |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4469 |
int count = model.getChildCount(treeRoot); |
2 | 4470 |
if (i < 0 || i >= count) { |
4471 |
return null; |
|
4472 |
} |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4473 |
Object obj = model.getChild(treeRoot, i); |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4474 |
if (obj == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4475 |
return null; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4476 |
|
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4477 |
Object[] objPath = {treeRoot, obj }; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4478 |
|
2 | 4479 |
TreePath path = new TreePath(objPath); |
4480 |
return new AccessibleJTreeNode(JTree.this, path, JTree.this); |
|
4481 |
} |
|
4482 |
||
4483 |
/** |
|
4484 |
* Get the index of this object in its accessible parent. |
|
4485 |
* |
|
4486 |
* @return the index of this object in its parent. Since a JTree |
|
4487 |
* top-level object does not have an accessible parent. |
|
4488 |
* @see #getAccessibleParent |
|
4489 |
*/ |
|
4490 |
public int getAccessibleIndexInParent() { |
|
4491 |
// didn't ever need to override this... |
|
4492 |
return super.getAccessibleIndexInParent(); |
|
4493 |
} |
|
4494 |
||
4495 |
// AccessibleSelection methods |
|
4496 |
/** |
|
4497 |
* Get the AccessibleSelection associated with this object. In the |
|
4498 |
* implementation of the Java Accessibility API for this class, |
|
4499 |
* return this object, which is responsible for implementing the |
|
4500 |
* AccessibleSelection interface on behalf of itself. |
|
4501 |
* |
|
4502 |
* @return this object |
|
4503 |
*/ |
|
4504 |
public AccessibleSelection getAccessibleSelection() { |
|
4505 |
return this; |
|
4506 |
} |
|
4507 |
||
4508 |
/** |
|
4509 |
* Returns the number of items currently selected. |
|
4510 |
* If no items are selected, the return value will be 0. |
|
4511 |
* |
|
4512 |
* @return the number of items currently selected. |
|
4513 |
*/ |
|
4514 |
public int getAccessibleSelectionCount() { |
|
4515 |
Object[] rootPath = new Object[1]; |
|
4516 |
rootPath[0] = treeModel.getRoot(); |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4517 |
if (rootPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4518 |
return 0; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4519 |
|
2 | 4520 |
TreePath childPath = new TreePath(rootPath); |
4521 |
if (JTree.this.isPathSelected(childPath)) { |
|
4522 |
return 1; |
|
4523 |
} else { |
|
4524 |
return 0; |
|
4525 |
} |
|
4526 |
} |
|
4527 |
||
4528 |
/** |
|
4529 |
* Returns an Accessible representing the specified selected item |
|
4530 |
* in the object. If there isn't a selection, or there are |
|
4531 |
* fewer items selected than the integer passed in, the return |
|
4532 |
* value will be null. |
|
4533 |
* |
|
4534 |
* @param i the zero-based index of selected items |
|
4535 |
* @return an Accessible containing the selected item |
|
4536 |
*/ |
|
4537 |
public Accessible getAccessibleSelection(int i) { |
|
4538 |
// The JTree can have only one accessible child, the root. |
|
4539 |
if (i == 0) { |
|
4540 |
Object[] rootPath = new Object[1]; |
|
4541 |
rootPath[0] = treeModel.getRoot(); |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4542 |
if (rootPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4543 |
return null; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4544 |
|
2 | 4545 |
TreePath childPath = new TreePath(rootPath); |
4546 |
if (JTree.this.isPathSelected(childPath)) { |
|
4547 |
return new AccessibleJTreeNode(JTree.this, childPath, JTree.this); |
|
4548 |
} |
|
4549 |
} |
|
4550 |
return null; |
|
4551 |
} |
|
4552 |
||
4553 |
/** |
|
4554 |
* Returns true if the current child of this object is selected. |
|
4555 |
* |
|
4556 |
* @param i the zero-based index of the child in this Accessible object. |
|
4557 |
* @see AccessibleContext#getAccessibleChild |
|
4558 |
*/ |
|
4559 |
public boolean isAccessibleChildSelected(int i) { |
|
4560 |
// The JTree can have only one accessible child, the root. |
|
4561 |
if (i == 0) { |
|
4562 |
Object[] rootPath = new Object[1]; |
|
4563 |
rootPath[0] = treeModel.getRoot(); |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4564 |
if (rootPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4565 |
return false; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4566 |
|
2 | 4567 |
TreePath childPath = new TreePath(rootPath); |
4568 |
return JTree.this.isPathSelected(childPath); |
|
4569 |
} else { |
|
4570 |
return false; |
|
4571 |
} |
|
4572 |
} |
|
4573 |
||
4574 |
/** |
|
4575 |
* Adds the specified selected item in the object to the object's |
|
4576 |
* selection. If the object supports multiple selections, |
|
4577 |
* the specified item is added to any existing selection, otherwise |
|
4578 |
* it replaces any existing selection in the object. If the |
|
4579 |
* specified item is already selected, this method has no effect. |
|
4580 |
* |
|
4581 |
* @param i the zero-based index of selectable items |
|
4582 |
*/ |
|
4583 |
public void addAccessibleSelection(int i) { |
|
4584 |
TreeModel model = JTree.this.getModel(); |
|
4585 |
if (model != null) { |
|
4586 |
if (i == 0) { |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4587 |
Object[] objPath = {model.getRoot()}; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4588 |
if (objPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4589 |
return; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4590 |
|
2 | 4591 |
TreePath path = new TreePath(objPath); |
4592 |
JTree.this.addSelectionPath(path); |
|
4593 |
} |
|
4594 |
} |
|
4595 |
} |
|
4596 |
||
4597 |
/** |
|
4598 |
* Removes the specified selected item in the object from the object's |
|
4599 |
* selection. If the specified item isn't currently selected, this |
|
4600 |
* method has no effect. |
|
4601 |
* |
|
4602 |
* @param i the zero-based index of selectable items |
|
4603 |
*/ |
|
4604 |
public void removeAccessibleSelection(int i) { |
|
4605 |
TreeModel model = JTree.this.getModel(); |
|
4606 |
if (model != null) { |
|
4607 |
if (i == 0) { |
|
4608 |
Object[] objPath = {model.getRoot()}; |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4609 |
if (objPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4610 |
return; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4611 |
|
2 | 4612 |
TreePath path = new TreePath(objPath); |
4613 |
JTree.this.removeSelectionPath(path); |
|
4614 |
} |
|
4615 |
} |
|
4616 |
} |
|
4617 |
||
4618 |
/** |
|
4619 |
* Clears the selection in the object, so that nothing in the |
|
4620 |
* object is selected. |
|
4621 |
*/ |
|
4622 |
public void clearAccessibleSelection() { |
|
4623 |
int childCount = getAccessibleChildrenCount(); |
|
4624 |
for (int i = 0; i < childCount; i++) { |
|
4625 |
removeAccessibleSelection(i); |
|
4626 |
} |
|
4627 |
} |
|
4628 |
||
4629 |
/** |
|
4630 |
* Causes every selected item in the object to be selected |
|
4631 |
* if the object supports multiple selections. |
|
4632 |
*/ |
|
4633 |
public void selectAllAccessibleSelection() { |
|
4634 |
TreeModel model = JTree.this.getModel(); |
|
4635 |
if (model != null) { |
|
4636 |
Object[] objPath = {model.getRoot()}; |
|
29250
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4637 |
if (objPath[0] == null) |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4638 |
return; |
f9edd0824de6
8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents:
28059
diff
changeset
|
4639 |
|
2 | 4640 |
TreePath path = new TreePath(objPath); |
4641 |
JTree.this.addSelectionPath(path); |
|
4642 |
} |
|
4643 |
} |
|
4644 |
||
4645 |
/** |
|
4646 |
* This class implements accessibility support for the |
|
4647 |
* <code>JTree</code> child. It provides an implementation of the |
|
4648 |
* Java Accessibility API appropriate to tree nodes. |
|
4649 |
*/ |
|
4650 |
protected class AccessibleJTreeNode extends AccessibleContext |
|
4651 |
implements Accessible, AccessibleComponent, AccessibleSelection, |
|
4652 |
AccessibleAction { |
|
4653 |
||
4654 |
private JTree tree = null; |
|
4655 |
private TreeModel treeModel = null; |
|
4656 |
private Object obj = null; |
|
4657 |
private TreePath path = null; |
|
4658 |
private Accessible accessibleParent = null; |
|
4659 |
private int index = 0; |
|
4660 |
private boolean isLeaf = false; |
|
4661 |
||
4662 |
/** |
|
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4663 |
* Constructs an AccessibleJTreeNode |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4664 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4665 |
* @param t an instance of {@code JTree} |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4666 |
* @param p an instance of {@code TreePath} |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
4667 |
* @param ap an instance of {@code Accessible} |
2 | 4668 |
* @since 1.4 |
4669 |
*/ |
|
4670 |
public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap) { |
|
4671 |
tree = t; |
|
4672 |
path = p; |
|
4673 |
accessibleParent = ap; |
|
4674 |
treeModel = t.getModel(); |
|
4675 |
obj = p.getLastPathComponent(); |
|
4676 |
if (treeModel != null) { |
|
4677 |
isLeaf = treeModel.isLeaf(obj); |
|
4678 |
} |
|
4679 |
} |
|
4680 |
||
4681 |
private TreePath getChildTreePath(int i) { |
|
4682 |
// Tree nodes can't be so complex that they have |
|
4683 |
// two sets of children -> we're ignoring that case |
|
4684 |
if (i < 0 || i >= getAccessibleChildrenCount()) { |
|
4685 |
return null; |
|
4686 |
} else { |
|
4687 |
Object childObj = treeModel.getChild(obj, i); |
|
4688 |
Object[] objPath = path.getPath(); |
|
4689 |
Object[] objChildPath = new Object[objPath.length+1]; |
|
4690 |
java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length); |
|
4691 |
objChildPath[objChildPath.length-1] = childObj; |
|
4692 |
return new TreePath(objChildPath); |
|
4693 |
} |
|
4694 |
} |
|
4695 |
||
4696 |
/** |
|
4697 |
* Get the AccessibleContext associated with this tree node. |
|
4698 |
* In the implementation of the Java Accessibility API for |
|
4699 |
* this class, return this object, which is its own |
|
4700 |
* AccessibleContext. |
|
4701 |
* |
|
4702 |
* @return this object |
|
4703 |
*/ |
|
4704 |
public AccessibleContext getAccessibleContext() { |
|
4705 |
return this; |
|
4706 |
} |
|
4707 |
||
4708 |
private AccessibleContext getCurrentAccessibleContext() { |
|
4709 |
Component c = getCurrentComponent(); |
|
4710 |
if (c instanceof Accessible) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
4711 |
return c.getAccessibleContext(); |
2 | 4712 |
} else { |
4713 |
return null; |
|
4714 |
} |
|
4715 |
} |
|
4716 |
||
4717 |
private Component getCurrentComponent() { |
|
4718 |
// is the object visible? |
|
4719 |
// if so, get row, selected, focus & leaf state, |
|
4720 |
// and then get the renderer component and return it |
|
4721 |
if (tree.isVisible(path)) { |
|
4722 |
TreeCellRenderer r = tree.getCellRenderer(); |
|
4723 |
if (r == null) { |
|
4724 |
return null; |
|
4725 |
} |
|
4726 |
TreeUI ui = tree.getUI(); |
|
4727 |
if (ui != null) { |
|
4728 |
int row = ui.getRowForPath(JTree.this, path); |
|
4729 |
boolean selected = tree.isPathSelected(path); |
|
4730 |
boolean expanded = tree.isExpanded(path); |
|
4731 |
boolean hasFocus = false; // how to tell?? -PK |
|
4732 |
return r.getTreeCellRendererComponent(tree, obj, |
|
4733 |
selected, expanded, isLeaf, row, hasFocus); |
|
4734 |
} |
|
4735 |
} |
|
4736 |
return null; |
|
4737 |
} |
|
4738 |
||
4739 |
// AccessibleContext methods |
|
4740 |
||
4741 |
/** |
|
4742 |
* Get the accessible name of this object. |
|
4743 |
* |
|
4744 |
* @return the localized name of the object; null if this |
|
4745 |
* object does not have a name |
|
4746 |
*/ |
|
4747 |
public String getAccessibleName() { |
|
4748 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4749 |
if (ac != null) { |
|
4750 |
String name = ac.getAccessibleName(); |
|
4751 |
if ((name != null) && (name != "")) { |
|
4752 |
return ac.getAccessibleName(); |
|
4753 |
} else { |
|
4754 |
return null; |
|
4755 |
} |
|
4756 |
} |
|
4757 |
if ((accessibleName != null) && (accessibleName != "")) { |
|
4758 |
return accessibleName; |
|
4759 |
} else { |
|
4760 |
// fall back to the client property |
|
4761 |
return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY); |
|
4762 |
} |
|
4763 |
} |
|
4764 |
||
4765 |
/** |
|
4766 |
* Set the localized accessible name of this object. |
|
4767 |
* |
|
4768 |
* @param s the new localized name of the object. |
|
4769 |
*/ |
|
4770 |
public void setAccessibleName(String s) { |
|
4771 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4772 |
if (ac != null) { |
|
4773 |
ac.setAccessibleName(s); |
|
4774 |
} else { |
|
4775 |
super.setAccessibleName(s); |
|
4776 |
} |
|
4777 |
} |
|
4778 |
||
4779 |
// |
|
4780 |
// *** should check tooltip text for desc. (needs MouseEvent) |
|
4781 |
// |
|
4782 |
/** |
|
4783 |
* Get the accessible description of this object. |
|
4784 |
* |
|
4785 |
* @return the localized description of the object; null if |
|
4786 |
* this object does not have a description |
|
4787 |
*/ |
|
4788 |
public String getAccessibleDescription() { |
|
4789 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4790 |
if (ac != null) { |
|
4791 |
return ac.getAccessibleDescription(); |
|
4792 |
} else { |
|
4793 |
return super.getAccessibleDescription(); |
|
4794 |
} |
|
4795 |
} |
|
4796 |
||
4797 |
/** |
|
4798 |
* Set the accessible description of this object. |
|
4799 |
* |
|
4800 |
* @param s the new localized description of the object |
|
4801 |
*/ |
|
4802 |
public void setAccessibleDescription(String s) { |
|
4803 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4804 |
if (ac != null) { |
|
4805 |
ac.setAccessibleDescription(s); |
|
4806 |
} else { |
|
4807 |
super.setAccessibleDescription(s); |
|
4808 |
} |
|
4809 |
} |
|
4810 |
||
4811 |
/** |
|
4812 |
* Get the role of this object. |
|
4813 |
* |
|
4814 |
* @return an instance of AccessibleRole describing the role of the object |
|
4815 |
* @see AccessibleRole |
|
4816 |
*/ |
|
4817 |
public AccessibleRole getAccessibleRole() { |
|
4818 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4819 |
if (ac != null) { |
|
4820 |
return ac.getAccessibleRole(); |
|
4821 |
} else { |
|
4822 |
return AccessibleRole.UNKNOWN; |
|
4823 |
} |
|
4824 |
} |
|
4825 |
||
4826 |
/** |
|
4827 |
* Get the state set of this object. |
|
4828 |
* |
|
4829 |
* @return an instance of AccessibleStateSet containing the |
|
4830 |
* current state set of the object |
|
4831 |
* @see AccessibleState |
|
4832 |
*/ |
|
4833 |
public AccessibleStateSet getAccessibleStateSet() { |
|
4834 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4835 |
AccessibleStateSet states; |
|
4836 |
if (ac != null) { |
|
4837 |
states = ac.getAccessibleStateSet(); |
|
4838 |
} else { |
|
4839 |
states = new AccessibleStateSet(); |
|
4840 |
} |
|
4841 |
// need to test here, 'cause the underlying component |
|
4842 |
// is a cellRenderer, which is never showing... |
|
4843 |
if (isShowing()) { |
|
4844 |
states.add(AccessibleState.SHOWING); |
|
4845 |
} else if (states.contains(AccessibleState.SHOWING)) { |
|
4846 |
states.remove(AccessibleState.SHOWING); |
|
4847 |
} |
|
4848 |
if (isVisible()) { |
|
4849 |
states.add(AccessibleState.VISIBLE); |
|
4850 |
} else if (states.contains(AccessibleState.VISIBLE)) { |
|
4851 |
states.remove(AccessibleState.VISIBLE); |
|
4852 |
} |
|
4853 |
if (tree.isPathSelected(path)){ |
|
4854 |
states.add(AccessibleState.SELECTED); |
|
4855 |
} |
|
4856 |
if (path == getLeadSelectionPath()) { |
|
4857 |
states.add(AccessibleState.ACTIVE); |
|
4858 |
} |
|
4859 |
if (!isLeaf) { |
|
4860 |
states.add(AccessibleState.EXPANDABLE); |
|
4861 |
} |
|
4862 |
if (tree.isExpanded(path)) { |
|
4863 |
states.add(AccessibleState.EXPANDED); |
|
4864 |
} else { |
|
4865 |
states.add(AccessibleState.COLLAPSED); |
|
4866 |
} |
|
4867 |
if (tree.isEditable()) { |
|
4868 |
states.add(AccessibleState.EDITABLE); |
|
4869 |
} |
|
4870 |
return states; |
|
4871 |
} |
|
4872 |
||
4873 |
/** |
|
4874 |
* Get the Accessible parent of this object. |
|
4875 |
* |
|
4876 |
* @return the Accessible parent of this object; null if this |
|
4877 |
* object does not have an Accessible parent |
|
4878 |
*/ |
|
4879 |
public Accessible getAccessibleParent() { |
|
4880 |
// someone wants to know, so we need to create our parent |
|
4881 |
// if we don't have one (hey, we're a talented kid!) |
|
4882 |
if (accessibleParent == null) { |
|
4883 |
Object[] objPath = path.getPath(); |
|
4884 |
if (objPath.length > 1) { |
|
4885 |
Object objParent = objPath[objPath.length-2]; |
|
4886 |
if (treeModel != null) { |
|
4887 |
index = treeModel.getIndexOfChild(objParent, obj); |
|
4888 |
} |
|
4889 |
Object[] objParentPath = new Object[objPath.length-1]; |
|
4890 |
java.lang.System.arraycopy(objPath, 0, objParentPath, |
|
4891 |
0, objPath.length-1); |
|
4892 |
TreePath parentPath = new TreePath(objParentPath); |
|
4893 |
accessibleParent = new AccessibleJTreeNode(tree, |
|
4894 |
parentPath, |
|
4895 |
null); |
|
4896 |
this.setAccessibleParent(accessibleParent); |
|
4897 |
} else if (treeModel != null) { |
|
4898 |
accessibleParent = tree; // we're the top! |
|
4899 |
index = 0; // we're an only child! |
|
4900 |
this.setAccessibleParent(accessibleParent); |
|
4901 |
} |
|
4902 |
} |
|
4903 |
return accessibleParent; |
|
4904 |
} |
|
4905 |
||
4906 |
/** |
|
4907 |
* Get the index of this object in its accessible parent. |
|
4908 |
* |
|
4909 |
* @return the index of this object in its parent; -1 if this |
|
4910 |
* object does not have an accessible parent. |
|
4911 |
* @see #getAccessibleParent |
|
4912 |
*/ |
|
4913 |
public int getAccessibleIndexInParent() { |
|
4914 |
// index is invalid 'till we have an accessibleParent... |
|
4915 |
if (accessibleParent == null) { |
|
4916 |
getAccessibleParent(); |
|
4917 |
} |
|
4918 |
Object[] objPath = path.getPath(); |
|
4919 |
if (objPath.length > 1) { |
|
4920 |
Object objParent = objPath[objPath.length-2]; |
|
4921 |
if (treeModel != null) { |
|
4922 |
index = treeModel.getIndexOfChild(objParent, obj); |
|
4923 |
} |
|
4924 |
} |
|
4925 |
return index; |
|
4926 |
} |
|
4927 |
||
4928 |
/** |
|
4929 |
* Returns the number of accessible children in the object. |
|
4930 |
* |
|
4931 |
* @return the number of accessible children in the object. |
|
4932 |
*/ |
|
4933 |
public int getAccessibleChildrenCount() { |
|
4934 |
// Tree nodes can't be so complex that they have |
|
4935 |
// two sets of children -> we're ignoring that case |
|
4936 |
return treeModel.getChildCount(obj); |
|
4937 |
} |
|
4938 |
||
4939 |
/** |
|
4940 |
* Return the specified Accessible child of the object. |
|
4941 |
* |
|
4942 |
* @param i zero-based index of child |
|
4943 |
* @return the Accessible child of the object |
|
4944 |
*/ |
|
4945 |
public Accessible getAccessibleChild(int i) { |
|
4946 |
// Tree nodes can't be so complex that they have |
|
4947 |
// two sets of children -> we're ignoring that case |
|
4948 |
if (i < 0 || i >= getAccessibleChildrenCount()) { |
|
4949 |
return null; |
|
4950 |
} else { |
|
4951 |
Object childObj = treeModel.getChild(obj, i); |
|
4952 |
Object[] objPath = path.getPath(); |
|
4953 |
Object[] objChildPath = new Object[objPath.length+1]; |
|
4954 |
java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length); |
|
4955 |
objChildPath[objChildPath.length-1] = childObj; |
|
4956 |
TreePath childPath = new TreePath(objChildPath); |
|
4957 |
return new AccessibleJTreeNode(JTree.this, childPath, this); |
|
4958 |
} |
|
4959 |
} |
|
4960 |
||
4961 |
/** |
|
4962 |
* Gets the locale of the component. If the component does not have |
|
4963 |
* a locale, then the locale of its parent is returned. |
|
4964 |
* |
|
4965 |
* @return This component's locale. If this component does not have |
|
4966 |
* a locale, the locale of its parent is returned. |
|
4967 |
* @exception IllegalComponentStateException |
|
4968 |
* If the Component does not have its own locale and has not yet |
|
4969 |
* been added to a containment hierarchy such that the locale can be |
|
4970 |
* determined from the containing parent. |
|
4971 |
* @see #setLocale |
|
4972 |
*/ |
|
4973 |
public Locale getLocale() { |
|
4974 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4975 |
if (ac != null) { |
|
4976 |
return ac.getLocale(); |
|
4977 |
} else { |
|
4978 |
return tree.getLocale(); |
|
4979 |
} |
|
4980 |
} |
|
4981 |
||
4982 |
/** |
|
4983 |
* Add a PropertyChangeListener to the listener list. |
|
4984 |
* The listener is registered for all properties. |
|
4985 |
* |
|
4986 |
* @param l The PropertyChangeListener to be added |
|
4987 |
*/ |
|
4988 |
public void addPropertyChangeListener(PropertyChangeListener l) { |
|
4989 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
4990 |
if (ac != null) { |
|
4991 |
ac.addPropertyChangeListener(l); |
|
4992 |
} else { |
|
4993 |
super.addPropertyChangeListener(l); |
|
4994 |
} |
|
4995 |
} |
|
4996 |
||
4997 |
/** |
|
4998 |
* Remove a PropertyChangeListener from the listener list. |
|
4999 |
* This removes a PropertyChangeListener that was registered |
|
5000 |
* for all properties. |
|
5001 |
* |
|
5002 |
* @param l The PropertyChangeListener to be removed |
|
5003 |
*/ |
|
5004 |
public void removePropertyChangeListener(PropertyChangeListener l) { |
|
5005 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5006 |
if (ac != null) { |
|
5007 |
ac.removePropertyChangeListener(l); |
|
5008 |
} else { |
|
5009 |
super.removePropertyChangeListener(l); |
|
5010 |
} |
|
5011 |
} |
|
5012 |
||
5013 |
/** |
|
5014 |
* Get the AccessibleAction associated with this object. In the |
|
5015 |
* implementation of the Java Accessibility API for this class, |
|
5016 |
* return this object, which is responsible for implementing the |
|
5017 |
* AccessibleAction interface on behalf of itself. |
|
5018 |
* |
|
5019 |
* @return this object |
|
5020 |
*/ |
|
5021 |
public AccessibleAction getAccessibleAction() { |
|
5022 |
return this; |
|
5023 |
} |
|
5024 |
||
5025 |
/** |
|
5026 |
* Get the AccessibleComponent associated with this object. In the |
|
5027 |
* implementation of the Java Accessibility API for this class, |
|
5028 |
* return this object, which is responsible for implementing the |
|
5029 |
* AccessibleComponent interface on behalf of itself. |
|
5030 |
* |
|
5031 |
* @return this object |
|
5032 |
*/ |
|
5033 |
public AccessibleComponent getAccessibleComponent() { |
|
5034 |
return this; // to override getBounds() |
|
5035 |
} |
|
5036 |
||
5037 |
/** |
|
5038 |
* Get the AccessibleSelection associated with this object if one |
|
5039 |
* exists. Otherwise return null. |
|
5040 |
* |
|
5041 |
* @return the AccessibleSelection, or null |
|
5042 |
*/ |
|
5043 |
public AccessibleSelection getAccessibleSelection() { |
|
5044 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5045 |
if (ac != null && isLeaf) { |
|
5046 |
return getCurrentAccessibleContext().getAccessibleSelection(); |
|
5047 |
} else { |
|
5048 |
return this; |
|
5049 |
} |
|
5050 |
} |
|
5051 |
||
5052 |
/** |
|
5053 |
* Get the AccessibleText associated with this object if one |
|
5054 |
* exists. Otherwise return null. |
|
5055 |
* |
|
5056 |
* @return the AccessibleText, or null |
|
5057 |
*/ |
|
5058 |
public AccessibleText getAccessibleText() { |
|
5059 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5060 |
if (ac != null) { |
|
5061 |
return getCurrentAccessibleContext().getAccessibleText(); |
|
5062 |
} else { |
|
5063 |
return null; |
|
5064 |
} |
|
5065 |
} |
|
5066 |
||
5067 |
/** |
|
5068 |
* Get the AccessibleValue associated with this object if one |
|
5069 |
* exists. Otherwise return null. |
|
5070 |
* |
|
5071 |
* @return the AccessibleValue, or null |
|
5072 |
*/ |
|
5073 |
public AccessibleValue getAccessibleValue() { |
|
5074 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5075 |
if (ac != null) { |
|
5076 |
return getCurrentAccessibleContext().getAccessibleValue(); |
|
5077 |
} else { |
|
5078 |
return null; |
|
5079 |
} |
|
5080 |
} |
|
5081 |
||
5082 |
||
5083 |
// AccessibleComponent methods |
|
5084 |
||
5085 |
/** |
|
5086 |
* Get the background color of this object. |
|
5087 |
* |
|
5088 |
* @return the background color, if supported, of the object; |
|
5089 |
* otherwise, null |
|
5090 |
*/ |
|
5091 |
public Color getBackground() { |
|
5092 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5093 |
if (ac instanceof AccessibleComponent) { |
|
5094 |
return ((AccessibleComponent) ac).getBackground(); |
|
5095 |
} else { |
|
5096 |
Component c = getCurrentComponent(); |
|
5097 |
if (c != null) { |
|
5098 |
return c.getBackground(); |
|
5099 |
} else { |
|
5100 |
return null; |
|
5101 |
} |
|
5102 |
} |
|
5103 |
} |
|
5104 |
||
5105 |
/** |
|
5106 |
* Set the background color of this object. |
|
5107 |
* |
|
5108 |
* @param c the new Color for the background |
|
5109 |
*/ |
|
5110 |
public void setBackground(Color c) { |
|
5111 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5112 |
if (ac instanceof AccessibleComponent) { |
|
5113 |
((AccessibleComponent) ac).setBackground(c); |
|
5114 |
} else { |
|
5115 |
Component cp = getCurrentComponent(); |
|
5116 |
if (cp != null) { |
|
5117 |
cp.setBackground(c); |
|
5118 |
} |
|
5119 |
} |
|
5120 |
} |
|
5121 |
||
5122 |
||
5123 |
/** |
|
5124 |
* Get the foreground color of this object. |
|
5125 |
* |
|
5126 |
* @return the foreground color, if supported, of the object; |
|
5127 |
* otherwise, null |
|
5128 |
*/ |
|
5129 |
public Color getForeground() { |
|
5130 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5131 |
if (ac instanceof AccessibleComponent) { |
|
5132 |
return ((AccessibleComponent) ac).getForeground(); |
|
5133 |
} else { |
|
5134 |
Component c = getCurrentComponent(); |
|
5135 |
if (c != null) { |
|
5136 |
return c.getForeground(); |
|
5137 |
} else { |
|
5138 |
return null; |
|
5139 |
} |
|
5140 |
} |
|
5141 |
} |
|
5142 |
||
5143 |
public void setForeground(Color c) { |
|
5144 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5145 |
if (ac instanceof AccessibleComponent) { |
|
5146 |
((AccessibleComponent) ac).setForeground(c); |
|
5147 |
} else { |
|
5148 |
Component cp = getCurrentComponent(); |
|
5149 |
if (cp != null) { |
|
5150 |
cp.setForeground(c); |
|
5151 |
} |
|
5152 |
} |
|
5153 |
} |
|
5154 |
||
5155 |
public Cursor getCursor() { |
|
5156 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5157 |
if (ac instanceof AccessibleComponent) { |
|
5158 |
return ((AccessibleComponent) ac).getCursor(); |
|
5159 |
} else { |
|
5160 |
Component c = getCurrentComponent(); |
|
5161 |
if (c != null) { |
|
5162 |
return c.getCursor(); |
|
5163 |
} else { |
|
5164 |
Accessible ap = getAccessibleParent(); |
|
5165 |
if (ap instanceof AccessibleComponent) { |
|
5166 |
return ((AccessibleComponent) ap).getCursor(); |
|
5167 |
} else { |
|
5168 |
return null; |
|
5169 |
} |
|
5170 |
} |
|
5171 |
} |
|
5172 |
} |
|
5173 |
||
5174 |
public void setCursor(Cursor c) { |
|
5175 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5176 |
if (ac instanceof AccessibleComponent) { |
|
5177 |
((AccessibleComponent) ac).setCursor(c); |
|
5178 |
} else { |
|
5179 |
Component cp = getCurrentComponent(); |
|
5180 |
if (cp != null) { |
|
5181 |
cp.setCursor(c); |
|
5182 |
} |
|
5183 |
} |
|
5184 |
} |
|
5185 |
||
5186 |
public Font getFont() { |
|
5187 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5188 |
if (ac instanceof AccessibleComponent) { |
|
5189 |
return ((AccessibleComponent) ac).getFont(); |
|
5190 |
} else { |
|
5191 |
Component c = getCurrentComponent(); |
|
5192 |
if (c != null) { |
|
5193 |
return c.getFont(); |
|
5194 |
} else { |
|
5195 |
return null; |
|
5196 |
} |
|
5197 |
} |
|
5198 |
} |
|
5199 |
||
5200 |
public void setFont(Font f) { |
|
5201 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5202 |
if (ac instanceof AccessibleComponent) { |
|
5203 |
((AccessibleComponent) ac).setFont(f); |
|
5204 |
} else { |
|
5205 |
Component c = getCurrentComponent(); |
|
5206 |
if (c != null) { |
|
5207 |
c.setFont(f); |
|
5208 |
} |
|
5209 |
} |
|
5210 |
} |
|
5211 |
||
5212 |
public FontMetrics getFontMetrics(Font f) { |
|
5213 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5214 |
if (ac instanceof AccessibleComponent) { |
|
5215 |
return ((AccessibleComponent) ac).getFontMetrics(f); |
|
5216 |
} else { |
|
5217 |
Component c = getCurrentComponent(); |
|
5218 |
if (c != null) { |
|
5219 |
return c.getFontMetrics(f); |
|
5220 |
} else { |
|
5221 |
return null; |
|
5222 |
} |
|
5223 |
} |
|
5224 |
} |
|
5225 |
||
5226 |
public boolean isEnabled() { |
|
5227 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5228 |
if (ac instanceof AccessibleComponent) { |
|
5229 |
return ((AccessibleComponent) ac).isEnabled(); |
|
5230 |
} else { |
|
5231 |
Component c = getCurrentComponent(); |
|
5232 |
if (c != null) { |
|
5233 |
return c.isEnabled(); |
|
5234 |
} else { |
|
5235 |
return false; |
|
5236 |
} |
|
5237 |
} |
|
5238 |
} |
|
5239 |
||
5240 |
public void setEnabled(boolean b) { |
|
5241 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5242 |
if (ac instanceof AccessibleComponent) { |
|
5243 |
((AccessibleComponent) ac).setEnabled(b); |
|
5244 |
} else { |
|
5245 |
Component c = getCurrentComponent(); |
|
5246 |
if (c != null) { |
|
5247 |
c.setEnabled(b); |
|
5248 |
} |
|
5249 |
} |
|
5250 |
} |
|
5251 |
||
5252 |
public boolean isVisible() { |
|
5253 |
Rectangle pathBounds = tree.getPathBounds(path); |
|
5254 |
Rectangle parentBounds = tree.getVisibleRect(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
5255 |
return pathBounds != null && parentBounds != null && |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
5256 |
parentBounds.intersects(pathBounds); |
2 | 5257 |
} |
5258 |
||
5259 |
public void setVisible(boolean b) { |
|
5260 |
} |
|
5261 |
||
5262 |
public boolean isShowing() { |
|
5263 |
return (tree.isShowing() && isVisible()); |
|
5264 |
} |
|
5265 |
||
5266 |
public boolean contains(Point p) { |
|
5267 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5268 |
if (ac instanceof AccessibleComponent) { |
|
5269 |
Rectangle r = ((AccessibleComponent) ac).getBounds(); |
|
5270 |
return r.contains(p); |
|
5271 |
} else { |
|
5272 |
Component c = getCurrentComponent(); |
|
5273 |
if (c != null) { |
|
5274 |
Rectangle r = c.getBounds(); |
|
5275 |
return r.contains(p); |
|
5276 |
} else { |
|
5277 |
return getBounds().contains(p); |
|
5278 |
} |
|
5279 |
} |
|
5280 |
} |
|
5281 |
||
5282 |
public Point getLocationOnScreen() { |
|
5283 |
if (tree != null) { |
|
5284 |
Point treeLocation = tree.getLocationOnScreen(); |
|
5285 |
Rectangle pathBounds = tree.getPathBounds(path); |
|
5286 |
if (treeLocation != null && pathBounds != null) { |
|
5287 |
Point nodeLocation = new Point(pathBounds.x, |
|
5288 |
pathBounds.y); |
|
5289 |
nodeLocation.translate(treeLocation.x, treeLocation.y); |
|
5290 |
return nodeLocation; |
|
5291 |
} else { |
|
5292 |
return null; |
|
5293 |
} |
|
5294 |
} else { |
|
5295 |
return null; |
|
5296 |
} |
|
5297 |
} |
|
5298 |
||
24983
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
5299 |
/** |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
5300 |
* Returns the relative location of the node |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
5301 |
* |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
5302 |
* @return the relative location of the node |
f5a6e2ed8c7d
8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents:
24187
diff
changeset
|
5303 |
*/ |
2 | 5304 |
protected Point getLocationInJTree() { |
5305 |
Rectangle r = tree.getPathBounds(path); |
|
5306 |
if (r != null) { |
|
5307 |
return r.getLocation(); |
|
5308 |
} else { |
|
5309 |
return null; |
|
5310 |
} |
|
5311 |
} |
|
5312 |
||
5313 |
public Point getLocation() { |
|
5314 |
Rectangle r = getBounds(); |
|
5315 |
if (r != null) { |
|
5316 |
return r.getLocation(); |
|
5317 |
} else { |
|
5318 |
return null; |
|
5319 |
} |
|
5320 |
} |
|
5321 |
||
5322 |
public void setLocation(Point p) { |
|
5323 |
} |
|
5324 |
||
5325 |
public Rectangle getBounds() { |
|
5326 |
Rectangle r = tree.getPathBounds(path); |
|
5327 |
Accessible parent = getAccessibleParent(); |
|
5328 |
if (parent != null) { |
|
5329 |
if (parent instanceof AccessibleJTreeNode) { |
|
5330 |
Point parentLoc = ((AccessibleJTreeNode) parent).getLocationInJTree(); |
|
5331 |
if (parentLoc != null && r != null) { |
|
5332 |
r.translate(-parentLoc.x, -parentLoc.y); |
|
5333 |
} else { |
|
5334 |
return null; // not visible! |
|
5335 |
} |
|
5336 |
} |
|
5337 |
} |
|
5338 |
return r; |
|
5339 |
} |
|
5340 |
||
5341 |
public void setBounds(Rectangle r) { |
|
5342 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5343 |
if (ac instanceof AccessibleComponent) { |
|
5344 |
((AccessibleComponent) ac).setBounds(r); |
|
5345 |
} else { |
|
5346 |
Component c = getCurrentComponent(); |
|
5347 |
if (c != null) { |
|
5348 |
c.setBounds(r); |
|
5349 |
} |
|
5350 |
} |
|
5351 |
} |
|
5352 |
||
5353 |
public Dimension getSize() { |
|
5354 |
return getBounds().getSize(); |
|
5355 |
} |
|
5356 |
||
5357 |
public void setSize (Dimension d) { |
|
5358 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5359 |
if (ac instanceof AccessibleComponent) { |
|
5360 |
((AccessibleComponent) ac).setSize(d); |
|
5361 |
} else { |
|
5362 |
Component c = getCurrentComponent(); |
|
5363 |
if (c != null) { |
|
5364 |
c.setSize(d); |
|
5365 |
} |
|
5366 |
} |
|
5367 |
} |
|
5368 |
||
5369 |
/** |
|
5370 |
* Returns the <code>Accessible</code> child, if one exists, |
|
5371 |
* contained at the local coordinate <code>Point</code>. |
|
5372 |
* Otherwise returns <code>null</code>. |
|
5373 |
* |
|
5374 |
* @param p point in local coordinates of this |
|
5375 |
* <code>Accessible</code> |
|
5376 |
* @return the <code>Accessible</code>, if it exists, |
|
5377 |
* at the specified location; else <code>null</code> |
|
5378 |
*/ |
|
5379 |
public Accessible getAccessibleAt(Point p) { |
|
5380 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5381 |
if (ac instanceof AccessibleComponent) { |
|
5382 |
return ((AccessibleComponent) ac).getAccessibleAt(p); |
|
5383 |
} else { |
|
5384 |
return null; |
|
5385 |
} |
|
5386 |
} |
|
5387 |
||
11268 | 5388 |
@SuppressWarnings("deprecation") |
2 | 5389 |
public boolean isFocusTraversable() { |
5390 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5391 |
if (ac instanceof AccessibleComponent) { |
|
5392 |
return ((AccessibleComponent) ac).isFocusTraversable(); |
|
5393 |
} else { |
|
5394 |
Component c = getCurrentComponent(); |
|
5395 |
if (c != null) { |
|
5396 |
return c.isFocusTraversable(); |
|
5397 |
} else { |
|
5398 |
return false; |
|
5399 |
} |
|
5400 |
} |
|
5401 |
} |
|
5402 |
||
5403 |
public void requestFocus() { |
|
5404 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5405 |
if (ac instanceof AccessibleComponent) { |
|
5406 |
((AccessibleComponent) ac).requestFocus(); |
|
5407 |
} else { |
|
5408 |
Component c = getCurrentComponent(); |
|
5409 |
if (c != null) { |
|
5410 |
c.requestFocus(); |
|
5411 |
} |
|
5412 |
} |
|
5413 |
} |
|
5414 |
||
5415 |
public void addFocusListener(FocusListener l) { |
|
5416 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5417 |
if (ac instanceof AccessibleComponent) { |
|
5418 |
((AccessibleComponent) ac).addFocusListener(l); |
|
5419 |
} else { |
|
5420 |
Component c = getCurrentComponent(); |
|
5421 |
if (c != null) { |
|
5422 |
c.addFocusListener(l); |
|
5423 |
} |
|
5424 |
} |
|
5425 |
} |
|
5426 |
||
5427 |
public void removeFocusListener(FocusListener l) { |
|
5428 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5429 |
if (ac instanceof AccessibleComponent) { |
|
5430 |
((AccessibleComponent) ac).removeFocusListener(l); |
|
5431 |
} else { |
|
5432 |
Component c = getCurrentComponent(); |
|
5433 |
if (c != null) { |
|
5434 |
c.removeFocusListener(l); |
|
5435 |
} |
|
5436 |
} |
|
5437 |
} |
|
5438 |
||
5439 |
// AccessibleSelection methods |
|
5440 |
||
5441 |
/** |
|
5442 |
* Returns the number of items currently selected. |
|
5443 |
* If no items are selected, the return value will be 0. |
|
5444 |
* |
|
5445 |
* @return the number of items currently selected. |
|
5446 |
*/ |
|
5447 |
public int getAccessibleSelectionCount() { |
|
5448 |
int count = 0; |
|
5449 |
int childCount = getAccessibleChildrenCount(); |
|
5450 |
for (int i = 0; i < childCount; i++) { |
|
5451 |
TreePath childPath = getChildTreePath(i); |
|
5452 |
if (tree.isPathSelected(childPath)) { |
|
5453 |
count++; |
|
5454 |
} |
|
5455 |
} |
|
5456 |
return count; |
|
5457 |
} |
|
5458 |
||
5459 |
/** |
|
5460 |
* Returns an Accessible representing the specified selected item |
|
5461 |
* in the object. If there isn't a selection, or there are |
|
5462 |
* fewer items selected than the integer passed in, the return |
|
5463 |
* value will be null. |
|
5464 |
* |
|
5465 |
* @param i the zero-based index of selected items |
|
5466 |
* @return an Accessible containing the selected item |
|
5467 |
*/ |
|
5468 |
public Accessible getAccessibleSelection(int i) { |
|
5469 |
int childCount = getAccessibleChildrenCount(); |
|
5470 |
if (i < 0 || i >= childCount) { |
|
5471 |
return null; // out of range |
|
5472 |
} |
|
5473 |
int count = 0; |
|
5474 |
for (int j = 0; j < childCount && i >= count; j++) { |
|
5475 |
TreePath childPath = getChildTreePath(j); |
|
5476 |
if (tree.isPathSelected(childPath)) { |
|
5477 |
if (count == i) { |
|
5478 |
return new AccessibleJTreeNode(tree, childPath, this); |
|
5479 |
} else { |
|
5480 |
count++; |
|
5481 |
} |
|
5482 |
} |
|
5483 |
} |
|
5484 |
return null; |
|
5485 |
} |
|
5486 |
||
5487 |
/** |
|
5488 |
* Returns true if the current child of this object is selected. |
|
5489 |
* |
|
5490 |
* @param i the zero-based index of the child in this Accessible |
|
5491 |
* object. |
|
5492 |
* @see AccessibleContext#getAccessibleChild |
|
5493 |
*/ |
|
5494 |
public boolean isAccessibleChildSelected(int i) { |
|
5495 |
int childCount = getAccessibleChildrenCount(); |
|
5496 |
if (i < 0 || i >= childCount) { |
|
5497 |
return false; // out of range |
|
5498 |
} else { |
|
5499 |
TreePath childPath = getChildTreePath(i); |
|
5500 |
return tree.isPathSelected(childPath); |
|
5501 |
} |
|
5502 |
} |
|
5503 |
||
5504 |
/** |
|
5505 |
* Adds the specified selected item in the object to the object's |
|
5506 |
* selection. If the object supports multiple selections, |
|
5507 |
* the specified item is added to any existing selection, otherwise |
|
5508 |
* it replaces any existing selection in the object. If the |
|
5509 |
* specified item is already selected, this method has no effect. |
|
5510 |
* |
|
5511 |
* @param i the zero-based index of selectable items |
|
5512 |
*/ |
|
5513 |
public void addAccessibleSelection(int i) { |
|
5514 |
TreeModel model = JTree.this.getModel(); |
|
5515 |
if (model != null) { |
|
5516 |
if (i >= 0 && i < getAccessibleChildrenCount()) { |
|
5517 |
TreePath path = getChildTreePath(i); |
|
5518 |
JTree.this.addSelectionPath(path); |
|
5519 |
} |
|
5520 |
} |
|
5521 |
} |
|
5522 |
||
5523 |
/** |
|
5524 |
* Removes the specified selected item in the object from the |
|
5525 |
* object's |
|
5526 |
* selection. If the specified item isn't currently selected, this |
|
5527 |
* method has no effect. |
|
5528 |
* |
|
5529 |
* @param i the zero-based index of selectable items |
|
5530 |
*/ |
|
5531 |
public void removeAccessibleSelection(int i) { |
|
5532 |
TreeModel model = JTree.this.getModel(); |
|
5533 |
if (model != null) { |
|
5534 |
if (i >= 0 && i < getAccessibleChildrenCount()) { |
|
5535 |
TreePath path = getChildTreePath(i); |
|
5536 |
JTree.this.removeSelectionPath(path); |
|
5537 |
} |
|
5538 |
} |
|
5539 |
} |
|
5540 |
||
5541 |
/** |
|
5542 |
* Clears the selection in the object, so that nothing in the |
|
5543 |
* object is selected. |
|
5544 |
*/ |
|
5545 |
public void clearAccessibleSelection() { |
|
5546 |
int childCount = getAccessibleChildrenCount(); |
|
5547 |
for (int i = 0; i < childCount; i++) { |
|
5548 |
removeAccessibleSelection(i); |
|
5549 |
} |
|
5550 |
} |
|
5551 |
||
5552 |
/** |
|
5553 |
* Causes every selected item in the object to be selected |
|
5554 |
* if the object supports multiple selections. |
|
5555 |
*/ |
|
5556 |
public void selectAllAccessibleSelection() { |
|
5557 |
TreeModel model = JTree.this.getModel(); |
|
5558 |
if (model != null) { |
|
5559 |
int childCount = getAccessibleChildrenCount(); |
|
5560 |
TreePath path; |
|
5561 |
for (int i = 0; i < childCount; i++) { |
|
5562 |
path = getChildTreePath(i); |
|
5563 |
JTree.this.addSelectionPath(path); |
|
5564 |
} |
|
5565 |
} |
|
5566 |
} |
|
5567 |
||
5568 |
// AccessibleAction methods |
|
5569 |
||
5570 |
/** |
|
5571 |
* Returns the number of accessible actions available in this |
|
5572 |
* tree node. If this node is not a leaf, there is at least |
|
5573 |
* one action (toggle expand), in addition to any available |
|
5574 |
* on the object behind the TreeCellRenderer. |
|
5575 |
* |
|
5576 |
* @return the number of Actions in this object |
|
5577 |
*/ |
|
5578 |
public int getAccessibleActionCount() { |
|
5579 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5580 |
if (ac != null) { |
|
5581 |
AccessibleAction aa = ac.getAccessibleAction(); |
|
5582 |
if (aa != null) { |
|
5583 |
return (aa.getAccessibleActionCount() + (isLeaf ? 0 : 1)); |
|
5584 |
} |
|
5585 |
} |
|
5586 |
return isLeaf ? 0 : 1; |
|
5587 |
} |
|
5588 |
||
5589 |
/** |
|
5590 |
* Return a description of the specified action of the tree node. |
|
5591 |
* If this node is not a leaf, there is at least one action |
|
5592 |
* description (toggle expand), in addition to any available |
|
5593 |
* on the object behind the TreeCellRenderer. |
|
5594 |
* |
|
5595 |
* @param i zero-based index of the actions |
|
5596 |
* @return a description of the action |
|
5597 |
*/ |
|
5598 |
public String getAccessibleActionDescription(int i) { |
|
5599 |
if (i < 0 || i >= getAccessibleActionCount()) { |
|
5600 |
return null; |
|
5601 |
} |
|
5602 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5603 |
if (i == 0) { |
|
5604 |
// TIGER - 4766636 |
|
5605 |
return AccessibleAction.TOGGLE_EXPAND; |
|
5606 |
} else if (ac != null) { |
|
5607 |
AccessibleAction aa = ac.getAccessibleAction(); |
|
5608 |
if (aa != null) { |
|
5609 |
return aa.getAccessibleActionDescription(i - 1); |
|
5610 |
} |
|
5611 |
} |
|
5612 |
return null; |
|
5613 |
} |
|
5614 |
||
5615 |
/** |
|
5616 |
* Perform the specified Action on the tree node. If this node |
|
5617 |
* is not a leaf, there is at least one action which can be |
|
5618 |
* done (toggle expand), in addition to any available on the |
|
5619 |
* object behind the TreeCellRenderer. |
|
5620 |
* |
|
5621 |
* @param i zero-based index of actions |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
26037
diff
changeset
|
5622 |
* @return true if the action was performed; else false. |
2 | 5623 |
*/ |
5624 |
public boolean doAccessibleAction(int i) { |
|
5625 |
if (i < 0 || i >= getAccessibleActionCount()) { |
|
5626 |
return false; |
|
5627 |
} |
|
5628 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
5629 |
if (i == 0) { |
|
5630 |
if (JTree.this.isExpanded(path)) { |
|
5631 |
JTree.this.collapsePath(path); |
|
5632 |
} else { |
|
5633 |
JTree.this.expandPath(path); |
|
5634 |
} |
|
5635 |
return true; |
|
5636 |
} else if (ac != null) { |
|
5637 |
AccessibleAction aa = ac.getAccessibleAction(); |
|
5638 |
if (aa != null) { |
|
5639 |
return aa.doAccessibleAction(i - 1); |
|
5640 |
} |
|
5641 |
} |
|
5642 |
return false; |
|
5643 |
} |
|
5644 |
||
5645 |
} // inner class AccessibleJTreeNode |
|
5646 |
||
5647 |
} // inner class AccessibleJTree |
|
5648 |
||
5649 |
} // End of class JTree |