I've implemented a few more methods in BasicTreeUI.

2006-06-07  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTreeUI.java
        (completeUIUninstall): Implemented.
        (uninstallUI): Moved some bits to completeUIUninstall().
Complete
        editing before uninstalling anything.
        (isToggleEvent): Implemented.
        (selectPathForEvent): Make use of isToggleEvent().
        (ComponentHandler.componentMoved): Implemented.
        (ComponentHandler.startTimer): Implemented.
        (ComponentHandler.getScrollPane): Implemented.
        (ComponentHandler.actionPerformed): Implemented.


/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.140
diff -u -1 -0 -r1.140 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	7 Jun 2006 14:36:03 -0000	1.140
+++ javax/swing/plaf/basic/BasicTreeUI.java	7 Jun 2006 20:26:23 -0000
@@ -851,23 +851,22 @@
     treeSelectionModel.setRowMapper(treeState);
     configureLayoutCache();
     updateSize();
   }
 
   /**
    * Invoked from uninstallUI after all the defaults/listeners have been
    * uninstalled.
    */
   protected void completeUIUninstall()
-  throws NotImplementedException
   {
-    // TODO: Implement this properly.
+    tree = null;
   }
 
   /**
    * Installs the subcomponents of the tree, which is the renderer pane.
    */
   protected void installComponents()
   {
     currentCellRenderer = createDefaultCellRenderer();
     rendererPane = createCellRendererPane();
     createdRenderer = true;
@@ -1398,25 +1397,26 @@
     tree.setBackground(null);
   }
 
   /**
    * Uninstall the UI for the component
    * 
    * @param c the component to uninstall UI for
    */
   public void uninstallUI(JComponent c)
   {
+    completeEditing();
+
     prepareForUIUninstall();
     uninstallDefaults();
     uninstallKeyboardActions();
     uninstallListeners();
-    tree = null;
     uninstallComponents();
     completeUIUninstall();
   }
 
   /**
    * Paints the specified component appropriate for the look and feel. This
    * method is invoked from the ComponentUI.update method when the specified
    * component is being painted. Subclasses should override this method and use
    * the specified Graphics object to render the content of the component.
    * 
@@ -1834,24 +1834,29 @@
   /**
    * Returning true indicates the row under the mouse should be toggled based on
    * the event. This is invoked after checkForClickInExpandControl, implying the
    * location is not in the expand (toggle) control.
    * 
    * @param event is the MouseEvent performed on the row.
    * @return true indicates the row under the mouse should be toggled based on
    *         the event.
    */
   protected boolean isToggleEvent(MouseEvent event)
-  throws NotImplementedException
   {
-    // FIXME: Not implemented.
-    return true;
+    boolean toggle = false;
+    if (SwingUtilities.isLeftMouseButton(event))
+      {
+        int clickCount = tree.getToggleClickCount();
+        if (clickCount > 0 && event.getClickCount() == clickCount)
+          toggle = true;
+      }
+    return toggle;
   }
 
   /**
    * Messaged to update the selection based on a MouseEvent over a particular
    * row. If the even is a toggle selection event, the row is either selected,
    * or deselected. If the event identifies a multi selection event, the
    * selection is updated from the anchor point. Otherwise, the row is selected,
    * and the previous selection is cleared.</p>
    * 
    * @param path is the path selected for an event
@@ -1882,21 +1887,22 @@
             int aRow = getRowForPath(tree, anchor);
             tree.addSelectionInterval(aRow, getRowForPath(tree, path));
           }
         else
           tree.addSelectionPath(path);
       }
     else
       {
         // This is an ordinary event that just selects the clicked row.
         tree.setSelectionPath(path);
-        tree.setAnchorSelectionPath(path);
+        if (isToggleEvent(event))
+          toggleExpandState(path);
       }
   }
 
   /**
    * Returns true if the node at <code>row</code> is a leaf.
    * 
    * @param row is the row we are concerned with.
    * @return true if the node at <code>row</code> is a leaf.
    */
   protected boolean isLeaf(int row)
@@ -2019,57 +2025,95 @@
     {
       // Nothing to do here.
     }
 
     /**
      * Invoked when the component's position changes.
      * 
      * @param e the event that occurs when moving the component
      */
     public void componentMoved(ComponentEvent e)
-    throws NotImplementedException
     {
-      // TODO: What should be done here, if anything?
+      if (timer == null)
+        {
+          JScrollPane scrollPane = getScrollPane();
+          if (scrollPane == null)
+            updateSize();
+          else
+            {
+              // Determine the scrollbar that is adjusting, if any, and
+              // start the timer for that. If no scrollbar is adjusting,
+              // we simply call updateSize().
+              scrollBar = scrollPane.getVerticalScrollBar();
+              if (scrollBar == null || !scrollBar.getValueIsAdjusting())
+                {
+                  // It's not the vertical scrollbar, try the horizontal one.
+                  scrollBar = scrollPane.getHorizontalScrollBar();
+                  if (scrollBar != null && scrollBar.getValueIsAdjusting())
+                    startTimer();
+                  else
+                    updateSize();
+                }
+              else
+                {
+                  startTimer();
+                }
+            }
+        }
     }
 
     /**
      * Creates, if necessary, and starts a Timer to check if needed to resize
      * the bounds
      */
     protected void startTimer()
-    throws NotImplementedException
     {
-      // TODO: Implement this properly.
+      if (timer == null)
+        {
+          timer = new Timer(200, this);
+          timer.setRepeats(true);
+        }
+      timer.start();
     }
 
     /**
      * Returns the JScrollPane housing the JTree, or null if one isn't found.
      * 
      * @return JScrollPane housing the JTree, or null if one isn't found.
      */
     protected JScrollPane getScrollPane()
-    throws NotImplementedException
     {
-      // FIXME: Not implemented.
-      return null;
+      JScrollPane found = null;
+      Component p = tree.getParent();
+      while (p != null && !(p instanceof JScrollPane))
+        p = p.getParent();
+      if (p instanceof JScrollPane)
+        found = (JScrollPane) p;
+      return found;
     }
 
     /**
      * Public as a result of Timer. If the scrollBar is null, or not adjusting,
      * this stops the timer and updates the sizing.
      * 
      * @param ae is the action performed
      */
     public void actionPerformed(ActionEvent ae)
-    throws NotImplementedException
     {
-      // TODO: Implement this properly.
+      if (scrollBar == null || !scrollBar.getValueIsAdjusting())
+        {
+          if (timer != null)
+            timer.stop();
+          updateSize();
+          timer = null;
+          scrollBar = null;
+        }
     }
   }
 
   /**
    * Listener responsible for getting cell editing events and updating the tree
    * accordingly.
    */
   public class CellEditorHandler
       implements CellEditorListener
   {
@@ -3441,23 +3485,22 @@
                                                     isExpanded, isLeaf, row,
                                                     focused);
 
     rendererPane.paintComponent(g, c, c.getParent(), bounds);
   }
 
   /**
    * Prepares for the UI to uninstall.
    */
   protected void prepareForUIUninstall()
-  throws NotImplementedException
   {
-    // TODO: Implement this properly.
+    // Nothing to do here yet.
   }
 
   /**
    * Returns true if the expand (toggle) control should be drawn for the
    * specified row.
    * 
    * @param path - current path to check for.
    * @param row - current row to check for.
    * @param isExpanded - true if the path is expanded
    * @param hasBeenExpanded - true if the path has been expanded already

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to