modules/controls/src/main/java/javafx/scene/control/skin/NestedTableColumnHeader.java

Print this page




 280     /** {@inheritDoc} */
 281     @Override protected void layoutChildren() {
 282         double w = getWidth() - snappedLeftInset() - snappedRightInset();
 283         double h = getHeight() - snappedTopInset() - snappedBottomInset();
 284 
 285         int labelHeight = (int) label.prefHeight(-1);
 286 
 287         if (label.isVisible()) {
 288             // label gets to span whole width and sits at top
 289             label.resize(w, labelHeight);
 290             label.relocate(snappedLeftInset(), snappedTopInset());
 291         }
 292 
 293         // children columns need to share the total available width
 294         double x = snappedLeftInset();
 295         int pos = 0;
 296         for (int i = 0, max = getColumnHeaders().size(); i < max; i++) {
 297             TableColumnHeader n = getColumnHeaders().get(i);
 298             if (! n.isVisible()) continue;
 299 
 300             double prefWidth = snapSize(n.prefWidth(-1));
 301 //            double prefHeight = n.prefHeight(-1);
 302 
 303             // position the column header in the default location...
 304             n.resize(prefWidth, snapSize(h - labelHeight));
 305             n.relocate(x, labelHeight + snappedTopInset());
 306 
 307 //            // ...but, if there are no children of this column, we should ensure
 308 //            // that it is resized vertically such that it goes to the very
 309 //            // bottom of the table header row.
 310 //            if (getTableHeaderRow() != null && n.getCol().getColumns().isEmpty()) {
 311 //                Bounds bounds = getTableHeaderRow().sceneToLocal(n.localToScene(n.getBoundsInLocal()));
 312 //                prefHeight = getTableHeaderRow().getHeight() - bounds.getMinY();
 313 //                n.resize(prefWidth, prefHeight);
 314 //            }
 315 
 316             // shuffle along the x-axis appropriately
 317             x += prefWidth;
 318 
 319             // position drag overlay to intercept column resize requests
 320             Rectangle dragRect = dragRects.get(n.getTableColumn());
 321             if (dragRect != null) {
 322                 dragRect.setHeight(n.getDragRectHeight());
 323                 dragRect.relocate(x - DRAG_RECT_WIDTH / 2, snappedTopInset() + labelHeight);
 324             }
 325         }
 326     }
 327 
 328     // sum up all children columns
 329     /** {@inheritDoc} */
 330     @Override protected double computePrefWidth(double height) {
 331         checkState();
 332 
 333         double width = 0.0F;
 334 
 335         if (getColumns() != null) {
 336             for (TableColumnHeader c : getColumnHeaders()) {
 337                 if (c.isVisible()) {
 338                     width += snapSize(c.computePrefWidth(height));
 339                 }
 340             }
 341         }
 342 
 343         return width;
 344     }
 345 
 346     /** {@inheritDoc} */
 347     @Override protected double computePrefHeight(double width) {
 348         checkState();
 349 
 350         double height = 0.0F;
 351 
 352         if (getColumnHeaders() != null) {
 353             for (TableColumnHeader n : getColumnHeaders()) {
 354                 height = Math.max(height, n.prefHeight(-1));
 355             }
 356         }
 357 
 358         return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();




 280     /** {@inheritDoc} */
 281     @Override protected void layoutChildren() {
 282         double w = getWidth() - snappedLeftInset() - snappedRightInset();
 283         double h = getHeight() - snappedTopInset() - snappedBottomInset();
 284 
 285         int labelHeight = (int) label.prefHeight(-1);
 286 
 287         if (label.isVisible()) {
 288             // label gets to span whole width and sits at top
 289             label.resize(w, labelHeight);
 290             label.relocate(snappedLeftInset(), snappedTopInset());
 291         }
 292 
 293         // children columns need to share the total available width
 294         double x = snappedLeftInset();
 295         int pos = 0;
 296         for (int i = 0, max = getColumnHeaders().size(); i < max; i++) {
 297             TableColumnHeader n = getColumnHeaders().get(i);
 298             if (! n.isVisible()) continue;
 299 
 300             double prefWidth = snapSizeX(n.prefWidth(-1));
 301 //            double prefHeight = n.prefHeight(-1);
 302 
 303             // position the column header in the default location...
 304             n.resize(prefWidth, snapSizeY(h - labelHeight));
 305             n.relocate(x, labelHeight + snappedTopInset());
 306 
 307 //            // ...but, if there are no children of this column, we should ensure
 308 //            // that it is resized vertically such that it goes to the very
 309 //            // bottom of the table header row.
 310 //            if (getTableHeaderRow() != null && n.getCol().getColumns().isEmpty()) {
 311 //                Bounds bounds = getTableHeaderRow().sceneToLocal(n.localToScene(n.getBoundsInLocal()));
 312 //                prefHeight = getTableHeaderRow().getHeight() - bounds.getMinY();
 313 //                n.resize(prefWidth, prefHeight);
 314 //            }
 315 
 316             // shuffle along the x-axis appropriately
 317             x += prefWidth;
 318 
 319             // position drag overlay to intercept column resize requests
 320             Rectangle dragRect = dragRects.get(n.getTableColumn());
 321             if (dragRect != null) {
 322                 dragRect.setHeight(n.getDragRectHeight());
 323                 dragRect.relocate(x - DRAG_RECT_WIDTH / 2, snappedTopInset() + labelHeight);
 324             }
 325         }
 326     }
 327 
 328     // sum up all children columns
 329     /** {@inheritDoc} */
 330     @Override protected double computePrefWidth(double height) {
 331         checkState();
 332 
 333         double width = 0.0F;
 334 
 335         if (getColumns() != null) {
 336             for (TableColumnHeader c : getColumnHeaders()) {
 337                 if (c.isVisible()) {
 338                     width += snapSizeX(c.computePrefWidth(height));
 339                 }
 340             }
 341         }
 342 
 343         return width;
 344     }
 345 
 346     /** {@inheritDoc} */
 347     @Override protected double computePrefHeight(double width) {
 348         checkState();
 349 
 350         double height = 0.0F;
 351 
 352         if (getColumnHeaders() != null) {
 353             for (TableColumnHeader n : getColumnHeaders()) {
 354                 height = Math.max(height, n.prefHeight(-1));
 355             }
 356         }
 357 
 358         return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();