PatchSet 6700 
Date: 2005/07/06 02:01:11
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: swing fixes

Members: 
        ChangeLog:1.4224->1.4225 
        libraries/javalib/javax/swing/JTree.java:1.19->1.20 
        libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java:1.5->1.6 
        
libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java:1.5->1.6 
        
libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java:1.11->1.12 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4224 kaffe/ChangeLog:1.4225
--- kaffe/ChangeLog:1.4224      Tue Jul  5 17:35:06 2005
+++ kaffe/ChangeLog     Wed Jul  6 02:01:11 2005
@@ -1,3 +1,26 @@
+2005-07-06  Dalibor Topic  <[EMAIL PROTECTED]>
+
+       Resynced with GNU Classpath.
+
+       2005-07-04  Lillian Angel  <[EMAIL PROTECTED]>
+
+        * javax/swing/JTree.java
+        (addSelectionPath): if mouse click somewhere other than
+        a row, all selections are removed
+        * javax/swing/plaf/basic/BasicTreeUI.java
+        (mouseClicked): if mouse clicked on a row, all other
+        selections are cleared. DISCONTIGUOUS mode implemented.
+        (getCellBounds): Implemented
+        (paintLeaf): paints with cell bounds
+        (paintNonLeaf): paints with cell bounds
+        * javax/swing/tree/DefaultTreeCellRenderer.java:
+        (DefaultTreeCellRendererComponent): changed color of
+        selected row
+        (getFont): Implemented
+        * javax/swing/tree/DefaultTreeSelectionModel.java:
+        (addSelectionPaths): check if parameter is null
+        (removeSelectionPaths): check if parameter is null
+
 2005-07-05  Guilhem Lavaux  <[EMAIL PROTECTED]>
 
        * kaffe/kaffevm/jni/jni_i.h
Index: kaffe/libraries/javalib/javax/swing/JTree.java
diff -u kaffe/libraries/javalib/javax/swing/JTree.java:1.19 
kaffe/libraries/javalib/javax/swing/JTree.java:1.20
--- kaffe/libraries/javalib/javax/swing/JTree.java:1.19 Mon Jul  4 00:08:17 2005
+++ kaffe/libraries/javalib/javax/swing/JTree.java      Wed Jul  6 02:01:15 2005
@@ -1079,6 +1079,13 @@
 
                if (path != null)
                        selectionModel.addSelectionPath(path);
+               else
+               {
+                       selectionModel.clearSelection();
+                       // need to repaint because cant fire an event with 
+                       // null selection.
+                       repaint();
+               }
        }
 
        public void addSelectionRows(int[] rows)
Index: kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java
diff -u kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java:1.5 
kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java:1.6
--- kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java:1.5 Sun Jul 
 3 16:28:49 2005
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTreeUI.java     Wed Jul 
 6 02:01:15 2005
@@ -37,6 +37,8 @@
 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.Point;
 import java.awt.Rectangle;
@@ -85,6 +87,7 @@
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeCellEditor;
 import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.SwingUtilities;
 import javax.swing.tree.TreeCellEditor;
 import javax.swing.tree.TreeCellRenderer;
 import javax.swing.tree.TreeSelectionModel;
