diff options
Diffstat (limited to 'libjava/classpath/javax/swing/tree')
6 files changed, 92 insertions, 125 deletions
diff --git a/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java b/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java index 9f587946..a1afe78 100644 --- a/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java +++ b/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java @@ -202,7 +202,7 @@ public class DefaultMutableTreeNode */ public void remove(int index) { - MutableTreeNode child = (MutableTreeNode) children.remove(index); + MutableTreeNode child = children.remove(index); child.setParent(null); } @@ -553,7 +553,7 @@ public class DefaultMutableTreeNode { node = node.getParent(); size = node.getChildCount(); - index = ((Integer) stack.pop()).intValue() + 1; + index = stack.pop().intValue() + 1; current--; } while (index >= size @@ -1052,10 +1052,10 @@ public class DefaultMutableTreeNode /** Provides an enumeration of a tree in breadth-first traversal * order. */ - static class BreadthFirstEnumeration implements Enumeration + static class BreadthFirstEnumeration implements Enumeration<TreeNode> { - LinkedList queue = new LinkedList(); + LinkedList<TreeNode> queue = new LinkedList<TreeNode>(); BreadthFirstEnumeration(TreeNode node) { @@ -1067,14 +1067,16 @@ public class DefaultMutableTreeNode return !queue.isEmpty(); } - public Object nextElement() + @SuppressWarnings("unchecked") + public TreeNode nextElement() { if (queue.isEmpty()) throw new NoSuchElementException("No more elements left."); - TreeNode node = (TreeNode) queue.removeFirst(); + TreeNode node = queue.removeFirst(); - Enumeration children = node.children(); + Enumeration<TreeNode> children = + (Enumeration<TreeNode>) node.children(); while (children.hasMoreElements()) queue.add(children.nextElement()); @@ -1085,16 +1087,18 @@ public class DefaultMutableTreeNode /** Provides an enumeration of a tree traversing it * preordered. */ - static class PreorderEnumeration implements Enumeration + static class PreorderEnumeration implements Enumeration<TreeNode> { TreeNode next; - Stack childrenEnums = new Stack(); + Stack<Enumeration<TreeNode>> childrenEnums = + new Stack<Enumeration<TreeNode>>(); + @SuppressWarnings("unchecked") PreorderEnumeration(TreeNode node) { next = node; - childrenEnums.push(node.children()); + childrenEnums.push((Enumeration<TreeNode>) node.children()); } public boolean hasMoreElements() @@ -1102,14 +1106,14 @@ public class DefaultMutableTreeNode return next != null; } - public Object nextElement() + public TreeNode nextElement() { if (next == null) throw new NoSuchElementException("No more elements left."); - Object current = next; + TreeNode current = next; - Enumeration children = (Enumeration) childrenEnums.peek(); + Enumeration<TreeNode> children = childrenEnums.peek(); // Retrieves the next element. next = traverse(children); @@ -1117,13 +1121,14 @@ public class DefaultMutableTreeNode return current; } - private TreeNode traverse(Enumeration children) + @SuppressWarnings("unchecked") + private TreeNode traverse(Enumeration<TreeNode> children) { // If more children are available step down. if (children.hasMoreElements()) { - TreeNode child = (TreeNode) children.nextElement(); - childrenEnums.push(child.children()); + TreeNode child = children.nextElement(); + childrenEnums.push((Enumeration<TreeNode>) child.children()); return child; } @@ -1137,7 +1142,7 @@ public class DefaultMutableTreeNode return null; else { - return traverse((Enumeration) childrenEnums.peek()); + return traverse(childrenEnums.peek()); } } } @@ -1145,16 +1150,18 @@ public class DefaultMutableTreeNode /** Provides an enumeration of a tree traversing it * postordered (= depth-first). */ - static class PostorderEnumeration implements Enumeration + static class PostorderEnumeration implements Enumeration<TreeNode> { Stack<TreeNode> nodes = new Stack<TreeNode>(); - Stack childrenEnums = new Stack(); + Stack<Enumeration<TreeNode>> childrenEnums = + new Stack<Enumeration<TreeNode>>(); + @SuppressWarnings("unchecked") PostorderEnumeration(TreeNode node) { nodes.push(node); - childrenEnums.push(node.children()); + childrenEnums.push((Enumeration<TreeNode>) node.children()); } public boolean hasMoreElements() @@ -1162,24 +1169,26 @@ public class DefaultMutableTreeNode return !nodes.isEmpty(); } - public Object nextElement() + public TreeNode nextElement() { if (nodes.isEmpty()) throw new NoSuchElementException("No more elements left!"); - Enumeration children = (Enumeration) childrenEnums.peek(); + Enumeration<TreeNode> children = childrenEnums.peek(); return traverse(children); } - private Object traverse(Enumeration children) + @SuppressWarnings("unchecked") + private TreeNode traverse(Enumeration<TreeNode> children) { if (children.hasMoreElements()) { - TreeNode node = (TreeNode) children.nextElement(); + TreeNode node = children.nextElement(); nodes.push(node); - Enumeration newChildren = node.children(); + Enumeration<TreeNode> newChildren = + (Enumeration<TreeNode>) node.children(); childrenEnums.push(newChildren); return traverse(newChildren); @@ -1190,7 +1199,7 @@ public class DefaultMutableTreeNode // Returns the node whose children // have all been visited. (= postorder) - Object next = nodes.peek(); + TreeNode next = nodes.peek(); nodes.pop(); return next; diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java index 4c10bfe..0489798 100644 --- a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java +++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java @@ -306,13 +306,7 @@ public class DefaultTreeCellEditor * Font to paint with, null indicates font of renderer is to be used. */ protected Font font; - - /** - * Helper field used to save the last path seen while the timer was - * running. - */ - private TreePath tPath; - + /** * Constructs a DefaultTreeCellEditor object for a JTree using the * specified renderer and a default editor. (Use this constructor @@ -347,38 +341,6 @@ public class DefaultTreeCellEditor Color c = UIManager.getColor("Tree.editorBorderSelectionColor"); setBorderSelectionColor(c); } - - /** - * Configures the editing component whenever it is null. - * - * @param tree the tree to configure to component for. - * @param renderer the renderer used to set up the nodes - * @param editor the editor used - */ - private void configureEditingComponent(JTree tree, - DefaultTreeCellRenderer renderer, - TreeCellEditor editor) - { - if (tree != null && lastPath != null) - { - Object val = lastPath.getLastPathComponent(); - boolean isLeaf = tree.getModel().isLeaf(val); - boolean expanded = tree.isExpanded(lastPath); - determineOffset(tree, val, true, expanded, isLeaf, lastRow); - - // set up icon - if (isLeaf) - renderer.setIcon(renderer.getLeafIcon()); - else if (expanded) - renderer.setIcon(renderer.getOpenIcon()); - else - renderer.setIcon(renderer.getClosedIcon()); - editingIcon = renderer.getIcon(); - - editingComponent = getTreeCellEditorComponent(tree, val, true, - expanded, isLeaf, lastRow); - } - } /** * writeObject diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java index 3766485..b9c8401 100644 --- a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java +++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java @@ -42,18 +42,14 @@ import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; -import java.awt.FontMetrics; import java.awt.Graphics; -import java.awt.Insets; import java.awt.Rectangle; import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JTree; import javax.swing.LookAndFeel; -import javax.swing.SwingUtilities; import javax.swing.UIManager; -import javax.swing.border.Border; import javax.swing.plaf.UIResource; /** @@ -515,7 +511,6 @@ public class DefaultTreeCellRenderer int xOffset = -1; if (bgColor != null) { - Icon i = getIcon(); xOffset = getXOffset(); g.setColor(bgColor); g.fillRect(xOffset, 0, getWidth() - xOffset, getHeight()); diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java b/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java index 3d9c677..2bb0d00 100644 --- a/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java +++ b/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java @@ -164,7 +164,7 @@ public class DefaultTreeSelectionModel * @see #removeSelectionPaths(TreePath[]) * @see #setSelectionPaths(TreePath[]) */ - private transient HashSet selectedPaths; + private transient HashSet<TreePath> selectedPaths; /** * A supporting datastructure that is used in addSelectionPaths() and @@ -174,7 +174,7 @@ public class DefaultTreeSelectionModel * @see #removeSelectionPaths(TreePath[]) * @see #setSelectionPaths(TreePath[]) */ - private transient HashSet tmpPaths; + private transient HashSet<TreePath> tmpPaths; /** * Constructs a new DefaultTreeSelectionModel. @@ -185,8 +185,8 @@ public class DefaultTreeSelectionModel listSelectionModel = new DefaultListSelectionModel(); listenerList = new EventListenerList(); leadIndex = -1; - tmpPaths = new HashSet(); - selectedPaths = new HashSet(); + tmpPaths = new HashSet<TreePath>(); + selectedPaths = new HashSet<TreePath>(); } /** @@ -206,8 +206,8 @@ public class DefaultTreeSelectionModel cloned.listenerList = new EventListenerList(); cloned.listSelectionModel = (DefaultListSelectionModel) listSelectionModel.clone(); - cloned.selectedPaths = new HashSet(); - cloned.tmpPaths = new HashSet(); + cloned.selectedPaths = new HashSet<TreePath>(); + cloned.tmpPaths = new HashSet<TreePath>(); return cloned; } @@ -394,7 +394,7 @@ public class DefaultTreeSelectionModel newLength = 1; } // Find new paths. - Vector changedPaths = null; + Vector<PathPlaceHolder> changedPaths = null; tmpPaths.clear(); int validPaths = 0; TreePath oldLeadPath = leadPath; @@ -407,7 +407,7 @@ public class DefaultTreeSelectionModel if (! selectedPaths.contains(paths[i])) { if (changedPaths == null) - changedPaths = new Vector(); + changedPaths = new Vector<PathPlaceHolder>(); changedPaths.add(new PathPlaceHolder(paths[i], true)); } leadPath = paths[i]; @@ -422,10 +422,10 @@ public class DefaultTreeSelectionModel // Some of the paths are already selected, put together // the new selection carefully. newSelection = new TreePath[validPaths]; - Iterator newPaths = tmpPaths.iterator(); + Iterator<TreePath> newPaths = tmpPaths.iterator(); validPaths = 0; for (int i = 0; newPaths.hasNext(); i++) - newSelection[i] = (TreePath) newPaths.next(); + newSelection[i] = newPaths.next(); } else { @@ -440,14 +440,14 @@ public class DefaultTreeSelectionModel if (selection[i] != null && ! tmpPaths.contains(selection[i])) { if (changedPaths == null) - changedPaths = new Vector(); + changedPaths = new Vector<PathPlaceHolder>(); changedPaths.add(new PathPlaceHolder(selection[i], false)); } } // Perform changes and notification. selection = newSelection; - HashSet tmp = selectedPaths; + HashSet<TreePath> tmp = selectedPaths; selectedPaths = tmpPaths; tmpPaths = tmp; tmpPaths.clear(); @@ -505,7 +505,7 @@ public class DefaultTreeSelectionModel } else { - Vector changedPaths = null; + Vector<PathPlaceHolder> changedPaths = null; tmpPaths.clear(); int validPaths = 0; TreePath oldLeadPath = leadPath; @@ -521,7 +521,7 @@ public class DefaultTreeSelectionModel { validPaths++; if (changedPaths == null) - changedPaths = new Vector(); + changedPaths = new Vector<PathPlaceHolder>(); changedPaths.add(new PathPlaceHolder(paths[i], true)); selectedPaths.add(paths[i]); tmpPaths.add(paths[i]); @@ -538,11 +538,11 @@ public class DefaultTreeSelectionModel { // Some of the paths are already selected, put together // the new selection carefully. - Iterator newPaths = tmpPaths.iterator(); + Iterator<TreePath> newPaths = tmpPaths.iterator(); i = oldPaths; while (newPaths.hasNext()) { - newSelection[i] = (TreePath) newPaths.next(); + newSelection[i] = newPaths.next(); i++; } } @@ -589,13 +589,13 @@ public class DefaultTreeSelectionModel clearSelection(); else { - Vector pathsToRemove = null; + Vector<PathPlaceHolder> pathsToRemove = null; for (int i = paths.length - 1; i >= 0; i--) { if (paths[i] != null && selectedPaths.contains(paths[i])) { if (pathsToRemove == null) - pathsToRemove = new Vector(); + pathsToRemove = new Vector<PathPlaceHolder>(); selectedPaths.remove(paths[i]); pathsToRemove.add(new PathPlaceHolder(paths[i], false)); @@ -610,9 +610,9 @@ public class DefaultTreeSelectionModel else { selection = new TreePath[selection.length - numRemove]; - Iterator keep = selectedPaths.iterator(); + Iterator<TreePath> keep = selectedPaths.iterator(); for (int valid = 0; keep.hasNext(); valid++) - selection[valid] = (TreePath) keep.next(); + selection[valid] = keep.next(); } // Update lead path. if (leadPath != null && ! selectedPaths.contains(leadPath)) @@ -1120,7 +1120,7 @@ public class DefaultTreeSelectionModel || selectionMode == DISCONTIGUOUS_TREE_SELECTION) return true; - HashSet set = new HashSet(); + HashSet<TreePath> set = new HashSet<TreePath>(); for (int i = 0; i < selection.length; i++) set.add(selection[i]); @@ -1128,10 +1128,10 @@ public class DefaultTreeSelectionModel set.remove(paths[i]); TreePath[] remaining = new TreePath[set.size()]; - Iterator iter = set.iterator(); + Iterator<TreePath> iter = set.iterator(); for (int i = 0; i < remaining.length; i++) - remaining[i] = (TreePath) iter.next(); + remaining[i] = iter.next(); return arePathsContiguous(remaining); } @@ -1144,7 +1144,8 @@ public class DefaultTreeSelectionModel * @param vPaths the vector of the changed patches * @param oldLeadSelection the old selection index */ - protected void notifyPathChange(Vector vPaths, TreePath oldLeadSelection) + protected void notifyPathChange(Vector<PathPlaceHolder> vPaths, + TreePath oldLeadSelection) { int numChangedPaths = vPaths.size(); @@ -1152,7 +1153,7 @@ public class DefaultTreeSelectionModel TreePath[] paths = new TreePath[numChangedPaths]; for (int i = 0; i < numChangedPaths; i++) { - PathPlaceHolder p = (PathPlaceHolder) vPaths.get(i); + PathPlaceHolder p = vPaths.get(i); news[i] = p.isNew; paths[i] = p.path; } diff --git a/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java b/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java index dff9298..488809e 100644 --- a/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java +++ b/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java @@ -135,7 +135,7 @@ public class FixedHeightLayoutCache } } - LinkedList lpath = new LinkedList(); + LinkedList<Object> lpath = new LinkedList<Object>(); NodeRecord rp = this; while (rp != null) { @@ -173,17 +173,17 @@ public class FixedHeightLayoutCache /** * The set of all expanded tree nodes. */ - Set expanded = new HashSet(); + Set<Object> expanded = new HashSet<Object>(); /** * Maps nodes to the row numbers. */ - Hashtable nodes = new Hashtable(); + Hashtable<Object,NodeRecord> nodes = new Hashtable<Object,NodeRecord>(); /** * Maps row numbers to nodes. */ - Hashtable row2node = new Hashtable(); + Hashtable<Integer,Object> row2node = new Hashtable<Integer,Object>(); /** * If true, the row map must be recomputed before using. @@ -338,7 +338,7 @@ public class FixedHeightLayoutCache if (dirty) update(); Object last = path.getLastPathComponent(); - NodeRecord r = (NodeRecord) nodes.get(last); + NodeRecord r = nodes.get(last); if (r == null) // This node is not visible. { @@ -373,7 +373,7 @@ public class FixedHeightLayoutCache return null; else { - NodeRecord r = (NodeRecord) nodes.get(last); + NodeRecord r = nodes.get(last); return r.getPath(); } } @@ -391,7 +391,7 @@ public class FixedHeightLayoutCache if (dirty) update(); - NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent()); + NodeRecord r = nodes.get(path.getLastPathComponent()); if (r == null) return - 1; else @@ -413,13 +413,13 @@ public class FixedHeightLayoutCache // As the rows have arbitrary height, we need to iterate. NodeRecord best = null; NodeRecord r; - Enumeration en = nodes.elements(); + Enumeration<NodeRecord> en = nodes.elements(); int dist = Integer.MAX_VALUE; while (en.hasMoreElements() && dist > 0) { - r = (NodeRecord) en.nextElement(); + r = en.nextElement(); if (best == null) { best = r; @@ -474,7 +474,7 @@ public class FixedHeightLayoutCache } /** - * Get the enumeration over all visible pathes that start from the given + * Get the enumeration over all visible paths that start from the given * parent path. * * @param parentPath the parent path @@ -491,7 +491,7 @@ public class FixedHeightLayoutCache for (int i = 0; i < parentPath.getPathCount(); i++) { node = parentPath.getPathComponent(i); - nr = (NodeRecord) nodes.get(node); + nr = nodes.get(node); if (nr.row >= 0) p.add(node); } @@ -583,10 +583,10 @@ public class FixedHeightLayoutCache if (dirty) update(); totalHeight = 0; - Enumeration en = nodes.elements(); + Enumeration<NodeRecord> en = nodes.elements(); while (en.hasMoreElements()) { - NodeRecord nr = (NodeRecord) en.nextElement(); + NodeRecord nr = en.nextElement(); Rectangle r = nr.getBounds(); totalHeight += r.height; } @@ -602,10 +602,10 @@ public class FixedHeightLayoutCache update(); maximalWidth = 0; - Enumeration en = nodes.elements(); + Enumeration<NodeRecord> en = nodes.elements(); while (en.hasMoreElements()) { - NodeRecord nr = (NodeRecord) en.nextElement(); + NodeRecord nr = en.nextElement(); Rectangle r = nr.getBounds(); if (r.x + r.width > maximalWidth) maximalWidth = r.x + r.width; diff --git a/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java b/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java index 8c70c13..50e8e5c 100644 --- a/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java +++ b/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java @@ -138,7 +138,7 @@ public class VariableHeightLayoutCache } } - LinkedList lpath = new LinkedList(); + LinkedList<Object> lpath = new LinkedList<Object>(); NodeRecord rp = this; while (rp != null) { @@ -146,7 +146,7 @@ public class VariableHeightLayoutCache if (rp.parent != null) { Object parent = rp.parent; - rp = (NodeRecord) nodes.get(parent); + rp = nodes.get(parent); // Add the root node, even if it is not visible. if (rp == null) lpath.addFirst(parent); @@ -171,17 +171,17 @@ public class VariableHeightLayoutCache /** * The set of all expanded tree nodes. */ - Set expanded = new HashSet(); + Set<Object> expanded = new HashSet<Object>(); /** * Maps nodes to the row numbers. */ - Hashtable nodes = new Hashtable(); + Hashtable<Object,NodeRecord> nodes = new Hashtable<Object,NodeRecord>(); /** * Maps row numbers to nodes. */ - ArrayList row2node = new ArrayList(); + ArrayList<Object> row2node = new ArrayList<Object>(); /** * If true, the row map must be recomputed before using. @@ -292,7 +292,7 @@ public class VariableHeightLayoutCache */ public void invalidatePathBounds(TreePath path) { - NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent()); + NodeRecord r = nodes.get(path.getLastPathComponent()); if (r != null) r.bounds = null; } @@ -354,7 +354,7 @@ public class VariableHeightLayoutCache Object last = path.getLastPathComponent(); Rectangle result = null; - NodeRecord r = (NodeRecord) nodes.get(last); + NodeRecord r = nodes.get(last); if (r != null) { // The RI allows null arguments for rect, in which case a new Rectangle @@ -405,7 +405,7 @@ public class VariableHeightLayoutCache if (dirty) update(); - NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent()); + NodeRecord r = nodes.get(path.getLastPathComponent()); if (r == null) return - 1; else @@ -427,13 +427,13 @@ public class VariableHeightLayoutCache // As the rows have arbitrary height, we need to iterate. NodeRecord best = null; NodeRecord r; - Enumeration en = nodes.elements(); + Enumeration<NodeRecord> en = nodes.elements(); int dist = Integer.MAX_VALUE; while (en.hasMoreElements() && dist > 0) { - r = (NodeRecord) en.nextElement(); + r = en.nextElement(); if (best == null) { best = r; @@ -488,7 +488,7 @@ public class VariableHeightLayoutCache } /** - * Get the enumeration over all visible pathes that start from the given + * Get the enumeration over all visible paths that start from the given * parent path. * * @param parentPath the parent path @@ -505,7 +505,7 @@ public class VariableHeightLayoutCache for (int i = 0; i < parentPath.getPathCount(); i++) { node = parentPath.getPathComponent(i); - nr = (NodeRecord) nodes.get(node); + nr = nodes.get(node); if (nr != null && nr.row >= 0) p.add(node); } @@ -603,7 +603,7 @@ public class VariableHeightLayoutCache int rowCount = getRowCount(); if (rowCount > 0) { - NodeRecord last = (NodeRecord) nodes.get(row2node.get(rowCount - 1)); + NodeRecord last = nodes.get(row2node.get(rowCount - 1)); height = last.bounds.y + last.bounds.height; } return height; @@ -618,10 +618,10 @@ public class VariableHeightLayoutCache update(); maximalWidth = 0; - Enumeration en = nodes.elements(); + Enumeration<NodeRecord> en = nodes.elements(); while (en.hasMoreElements()) { - NodeRecord nr = (NodeRecord) en.nextElement(); + NodeRecord nr = en.nextElement(); if (nr != null) { Rectangle r = nr.getBounds(); |