-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
x86
-
linux
Name: jl125535 Date: 05/20/2002
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)Java
HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
Verified in 1.4.
A DESCRIPTION OF THE PROBLEM :
The utility class javax.swing.JTree.DynamicUtilTreeNode
can be used to convert Vector and Hashtable objects to tree
nodes. (See the javadoc for the constructor.)
It could be generalized so that it supports the more generic
Map and List interfaces. This should not interfere with the
existing functionality since the generalization is straightforward
(see the Source section below).
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
I adapted the code and the javadocs of the JTree.java file of JDK1.4 beta3 (to
co). I changed some occurrences of Vector and HashTable to List and Map.
Note that i'm not proficient with the diff tool, but I included an output to
highlight the differences below. (I intended to include the adapted JTree.java
file, but your bug database script does not seem to accept such a long text).
Note that the diff is meant to describe the change I want to be made, I have not
used the adapted version.
//////////////////////////// diff -C 2 of JTree.java /////////////////////
*** JTree.java Tue Jan 15 00:10:25 2002
--- /tmp/java/javax/swing/JTree.java Sat Oct 20 09:15:03 2001
***************
*** 375,380 ****
* If the object is:<ul>
* <li>an array of <code>Object</code>s,
! * <li>a <code>Map</code>, or
! * <li>a <code>java.util.List</code>
* </ul>then a new root node is created with each of the incoming
* objects as children. Otherwise, a new root is created with the
--- 375,380 ----
* If the object is:<ul>
* <li>an array of <code>Object</code>s,
! * <li>a <code>Hashtable</code>, or
! * <li>a <code>Vector</code>
* </ul>then a new root node is created with each of the incoming
* objects as children. Otherwise, a new root is created with the
***************
*** 388,393 ****
DefaultMutableTreeNode root;
! if((value instanceof Object[]) || (value instanceof Map) ||
! (value instanceof java.util.List)) {
root = new DefaultMutableTreeNode("root");
DynamicUtilTreeNode.createChildren(root, value);
--- 388,393 ----
DefaultMutableTreeNode root;
! if((value instanceof Object[]) || (value instanceof Hashtable) ||
! (value instanceof Vector)) {
root = new DefaultMutableTreeNode("root");
DynamicUtilTreeNode.createChildren(root, value);
***************
*** 433,446 ****
/**
* Returns a <code>JTree</code> with each element of the specified
! * <code>java.util.List</code> as the
* child of a new root node which is not displayed. By default, the
* tree defines a leaf node as any node without children.
*
! * @param value a <code>java.util.List</code>
* @return a <code>JTree</code> with the contents of the
! * <code>java.util.List</code> as children of the root node
* @see DefaultTreeModel#asksAllowsChildren
*/
! public JTree(java.util.List value) {
this(createTreeModel(value));
this.setRootVisible(false);
--- 433,446 ----
/**
* Returns a <code>JTree</code> with each element of the specified
! * <code>Vector</code> as the
* child of a new root node which is not displayed. By default, the
* tree defines a leaf node as any node without children.
*
! * @param value a <code>Vector</code>
* @return a <code>JTree</code> with the contents of the
! * <code>Vector</code> as children of the root node
* @see DefaultTreeModel#asksAllowsChildren
*/
! public JTree(Vector value) {
this(createTreeModel(value));
this.setRootVisible(false);
***************
*** 450,454 ****
/**
! * Returns a <code>JTree</code> created from a <code>Map</code>
* which does not display with root.
* Each value-half of the key/value pairs in the <code>HashTable</code>
--- 450,454 ----
/**
! * Returns a <code>JTree</code> created from a <code>Hashtable</code>
* which does not display with root.
* Each value-half of the key/value pairs in the <code>HashTable</code>
***************
*** 456,465 ****
* a leaf node as any node without children.
*
! * @param value a <code>Map</code>
* @return a <code>JTree</code> with the contents of the
! * <code>Map</code> as children of the root node
* @see DefaultTreeModel#asksAllowsChildren
*/
! public JTree(Map value) {
this(createTreeModel(value));
this.setRootVisible(false);
--- 456,465 ----
* a leaf node as any node without children.
*
! * @param value a <code>Hashtable</code>
* @return a <code>JTree</code> with the contents of the
! * <code>Hashtable</code> as children of the root node
* @see DefaultTreeModel#asksAllowsChildren
*/
! public JTree(Hashtable value) {
this(createTreeModel(value));
this.setRootVisible(false);
***************
*** 3269,3288 ****
public static void createChildren(DefaultMutableTreeNode parent,
Object children) {
! if(children instanceof java.util.List) {
! java.util.List childList = (java.util.List)children;
! for(int counter = 0, maxCounter = childList.size();
counter < maxCounter; counter++)
parent.add(new DynamicUtilTreeNode
! (childList.get(counter),
! childList.get(counter)));
}
! else if(children instanceof Map) {
! Map childHT = (Map)children;
! Iterator keys = childHT.keySet().iterator();
Object aKey;
! while(keys.hasNext()) {
! aKey = keys.next();
parent.add(new DynamicUtilTreeNode(aKey,
childHT.get(aKey)));
--- 3269,3288 ----
public static void createChildren(DefaultMutableTreeNode parent,
Object children) {
! if(children instanceof Vector) {
! Vector childVector = (Vector)children;
! for(int counter = 0, maxCounter = childVector.size();
counter < maxCounter; counter++)
parent.add(new DynamicUtilTreeNode
! (childVector.elementAt(counter),
! childVector.elementAt(counter)));
}
! else if(children instanceof Hashtable) {
! Hashtable childHT = (Hashtable)children;
! Enumeration keys = childHT.keys();
Object aKey;
! while(keys.hasMoreElements()) {
! aKey = keys.nextElement();
parent.add(new DynamicUtilTreeNode(aKey,
childHT.get(aKey)));
***************
*** 3303,3307 ****
* with the specified children. For the node to allow children,
* the children-object must be an array of objects, a
! * <code>java.util.List</code>, or a <code>Map</code> -- even
* if empty. Otherwise, the node is not
* allowed to have children.
--- 3303,3307 ----
* with the specified children. For the node to allow children,
* the children-object must be an array of objects, a
! * <code>Vector</code>, or a <code>Hashtable</code> -- even
* if empty. Otherwise, the node is not
* allowed to have children.
***************
*** 3310,3314 ****
* new node
* @param children an array of <code>Object</code>s, a
! * <code>java.util.List</code>, or a <code>Map</code>
* used to create the child nodes; if any other
* object is specified, or if the value is
--- 3310,3314 ----
* new node
* @param children an array of <code>Object</code>s, a
! * <code>Vector</code>, or a <code>Hashtable</code>
* used to create the child nodes; if any other
* object is specified, or if the value is
***************
*** 3321,3327 ****
childValue = children;
if(children != null) {
! if(children instanceof java.util.List)
setAllowsChildren(true);
! else if(children instanceof Map)
setAllowsChildren(true);
else if(children instanceof Object[])
--- 3321,3327 ----
childValue = children;
if(children != null) {
! if(children instanceof Vector)
setAllowsChildren(true);
! else if(children instanceof Hashtable)
setAllowsChildren(true);
else if(children instanceof Object[])
***************
*** 3358,3365 ****
/**
* Loads the children based on <code>childValue</code>.
! * If <code>childValue</code> is a <code>java.util.List
! </code>
* or array each element is added as a child,
! * if <code>childValue</code> is a <code>Map</code>
* each key/value pair is added in the order that
* <code>Enumeration</code> returns the keys.
--- 3358,3364 ----
/**
* Loads the children based on <code>childValue</code>.
! * If <code>childValue</code> is a <code>Vector</code>
* or array each element is added as a child,
! * if <code>childValue</code> is a <code>Hashtable</code>
* each key/value pair is added in the order that
* <code>Enumeration</code> returns the keys.
---------- END SOURCE ----------
(Review ID: 138287)
======================================================================
- duplicates
-
JDK-4304287 Swing components should require the use of Collections and not Vectors
-
- Open
-