Please disregard the last email, this is the updated patch that needs to be approved.
Here is a new patch for these classes. I implemented it so the user can select paths/rows in the JTree. But still, but visual testing you cannot see this very well. - Patch Attached. * javax/swing/JTree.java: (valueChanged): repaint everytime something is selected in the tree. (setSelectionModel): set TreeSelectionListeners (isRowSelected): isRowSelected uses isPathSelected * javax/swing/plaf/basic/BasicTreeUI.java (setSelectionModel): works with JTree to set the selection model (getPathForRow): took out unneeded lines (mouseClicked): switched if statements, should check if already selected first. (paintLeaf): checked selection of Leaf and paint selected differently than not selected cells (paintNonLeaf): checked selection of nonLeaf and paint selected differently than not selected cells (paintRecursive): updated to work with other paint functions * javax/swing/tree/DefaultTreeSelectionModel.java: (addSelectionPath): fire change, so selection is registered to listener (addSelectionPaths): fire change, so selection is registered to listener (removeSelectionPath): fire change, so selection is registered to listener (removeSelectionPaths): fire change, so selection is registered to listener (isPathSelected): took out unneeded lines (getTreeSelectionListeners): made more logical to call getListeners (fireValueChanged): fixed loop to be more logical -- Lillian Angel Red Hat Canada, Ltd. (416) 482-2661 x239 [EMAIL PROTECTED]
Index: javax/swing/JTree.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v retrieving revision 1.24 diff -u -r1.24 JTree.java --- javax/swing/JTree.java 29 Jun 2005 13:20:01 -0000 1.24 +++ javax/swing/JTree.java 29 Jun 2005 20:29:11 -0000 @@ -172,6 +172,8 @@ TreeSelectionEvent rewritten = (TreeSelectionEvent) ev.cloneWithSource(JTree.this); fireValueChanged(rewritten); + JTree.this.revalidate(); + JTree.this.repaint(); } } // TreeSelectionRedirector @@ -889,11 +891,20 @@ public void setSelectionModel(TreeSelectionModel model) { if (selectionModel == model) - return; - - TreeSelectionModel oldValue = selectionModel; - selectionModel = model; - firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); + return; + + if (selectionModel != null) + selectionModel.removeTreeSelectionListener(selectionRedirector); + + TreeSelectionModel oldValue = selectionModel; + selectionModel = model; + + if (selectionModel != null) + selectionModel.addTreeSelectionListener(selectionRedirector); + + firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); + revalidate(); + repaint(); } public int getVisibleRowCount() @@ -1221,7 +1232,7 @@ public boolean isRowSelected(int row) { - return selectionModel.isRowSelected(row); + return selectionModel.isPathSelected(getPathForRow(row)); } public boolean isSelectionEmpty() Index: javax/swing/plaf/basic/BasicTreeUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v retrieving revision 1.11 diff -u -r1.11 BasicTreeUI.java --- javax/swing/plaf/basic/BasicTreeUI.java 29 Jun 2005 13:25:24 -0000 1.11 +++ javax/swing/plaf/basic/BasicTreeUI.java 29 Jun 2005 20:29:11 -0000 @@ -564,12 +564,7 @@ { if (newLSM != null) { - tree - .removePropertyChangeListener(selectionModelPropertyChangeListener); treeSelectionModel = newLSM; - treeState.setSelectionModel(newLSM); - tree - .addPropertyChangeListener(selectionModelPropertyChangeListener); tree.setSelectionModel(treeSelectionModel); } } @@ -619,6 +614,8 @@ if (pathForRow != null) pathForRow = pathForRow.getNextNode(); } + if (pathForRow == null) + return null; return new TreePath(pathForRow.getPath()); } @@ -1700,11 +1697,12 @@ { Point click = e.getPoint(); int row = ((int) click.getY() / getRowHeight()) - 1; - - if (BasicTreeUI.this.tree.getSelectionModel().getSelectionMode() == treeSelectionModel.SINGLE_TREE_SELECTION) - BasicTreeUI.this.tree.addSelectionRow(row); - else if (BasicTreeUI.this.tree.isRowSelected(row)) + + if (BasicTreeUI.this.tree.isRowSelected(row)) BasicTreeUI.this.tree.removeSelectionRow(row); + else if (BasicTreeUI.this.tree.getSelectionModel() + .getSelectionMode() == treeSelectionModel.SINGLE_TREE_SELECTION) + BasicTreeUI.this.tree.addSelectionRow(row); // FIXME: add in selection for more than 1 row, or an entire // path } @@ -2232,20 +2230,40 @@ /* * HELPER METHODS FOR PAINTING * */ - private void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf) + private void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf, + int childIndex) { + TreePath tp = new TreePath(((DefaultMutableTreeNode) leaf).getPath()); + boolean selected = tree.isPathSelected(tp); + Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree, - leaf, false, false, true, 0, false); + leaf, selected, false, true, 0, false); + + if (selected) + { + Component comp = tree.getCellRenderer().getTreeCellRendererComponent(tree, leaf, true, false, true, 0, false); + rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10, 25)); + } + g.translate(x, y); c.paint(g); g.translate(-x, -y); } private void paintNonLeaf(Graphics g, int x, int y, JTree tree, - Object nonLeaf) + Object nonLeaf, int childIndex) { + TreePath tp = new TreePath(((DefaultMutableTreeNode) nonLeaf).getPath()); + boolean selected = tree.isPathSelected(tp); + Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree, - nonLeaf, false, false, false, 0, false); + nonLeaf, selected, false, false, 0, false); + + if (selected) + { + Component comp = tree.getCellRenderer().getTreeCellRendererComponent(tree, nonLeaf, true, false, true, 0, false); + rendererPane.paintComponent(g, comp, tree, new Rectangle(x, y, 10, 25)); + } g.translate(x, y); c.paint(g); g.translate(-x, -y); @@ -2265,13 +2283,13 @@ if (mod.isLeaf(curr)) { - paintLeaf(g, indentation, descent, tree, curr); + paintLeaf(g, indentation, descent, tree, curr, childNumber); descent += getRowHeight(); } else { if (depth > 0 || tree.isRootVisible()) { - paintNonLeaf(g, indentation, descent, tree, curr); + paintNonLeaf(g, indentation, descent, tree, curr, childNumber); descent += getRowHeight(); y0 += halfHeight; } @@ -2294,7 +2312,7 @@ .drawLine(indentation + halfWidth, y0, indentation + halfWidth, y1); } - + return descent; } Index: javax/swing/tree/DefaultTreeCellRenderer.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/tree/DefaultTreeCellRenderer.java,v retrieving revision 1.5 diff -u -r1.5 DefaultTreeCellRenderer.java --- javax/swing/tree/DefaultTreeCellRenderer.java 11 Nov 2004 17:22:52 -0000 1.5 +++ javax/swing/tree/DefaultTreeCellRenderer.java 29 Jun 2005 20:29:11 -0000 @@ -373,14 +373,12 @@ * validate */ public void validate() { - // TODO } // validate() /** * revalidate */ public void revalidate() { - // TODO } // revalidate() /** @@ -392,7 +390,6 @@ * @param value4 TODO */ public void repaint(long value0, int value1, int value2, int value3, int value4) { - // TODO } // repaint() /** @@ -410,7 +407,6 @@ * @param value2 TODO */ protected void firePropertyChange(String value0, Object value1, Object value2) { - // TODO } // firePropertyChange() /** @@ -420,7 +416,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, byte value1, byte value2) { - // TODO } // firePropertyChange() /** @@ -430,7 +425,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, char value1, char value2) { - // TODO } // firePropertyChange() /** @@ -440,7 +434,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, short value1, short value2) { - // TODO } // firePropertyChange() /** @@ -450,7 +443,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, int value1, int value2) { - // TODO } // firePropertyChange() /** @@ -460,7 +452,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, long value1, long value2) { - // TODO } // firePropertyChange() /** @@ -470,7 +461,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, float value1, float value2) { - // TODO } // firePropertyChange() /** @@ -480,7 +470,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, double value1, double value2) { - // TODO } // firePropertyChange() /** @@ -490,7 +479,6 @@ * @param value2 TODO */ public void firePropertyChange(String value0, boolean value1, boolean value2) { - // TODO } // firePropertyChange() Index: javax/swing/tree/DefaultTreeSelectionModel.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/tree/DefaultTreeSelectionModel.java,v retrieving revision 1.13 diff -u -r1.13 DefaultTreeSelectionModel.java --- javax/swing/tree/DefaultTreeSelectionModel.java 29 Jun 2005 13:20:01 -0000 1.13 +++ javax/swing/tree/DefaultTreeSelectionModel.java 29 Jun 2005 20:29:11 -0000 @@ -51,6 +51,7 @@ import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; + /** * DefaultTreeSelectionModel * @@ -271,10 +272,12 @@ { TreePath[] temp = new TreePath[selection.length + 1]; System.arraycopy(selection, 0, temp, 0, selection.length); - temp[temp.length - 1] = value0; + temp[temp.length - 1] = value0; selection = new TreePath[temp.length]; System.arraycopy(temp, 0, selection, 0, temp.length); } + + fireValueChanged(new TreeSelectionEvent(this, value0, true, leadPath, value0)); } } @@ -305,7 +308,9 @@ selection = new TreePath[temp.length]; System.arraycopy(temp, 0, selection, 0, temp.length); } - } + + fireValueChanged(new TreeSelectionEvent(this, v0, true, leadPath, value0[0])); + } } } @@ -336,6 +341,8 @@ selection.length - index - 1); selection = new TreePath[temp.length]; System.arraycopy(temp, 0, selection, 0, temp.length); + + fireValueChanged(new TreeSelectionEvent(this, value0, false, leadPath, value0)); } } @@ -370,6 +377,8 @@ selection.length - index - 1); selection = new TreePath[temp.length]; System.arraycopy(temp, 0, selection, 0, temp.length); + + fireValueChanged(new TreeSelectionEvent(this, v0, false, leadPath, value0[0])); } } } @@ -421,6 +430,9 @@ */ public boolean isPathSelected(TreePath value0) { + if (selection == null) + return false; + for (int i = 0; i < selection.length; i++) { if (selection[i].equals(value0)) @@ -477,8 +489,7 @@ */ public TreeSelectionListener[] getTreeSelectionListeners() { - return (TreeSelectionListener[]) listenerList - .getListeners(TreeSelectionListener.class); + return (TreeSelectionListener[]) getListeners(TreeSelectionListener.class); } /** @@ -488,9 +499,9 @@ */ protected void fireValueChanged(TreeSelectionEvent event) { - TreeSelectionListener[] listeners = getTreeSelectionListeners(); + TreeSelectionListener[] listeners = getTreeSelectionListeners(); - for (int i = listeners.length - 1; i >= 0; --i) + for (int i = 0; i < listeners.length; ++i) listeners[i].valueChanged(event); }
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches