src/share/classes/javax/swing/tree/AbstractLayoutCache.java

Print this page




 211      * @param bounds the region being queried
 212      * @return the preferred width for the passed in region
 213      */
 214     public int getPreferredWidth(Rectangle bounds) {
 215         int           rowCount = getRowCount();
 216 
 217         if(rowCount > 0) {
 218             // Get the width
 219             TreePath      firstPath;
 220             int           endY;
 221 
 222             if(bounds == null) {
 223                 firstPath = getPathForRow(0);
 224                 endY = Integer.MAX_VALUE;
 225             }
 226             else {
 227                 firstPath = getPathClosestTo(bounds.x, bounds.y);
 228                 endY = bounds.height + bounds.y;
 229             }
 230 
 231             Enumeration   paths = getVisiblePathsFrom(firstPath);
 232 
 233             if(paths != null && paths.hasMoreElements()) {
 234                 Rectangle   pBounds = getBounds((TreePath)paths.nextElement(),
 235                                                 null);
 236                 int         width;
 237 
 238                 if(pBounds != null) {
 239                     width = pBounds.x + pBounds.width;
 240                     if (pBounds.y >= endY) {
 241                         return width;
 242                     }
 243                 }
 244                 else
 245                     width = 0;
 246                 while (pBounds != null && paths.hasMoreElements()) {
 247                     pBounds = getBounds((TreePath)paths.nextElement(),
 248                                         pBounds);
 249                     if (pBounds != null && pBounds.y < endY) {
 250                         width = Math.max(width, pBounds.x + pBounds.width);
 251                     }
 252                     else {
 253                         pBounds = null;
 254                     }
 255                 }
 256                 return width;
 257             }
 258         }
 259         return 0;
 260     }
 261 
 262     //
 263     // Abstract methods that must be implemented to be concrete.
 264     //
 265 
 266     /**
 267       * Returns true if the value identified by row is currently expanded.




 211      * @param bounds the region being queried
 212      * @return the preferred width for the passed in region
 213      */
 214     public int getPreferredWidth(Rectangle bounds) {
 215         int           rowCount = getRowCount();
 216 
 217         if(rowCount > 0) {
 218             // Get the width
 219             TreePath      firstPath;
 220             int           endY;
 221 
 222             if(bounds == null) {
 223                 firstPath = getPathForRow(0);
 224                 endY = Integer.MAX_VALUE;
 225             }
 226             else {
 227                 firstPath = getPathClosestTo(bounds.x, bounds.y);
 228                 endY = bounds.height + bounds.y;
 229             }
 230 
 231             Enumeration<TreePath> paths = getVisiblePathsFrom(firstPath);
 232 
 233             if(paths != null && paths.hasMoreElements()) {
 234                 Rectangle   pBounds = getBounds(paths.nextElement(),
 235                                                 null);
 236                 int         width;
 237 
 238                 if(pBounds != null) {
 239                     width = pBounds.x + pBounds.width;
 240                     if (pBounds.y >= endY) {
 241                         return width;
 242                     }
 243                 }
 244                 else
 245                     width = 0;
 246                 while (pBounds != null && paths.hasMoreElements()) {
 247                     pBounds = getBounds(paths.nextElement(),
 248                                         pBounds);
 249                     if (pBounds != null && pBounds.y < endY) {
 250                         width = Math.max(width, pBounds.x + pBounds.width);
 251                     }
 252                     else {
 253                         pBounds = null;
 254                     }
 255                 }
 256                 return width;
 257             }
 258         }
 259         return 0;
 260     }
 261 
 262     //
 263     // Abstract methods that must be implemented to be concrete.
 264     //
 265 
 266     /**
 267       * Returns true if the value identified by row is currently expanded.