[cp-patches] FYI: BasicTreeUI fix

2007-04-03 Thread Roman Kennke
This fixes BasicTreeUI.getPathBounds() to also consider the tree's
insets, plus it adds a bunch of null checks for safety (all of this
stuff is public API and can thus be overridden to return null, so...).

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicTreeUI.java
(getPathBounds): Consider the tree's insets. Added a bunch of
null checks.

/Roman

-- 
http://kennke.org/blog/
Index: javax/swing/plaf/basic/BasicTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.156
diff -u -1 -5 -r1.156 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	10 Dec 2006 20:25:48 -	1.156
+++ javax/swing/plaf/basic/BasicTreeUI.java	3 Apr 2007 20:40:32 -
@@ -104,31 +104,31 @@
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreeSelectionModel;
 import javax.swing.tree.VariableHeightLayoutCache;
 
 /**
  * A delegate providing the user interface for codeJTree/code according to
  * the Basic look and feel.
  * 
  * @see javax.swing.JTree
  * @author Lillian Angel ([EMAIL PROTECTED])
  * @author Sascha Brawer ([EMAIL PROTECTED])
  * @author Audrius Meskauskas ([EMAIL PROTECTED])
  */
 public class BasicTreeUI
-extends TreeUI
+  extends TreeUI
 {
   /**
* The tree cell editing may be started by the single mouse click on the
* selected cell. To separate it from the double mouse click, the editing
* session starts after this time (in ms) after that single click, and only no
* other clicks were performed during that time.
*/
   static int WAIT_TILL_EDITING = 900;
 
   /** Collapse Icon for the tree. */
   protected transient Icon collapsedIcon;
 
   /** Expanded Icon for the tree. */
   protected transient Icon expandedIcon;
 
@@ -644,31 +644,42 @@
 return treeSelectionModel;
   }
 
   /**
* Returns the Rectangle enclosing the label portion that the last item in
* path will be drawn to. Will return null if any component in path is
* currently valid.
* 
* @param tree is the current tree the path will be drawn to.
* @param path is the current path the tree to draw to.
* @return the Rectangle enclosing the label portion that the last item in the
* path will be drawn to.
*/
   public Rectangle getPathBounds(JTree tree, TreePath path)
   {
-return treeState.getBounds(path, new Rectangle());
+Rectangle bounds = null;
+if (tree != null  treeState != null)
+  {
+bounds = treeState.getBounds(path, null);
+Insets i = tree.getInsets();
+if (bounds != null  i != null)
+  {
+bounds.x += i.left;
+bounds.y += i.top;
+  }
+  }
+return bounds;
   }
 
   /**
* Returns the max height of all the nodes in the tree.
* 
* @param tree - the current tree
* @return the max height.
*/
   int getMaxHeight(JTree tree)
   {
 if (maxHeight != 0)
   return maxHeight;
 
 Icon e = UIManager.getIcon(Tree.openIcon);
 Icon c = UIManager.getIcon(Tree.closedIcon);
@@ -1549,31 +1560,30 @@
 int rows = treeState.getRowCount();
 
 if (rows == 0)
   // There is nothing to do if the tree is empty.
   return;
 
 Rectangle clip = g.getClipBounds();
 
 Insets insets = tree.getInsets();
 
 if (clip != null  treeModel != null)
   {
 int startIndex = tree.getClosestRowForLocation(clip.x, clip.y);
 int endIndex = tree.getClosestRowForLocation(clip.x + clip.width,
  clip.y + clip.height);
-
 // Also paint dashes to the invisible nodes below.
 // These should be painted first, otherwise they may cover
 // the control icons.
 if (endIndex  rows)
   for (int i = endIndex + 1; i  rows; i++)
 {
   TreePath path = treeState.getPathForRow(i);
   if (isLastChild(path))
 paintVerticalPartOfLeg(g, clip, insets, path);
 }
 
 // The two loops are required to ensure that the lines are not
 // painted over the other tree components.
 
 int n = endIndex - startIndex + 1;


Re: [cp-patches] FYI: BasicTreeUI fix

2005-10-18 Thread Lillian Angel
Noticed the expanded and collapsed icon defaults were set to the wrong
icons. Fixed this and reworked mousePressed to work with these changes.


2005-10-18  Lillian Angel  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicTreeUI.java:
Removed leafIcon field.
(BasicTreeUI): Removed leafIcon initialization.
(installDefaults): Icon defaults were wrong, fixed.
(isLocationInExpandControl): Fixed to incorporated gap.
(mousePressed): Fixed to include correct icon widths. Sometimes
the labels icon is different from what the tree's default icon 
is set to. Added a check for this.
(getCellBounds): No need to include gap here.
(getCurrentControlIcon): Fixed to use expandedIcon and 
collapsedIcon.
(paintRow): No need paint beyond preferred width of tree here.
(updateCurrentVisiblePath): If nothing is selected, the root 
should be selected without focus.
* javax/swing/plaf/metal/MetalTreeUI.java
(installDefaults): Fixed defaults for the expanded/collapsed 
icons.


On Mon, 2005-10-17 at 14:46 -0400, Lillian Angel wrote:
 Now this is completely fixed.
 
 2005-10-17  Lillian Angel  [EMAIL PROTECTED]
 
 * javax/swing/plaf/basic/BasicTreeUI.java
 (installUI): Moved call to installKeyboardActions and Listeners
 to before expansion of root.
 (paint): Added check to make sure the cached visible path is 
   updated.
 (treeExpanded): Added call to update visible path.
 (treeCollapsed): Likewise.
 (treeNodesChanged): Likewise.
 (treeNodesInserted): Likewise.
 (treeNodesRemoved): Likewise.
 (treeStructureChanged): Likewise.
 (paintRecursive): Moved code to paintRow.
 (paintControlIcons): Fixed to paint custom control icons 
   properly.
 (paintExpandControl): Removed unneeded parameter.
 (paintRow): Added code to paint the row with the correct width.
 * javax/swing/plaf/metal/MetalTreeUI.java
 (installUI): Moved code to expand the root after all the 
   listeners have been initialized.
 
 On Fri, 2005-10-14 at 17:42 -0400, Lillian Angel wrote:
  After testing some new apps, I noticed that there was a slight problem
  with some custom icons. I almost have it fixed completely.
  
  2005-10-14  Lillian Angel  [EMAIL PROTECTED]
  
  * javax/swing/LookAndFeel.java
  (makeIcon): Implemented.
  * javax/swing/plaf/basic/BasicTreeUI.java
  (updateCachedPreferredSize): Should only add with of control
  icon if
  not a leaf.
  (mousePressed): Fixed to use new gap field.
  (paintRecursive): Likewise.
  (paintRow): Likewise.
  (updateCurrentVisiblePath): Shouldn't include root if it is
  not of a valid size to be painted.
  
  ___
  Classpath-patches mailing list
  Classpath-patches@gnu.org
  http://lists.gnu.org/mailman/listinfo/classpath-patches
 ___
 Classpath-patches mailing list
 Classpath-patches@gnu.org
 http://lists.gnu.org/mailman/listinfo/classpath-patches
Index: javax/swing/plaf/basic/BasicTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.101
diff -u -r1.101 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	18 Oct 2005 15:02:42 -	1.101
+++ javax/swing/plaf/basic/BasicTreeUI.java	18 Oct 2005 17:38:54 -
@@ -225,9 +225,6 @@
 
   /** Set to true if the editor has a different size than the renderer. */
   protected boolean editorHasDifferentSize;
-
-  /** Leaf icon for the tree. */
-  Icon leafIcon;
   
   /** The action listener for the editor's Timer. */
   Timer editorTimer = new EditorUpdateTimer();
@@ -285,7 +282,6 @@
 
 editingRow = -1;
 lastSelectedRow = -1;
-leafIcon = UIManager.getIcon(Tree.leafIcon);
   }
 
   /**
@@ -1233,8 +1229,8 @@
 tree.setRowHeight(UIManager.getInt(Tree.rowHeight));
 tree.requestFocusInWindow(false);
 tree.setScrollsOnExpand(UIManager.getBoolean(Tree.scrollsOnExpand));
-setExpandedIcon(UIManager.getIcon(Tree.openIcon));
-setCollapsedIcon(UIManager.getIcon(Tree.closedIcon));
+setExpandedIcon(UIManager.getIcon(Tree.expandedIcon));
+setCollapsedIcon(UIManager.getIcon(Tree.collapsedIcon));
   }
 
   /**
@@ -1673,11 +1669,10 @@
 
 if (!isLeaf(row))
   {
-if (bounds == null)
-  bounds = getPathBounds(tree, path);
+bounds = getPathBounds(tree, path);
 
 if (hasControlIcons()  (mouseX  bounds.x) 
- (mouseX  (bounds.x - getCurrentControlIcon(path).getIconWidth(
+ (mouseX  (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap)))
   cntlClick = true;
   }
 return cntlClick;
@@ -2310,13 +2305,29 @@
 

Re: [cp-patches] FYI: BasicTreeUI fix

2005-10-17 Thread Lillian Angel
Now this is completely fixed.

2005-10-17  Lillian Angel  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicTreeUI.java
(installUI): Moved call to installKeyboardActions and Listeners
to before expansion of root.
(paint): Added check to make sure the cached visible path is 
updated.
(treeExpanded): Added call to update visible path.
(treeCollapsed): Likewise.
(treeNodesChanged): Likewise.
(treeNodesInserted): Likewise.
(treeNodesRemoved): Likewise.
(treeStructureChanged): Likewise.
(paintRecursive): Moved code to paintRow.
(paintControlIcons): Fixed to paint custom control icons 
properly.
(paintExpandControl): Removed unneeded parameter.
(paintRow): Added code to paint the row with the correct width.
* javax/swing/plaf/metal/MetalTreeUI.java
(installUI): Moved code to expand the root after all the 
listeners have been initialized.

On Fri, 2005-10-14 at 17:42 -0400, Lillian Angel wrote:
 After testing some new apps, I noticed that there was a slight problem
 with some custom icons. I almost have it fixed completely.
 
 2005-10-14  Lillian Angel  [EMAIL PROTECTED]
 
 * javax/swing/LookAndFeel.java
 (makeIcon): Implemented.
 * javax/swing/plaf/basic/BasicTreeUI.java
 (updateCachedPreferredSize): Should only add with of control
 icon if
 not a leaf.
 (mousePressed): Fixed to use new gap field.
 (paintRecursive): Likewise.
 (paintRow): Likewise.
 (updateCurrentVisiblePath): Shouldn't include root if it is
 not of a valid size to be painted.
 
 ___
 Classpath-patches mailing list
 Classpath-patches@gnu.org
 http://lists.gnu.org/mailman/listinfo/classpath-patches
Index: javax/swing/plaf/basic/BasicTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.99
diff -u -r1.99 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	14 Oct 2005 22:37:07 -	1.99
+++ javax/swing/plaf/basic/BasicTreeUI.java	17 Oct 2005 18:38:45 -
@@ -1187,7 +1187,6 @@
   isLeaf = treeModel.isLeaf(path[i]);
 if (!isLeaf  hasControlIcons())
   bounds.width += getCurrentControlIcon(curr).getIconWidth();
-
 maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
   }
 preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length));
@@ -1347,7 +1346,9 @@
 installDefaults();
 
 installComponents();
-
+installKeyboardActions();
+installListeners();
+
 setCellEditor(createDefaultCellEditor());
 createdCellEditor = true;
 isEditing = false;
@@ -1362,8 +1363,6 @@
   }
 treeSelectionModel = tree.getSelectionModel();
 
-installKeyboardActions();
-installListeners();
 completeUIInstall();
   }
 
@@ -1410,13 +1409,16 @@
   public void paint(Graphics g, JComponent c)
   {
 JTree tree = (JTree) c;
+if (currentVisiblePath == null)
+  updateCurrentVisiblePath();
+
 if (treeModel != null)
   {
 Object root = treeModel.getRoot();
 paintRecursive(g, 0, 0, 0, tree, treeModel, root);
 
 if (hasControlIcons())
-  paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root);
+  paintControlIcons(g, 0, 0, 0, tree, treeModel, root);
   }
   }
 
@@ -2554,6 +2556,7 @@
 public void treeExpanded(TreeExpansionEvent event)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -2567,6 +2570,7 @@
 public void treeCollapsed(TreeExpansionEvent event)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -2750,6 +2754,7 @@
 public void treeNodesChanged(TreeModelEvent e)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -2765,6 +2770,7 @@
 public void treeNodesInserted(TreeModelEvent e)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -2783,6 +2789,7 @@
 public void treeNodesRemoved(TreeModelEvent e)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -2800,6 +2807,7 @@
 public void treeStructureChanged(TreeModelEvent e)
 {
   validCachedPreferredSize = false;
+  updateCurrentVisiblePath();
   tree.revalidate();
   tree.repaint();
 }
@@ -3085,11 +3093,7 @@
 boolean isLeaf = mod.isLeaf(curr);
 Rectangle bounds = getPathBounds(tree, path);
 Object root = mod.getRoot();
-int 

[cp-patches] FYI: BasicTreeUI fix

2005-08-16 Thread Anthony Balkissoon
This patch makes JTable key registrations match the JDK in that the UI
InputMap-ActionMap pair is registered as the parents of the JTable's
InputMap-ActionMap pair.  Patch is attached.


2005-08-16  Anthony Balkissoon  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicLookAndFeel.java:
(initComponentDefaults): Fixed typo.
* javax/swing/plaf/basic/BasicTableUI.java:
(installKeyboardActions): Replaced calls to registerKeyboardAction with
additions to an explicit InputMap-ActionMap pair and then set this
pair as the parent pair to the JTable's.  This matches the JDK where
the UI Input-Action pairs are the parents of the component's.
(ActionListenerProxy): New class.

-Tony
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.44
diff -u -r1.44 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java	12 Aug 2005 20:45:17 -	1.44
+++ javax/swing/plaf/basic/BasicLookAndFeel.java	16 Aug 2005 17:38:20 -
@@ -887,7 +887,7 @@
 shift KP_LEFT, selectPreviousColumnExtendSelection,
 ESCAPE,  cancel,
 ctrl shift PAGE_UP, scrollLeftExtendSelection,
-shift KP_RIGHT,  selectNextColumnExtendSelection,
+shift KP_RIGHT, selectNextColumnExtendSelection,
 ctrl PAGE_UP,  scrollLeftChangeSelection,
 shift PAGE_UP, scrollUpExtendSelection,
 ctrl shift PAGE_DOWN, scrollRightExtendSelection,
Index: javax/swing/plaf/basic/BasicTableUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v
retrieving revision 1.22
diff -u -r1.22 BasicTableUI.java
--- javax/swing/plaf/basic/BasicTableUI.java	15 Aug 2005 19:50:38 -	1.22
+++ javax/swing/plaf/basic/BasicTableUI.java	16 Aug 2005 17:38:20 -
@@ -54,6 +54,7 @@
 import java.awt.event.MouseEvent;
 
 import javax.swing.AbstractAction;
+import javax.swing.ActionMap;
 import javax.swing.BorderFactory;
 import javax.swing.CellRendererPane;
 import javax.swing.InputMap;
@@ -68,6 +69,7 @@
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.MouseInputListener;
 import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.InputMapUIResource;
 import javax.swing.plaf.TableUI;
 import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
@@ -269,23 +271,70 @@
   {
 UIDefaults defaults = UIManager.getLookAndFeelDefaults();
 InputMap ancestorMap = (InputMap)defaults.get(Table.ancestorInputMap);
+InputMapUIResource parentInputMap = new InputMapUIResource();
+// FIXME: The JDK uses a LazyActionMap for parentActionMap
+ActionMap parentActionMap = new ActionMap();
 action = new TableAction();
 Object keys[] = ancestorMap.allKeys();
-// Register the key bindings with the JTable.
+// Register key bindings in the UI InputMap-ActionMap pair
 // Note that we register key bindings with both the old and new modifier
 // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on.
 for (int i = 0; i  keys.length; i++)
   {
-table.registerKeyboardAction(action,(String)ancestorMap.get((KeyStroke)keys[i]), 
- KeyStroke.getKeyStroke
- (((KeyStroke)keys[i]).getKeyCode(), convertModifiers(((KeyStroke)keys[i]).getModifiers())), 
- JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
-
-table.registerKeyboardAction(action,(String)ancestorMap.get((KeyStroke)keys[i]), 
- KeyStroke.getKeyStroke
- (((KeyStroke)keys[i]).getKeyCode(), ((KeyStroke)keys[i]).getModifiers()), 
- JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+parentInputMap.put(KeyStroke.getKeyStroke
+  (((KeyStroke)keys[i]).getKeyCode(), convertModifiers
+   (((KeyStroke)keys[i]).getModifiers())),
+   (String)ancestorMap.get((KeyStroke)keys[i]));
+
+parentInputMap.put(KeyStroke.getKeyStroke
+  (((KeyStroke)keys[i]).getKeyCode(), 
+   ((KeyStroke)keys[i]).getModifiers()),
+   (String)ancestorMap.get((KeyStroke)keys[i]));
+
+parentActionMap.put
+  ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy
+   (action, (String)ancestorMap.get((KeyStroke)keys[i])));
+
   }
+// Set the UI InputMap-ActionMap pair to be the parents of the
+// JTable's InputMap-ActionMap pair
+parentInputMap.setParent
+  (table.getInputMap
+   (JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent());
+parentActionMap.setParent(table.getActionMap().getParent());
+