@@ -1723,14 +1726,30 @@
                {
                        Point click = e.getPoint();
                        int row = ((int) click.getY() / getRowHeight()) - 1;
-
+                       
                        if (BasicTreeUI.this.tree.isRowSelected(row))
                                BasicTreeUI.this.tree.removeSelectionRow(row);
                        else if (BasicTreeUI.this.tree.getSelectionModel()
-                                       .getSelectionMode() == 
treeSelectionModel.SINGLE_TREE_SELECTION)
+                                       .getSelectionMode() == 
+                                               
treeSelectionModel.SINGLE_TREE_SELECTION)
+                       {
+                               // clear selection, since only able to select 
one row at a time.
+                               
BasicTreeUI.this.tree.getSelectionModel().clearSelection();
+                               BasicTreeUI.this.tree.addSelectionRow(row);
+                       }
+                       else if (BasicTreeUI.this.tree.getSelectionModel()
+                                       .getSelectionMode() == 
+                                               
treeSelectionModel.CONTIGUOUS_TREE_SELECTION)
+                       {
+                               //TODO
+                       }
+                       else
+                       {
+                               BasicTreeUI.this.tree.getSelectionModel()
+                               .setSelectionMode(
+                                               
treeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
                                BasicTreeUI.this.tree.addSelectionRow(row);
-                       // FIXME: add in selection for more than 1 row, or an 
entire
-                       // path
+                       }
                }
 
                /**
@@ -2257,6 +2276,25 @@
        /* * HELPER METHODS FOR PAINTING * */
 
        /**
+        * Returns the cell bounds for painting selected cells
+        * 
+        * @param x is the x location of the cell
+        * @param y is the y location of the cell
+        * @param cell is the Object to get the bounds for
+        * 
+        * @returns Rectangle that represents the cell bounds
+        */
+       private Rectangle getCellBounds(int x, int y, Object cell)
+       {
+               String s = cell.toString();
+               Font f = tree.getFont();
+               FontMetrics fm = 
tree.getToolkit().getFontMetrics(tree.getFont());
+
+               return new Rectangle(x, y, 
SwingUtilities.computeStringWidth(fm, s), fm
+                               .getHeight());
+       }
+
+       /**
         * Paints a leaf in the tree
         * 
         * @param g the Graphics context in which to paint
@@ -2270,21 +2308,22 @@
                TreePath tp = new TreePath(((DefaultMutableTreeNode) 
leaf).getPath());
                boolean selected = tree.isPathSelected(tp);
 
-               Component c = 
tree.getCellRenderer().getTreeCellRendererComponent(tree,
-                               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));
+                       rendererPane.paintComponent(g, comp, tree, 
getCellBounds(x, y, leaf));
+               }
+               else
+               {
+                       Component c = 
tree.getCellRenderer().getTreeCellRendererComponent(tree,
+                                       leaf, false, false, true, 0, false);
+                       
+                       g.translate(x, y);
+                       c.paint(g);
+                       g.translate(-x, -y);
                }
-
-               g.translate(x, y);
-               c.paint(g);
-               g.translate(-x, -y);
        }
 
        /**
@@ -2302,20 +2341,22 @@
                TreePath tp = new TreePath(((DefaultMutableTreeNode) 
nonLeaf).getPath());
                boolean selected = tree.isPathSelected(tp);
 
-               Component c = 
tree.getCellRenderer().getTreeCellRendererComponent(tree,
-                               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));
+                       rendererPane.paintComponent(g, comp, tree, 
getCellBounds(x, y, nonLeaf));
+               }
+               else
+               {
+                       Component c = 
tree.getCellRenderer().getTreeCellRendererComponent(tree,
+                                       nonLeaf, false, false, false, 0, false);
+                       
+                       g.translate(x, y);
+                       c.paint(g);
+                       g.translate(-x, -y);
                }
-               g.translate(x, y);
-               c.paint(g);
-               g.translate(-x, -y);
        }
 
        /**
Index: kaffe/libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java
diff -u 
kaffe/libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java:1.5 
kaffe/libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java:1.6
--- kaffe/libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java:1.5   
Mon Jul  4 00:08:48 2005
+++ kaffe/libraries/javalib/javax/swing/tree/DefaultTreeCellRenderer.java       
Wed Jul  6 02:01:16 2005
@@ -116,6 +116,7 @@
         * borderSelectionColor
         */
        protected Color borderSelectionColor;
+       
 
        // -------------------------------------------------------------
        // Initialization ---------------------------------------------
@@ -380,17 +381,42 @@
                this.hasFocus = hasFocus;
 
                if (leaf)
-                       setIcon(getLeafIcon());
+                       setLeafIcon(getLeafIcon());
                else if (expanded)
-                       setIcon(getOpenIcon());
+                       setOpenIcon(getOpenIcon());
                else
-                       setIcon(getClosedIcon());
+                       setClosedIcon(getClosedIcon());
 
                setText(val.toString());
                setHorizontalAlignment(LEFT);
+               setOpaque(true);
                setVerticalAlignment(TOP);
+               setEnabled(true);
+               setFont(getFont());
 
+               if (selected) 
+               {
+                       super.setBackground(getBackgroundSelectionColor());
+                       super.setForeground(getTextSelectionColor());
+               }
+               else
+               {
+                       super.setBackground((tree.getParent()).getBackground());
+                       super.setForeground(getTextNonSelectionColor());
+               }
+               
+               
                return this;
