< prev index next >

modules/controls/src/main/java/javafx/scene/control/TableUtil.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 359         }
 360         return remainingDelta == 0;
 361     }
 362 
 363     // function used to actually perform the resizing of the given column,
 364     // whilst ensuring it stays within the min and max bounds set on the column.
 365     // Returns the remaining delta if it could not all be applied.
 366     static double resize(TableColumnBase column, double delta) {
 367         if (delta == 0) return 0.0F;
 368         if (! column.isResizable()) return delta;
 369 
 370         final boolean isShrinking = delta < 0;
 371         final List<TableColumnBase<?,?>> resizingChildren = getResizableChildren(column, isShrinking);
 372 
 373         if (resizingChildren.size() > 0) {
 374             return resizeColumns(resizingChildren, delta);
 375         } else {
 376             double newWidth = column.getWidth() + delta;
 377 
 378             if (newWidth > column.getMaxWidth()) {
 379                 column.impl_setWidth(column.getMaxWidth());
 380                 return newWidth - column.getMaxWidth();
 381             } else if (newWidth < column.getMinWidth()) {
 382                 column.impl_setWidth(column.getMinWidth());
 383                 return newWidth - column.getMinWidth();
 384             } else {
 385                 column.impl_setWidth(newWidth);
 386                 return 0.0F;
 387             }
 388         }
 389     }
 390 
 391     // Returns all children columns of the given column that are able to be
 392     // resized. This is based on whether they are visible, resizable, and have
 393     // not space before they hit the min / max values.
 394     private static List<TableColumnBase<?,?>> getResizableChildren(TableColumnBase<?,?> column, boolean isShrinking) {
 395         if (column == null || column.getColumns().isEmpty()) {
 396             return Collections.emptyList();
 397         }
 398 
 399         List<TableColumnBase<?,?>> tablecolumns = new ArrayList<TableColumnBase<?,?>>();
 400         for (TableColumnBase c : column.getColumns()) {
 401             if (! c.isVisible()) continue;
 402             if (! c.isResizable()) continue;
 403 
 404             if (isShrinking && c.getWidth() > c.getMinWidth()) {
 405                 tablecolumns.add(c);


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 359         }
 360         return remainingDelta == 0;
 361     }
 362 
 363     // function used to actually perform the resizing of the given column,
 364     // whilst ensuring it stays within the min and max bounds set on the column.
 365     // Returns the remaining delta if it could not all be applied.
 366     static double resize(TableColumnBase column, double delta) {
 367         if (delta == 0) return 0.0F;
 368         if (! column.isResizable()) return delta;
 369 
 370         final boolean isShrinking = delta < 0;
 371         final List<TableColumnBase<?,?>> resizingChildren = getResizableChildren(column, isShrinking);
 372 
 373         if (resizingChildren.size() > 0) {
 374             return resizeColumns(resizingChildren, delta);
 375         } else {
 376             double newWidth = column.getWidth() + delta;
 377 
 378             if (newWidth > column.getMaxWidth()) {
 379                 column.doSetWidth(column.getMaxWidth());
 380                 return newWidth - column.getMaxWidth();
 381             } else if (newWidth < column.getMinWidth()) {
 382                 column.doSetWidth(column.getMinWidth());
 383                 return newWidth - column.getMinWidth();
 384             } else {
 385                 column.doSetWidth(newWidth);
 386                 return 0.0F;
 387             }
 388         }
 389     }
 390 
 391     // Returns all children columns of the given column that are able to be
 392     // resized. This is based on whether they are visible, resizable, and have
 393     // not space before they hit the min / max values.
 394     private static List<TableColumnBase<?,?>> getResizableChildren(TableColumnBase<?,?> column, boolean isShrinking) {
 395         if (column == null || column.getColumns().isEmpty()) {
 396             return Collections.emptyList();
 397         }
 398 
 399         List<TableColumnBase<?,?>> tablecolumns = new ArrayList<TableColumnBase<?,?>>();
 400         for (TableColumnBase c : column.getColumns()) {
 401             if (! c.isVisible()) continue;
 402             if (! c.isResizable()) continue;
 403 
 404             if (isShrinking && c.getWidth() > c.getMinWidth()) {
 405                 tablecolumns.add(c);


< prev index next >