1 /*
2 * Copyright (c) 2010, 2014, 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
245 cell.applyCss();
246 maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
247 getChildren().remove(cell);
248 }
249 }
250
251 // dispose of the cell to prevent it retaining listeners (see RT-31015)
252 cell.updateIndex(-1);
253
254 // RT-36855 - take into account the column header text / graphic widths.
255 // Magic 10 is to allow for sort arrow to appear without text truncation.
256 TableColumnHeader header = getTableHeaderRow().getColumnHeaderFor(tc);
257 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
258 Node graphic = header.label.getGraphic();
259 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
260 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
261 maxWidth = Math.max(maxWidth, headerWidth);
262
263 // RT-23486
264 maxWidth += padding;
265 if(tableView.getColumnResizePolicy() == TableView.CONSTRAINED_RESIZE_POLICY) {
266 maxWidth = Math.max(maxWidth, tc.getWidth());
267 }
268
269 tc.impl_setWidth(maxWidth);
270 }
271
272 /** {@inheritDoc} */
273 @Override public int getItemCount() {
274 return tableView.getItems() == null ? 0 : tableView.getItems().size();
275 }
276
277 /** {@inheritDoc} */
278 @Override public TableRow<T> createCell() {
279 TableRow<T> cell;
280
281 if (tableView.getRowFactory() != null) {
282 cell = tableView.getRowFactory().call(tableView);
283 } else {
284 cell = new TableRow<T>();
285 }
286
287 cell.updateTableView(tableView);
288 return cell;
289 }
|
1 /*
2 * Copyright (c) 2010, 2018, 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
245 cell.applyCss();
246 maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
247 getChildren().remove(cell);
248 }
249 }
250
251 // dispose of the cell to prevent it retaining listeners (see RT-31015)
252 cell.updateIndex(-1);
253
254 // RT-36855 - take into account the column header text / graphic widths.
255 // Magic 10 is to allow for sort arrow to appear without text truncation.
256 TableColumnHeader header = getTableHeaderRow().getColumnHeaderFor(tc);
257 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
258 Node graphic = header.label.getGraphic();
259 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
260 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
261 maxWidth = Math.max(maxWidth, headerWidth);
262
263 // RT-23486
264 maxWidth += padding;
265 if (tableView.getColumnResizePolicy() == TableView.CONSTRAINED_RESIZE_POLICY && tableView.getWidth() > 0) {
266
267 if (maxWidth > tc.getMaxWidth()) {
268 maxWidth = tc.getMaxWidth();
269 }
270
271 int size = tc.getColumns().size();
272 if (size > 0) {
273 resizeColumnToFitContent(tc.getColumns().get(size - 1), maxRows);
274 return;
275 }
276
277 resizeColumn(tc, Math.round(maxWidth - tc.getWidth()));
278 } else {
279 tc.impl_setWidth(maxWidth);
280 }
281 }
282
283 /** {@inheritDoc} */
284 @Override public int getItemCount() {
285 return tableView.getItems() == null ? 0 : tableView.getItems().size();
286 }
287
288 /** {@inheritDoc} */
289 @Override public TableRow<T> createCell() {
290 TableRow<T> cell;
291
292 if (tableView.getRowFactory() != null) {
293 cell = tableView.getRowFactory().call(tableView);
294 } else {
295 cell = new TableRow<T>();
296 }
297
298 cell.updateTableView(tableView);
299 return cell;
300 }
|