+       }
+       
+       /**
+        * getFont
+        * 
+        * @return the current Font
+        */
+       public Font getFont()
+       {
+               return super.getFont();
        }
 
        /**
Index: kaffe/libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java
diff -u 
kaffe/libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java:1.11 
kaffe/libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java:1.12
--- 
kaffe/libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java:1.11    
    Mon Jul  4 00:08:48 2005
+++ kaffe/libraries/javalib/javax/swing/tree/DefaultTreeSelectionModel.java     
Wed Jul  6 02:01:16 2005
@@ -274,7 +274,7 @@
                                selection = new TreePath[temp.length];
                                System.arraycopy(temp, 0, selection, 0, 
temp.length);
                        }
-
+                       leadPath = value0;
                        fireValueChanged(new TreeSelectionEvent(this, value0, 
true,
                                        leadPath, value0));
                }
@@ -291,25 +291,29 @@
         */
        public void addSelectionPaths(TreePath[] value0)
        {
-               TreePath v0 = null;
-               for (int i = 0; i < value0.length; i++)
+               if (value0 != null)
                {
-                       v0 = value0[i];
-                       if (!isPathSelected(v0))
+                       TreePath v0 = null;
+                       for (int i = 0; i < value0.length; i++)
                        {
-                               if (isSelectionEmpty())
-                                       setSelectionPath(v0);
-                               else
+                               v0 = value0[i];
+                               if (!isPathSelected(v0))
                                {
-                                       TreePath[] temp = new 
TreePath[selection.length + 1];
-                                       System.arraycopy(selection, 0, temp, 0, 
selection.length);
-                                       temp[temp.length - 1] = v0;
-                                       selection = new TreePath[temp.length];
-                                       System.arraycopy(temp, 0, selection, 0, 
temp.length);
+                                       if (isSelectionEmpty())
+                                               setSelectionPath(v0);
+                                       else
+                                       {
+                                               TreePath[] temp = new 
TreePath[selection.length + 1];
+                                               System.arraycopy(selection, 0, 
temp, 0,
+                                                               
selection.length);
+                                               temp[temp.length - 1] = v0;
+                                               selection = new 
TreePath[temp.length];
+                                               System.arraycopy(temp, 0, 
selection, 0, temp.length);
+                                       }
+                                       leadPath = value0[value0.length - 1];
+                                       fireValueChanged(new 
TreeSelectionEvent(this, v0, true,
+                                                       leadPath, value0[0]));
                                }
-
-                               fireValueChanged(new TreeSelectionEvent(this, 
v0, true,
-                                               leadPath, value0[0]));
                        }
                }
        }
@@ -357,30 +361,33 @@
         */
        public void removeSelectionPaths(TreePath[] value0)
        {
-               int index = -1;
-               TreePath v0 = null;
-               for (int i = 0; i < value0.length; i++)
+               if (value0 != null)
                {
-                       v0 = value0[i];
-                       if (isPathSelected(v0))
+                       int index = -1;
+                       TreePath v0 = null;
+                       for (int i = 0; i < value0.length; i++)
                        {
-                               for (int x = 0; x < selection.length; x++)
+                               v0 = value0[i];
+                               if (isPathSelected(v0))
                                {
-                                       if (selection[i].equals(v0))
+                                       for (int x = 0; x < selection.length; 
x++)
                                        {
-                                               index = x;
-                                               break;
+                                               if (selection[i].equals(v0))
+                                               {
+                                                       index = x;
+                                                       break;
+                                               }
                                        }
-                               }
-                               TreePath[] temp = new TreePath[selection.length 
- 1];
-                               System.arraycopy(selection, 0, temp, 0, index);
-                               System.arraycopy(selection, index + 1, temp, 
index,
-                                               selection.length - index - 1);
-                               selection = new TreePath[temp.length];
-                               System.arraycopy(temp, 0, selection, 0, 
temp.length);
+                                       TreePath[] temp = new 
TreePath[selection.length - 1];
+                                       System.arraycopy(selection, 0, temp, 0, 
index);
+                                       System.arraycopy(selection, index + 1, 
temp, index,
+                                                       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]));
+                                       fireValueChanged(new 
TreeSelectionEvent(this, v0, false,
+                                                       leadPath, value0[0]));
+                               }
                        }
                }
        }

_______________________________________________
kaffe mailing list
kaffe@kaffe.org
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to