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
23 * questions.
24 */
25 package javafx.scene.control.skin;
26
27 import com.sun.javafx.scene.control.Properties;
28 import com.sun.javafx.scene.control.TreeTableViewBackingList;
29 import com.sun.javafx.scene.control.skin.Utils;
30 import javafx.beans.property.BooleanProperty;
31 import javafx.beans.property.ObjectProperty;
32 import javafx.beans.property.SimpleObjectProperty;
33 import javafx.collections.FXCollections;
34 import javafx.collections.ObservableList;
35 import javafx.scene.Node;
36 import javafx.scene.control.Control;
37 import javafx.scene.control.IndexedCell;
38 import javafx.scene.control.ResizeFeaturesBase;
39 import javafx.scene.control.TableCell;
40 import javafx.scene.control.TableColumn;
41 import javafx.scene.control.TableColumnBase;
42 import javafx.scene.control.TableFocusModel;
43 import javafx.scene.control.TablePositionBase;
44 import javafx.scene.control.TableSelectionModel;
45 import javafx.scene.control.TableView;
46 import javafx.scene.control.TreeTableCell;
47 import javafx.scene.control.TreeTableColumn;
126 }
127
128 // dispose of the cell to prevent it retaining listeners (see RT-31015)
129 cell.updateIndex(-1);
130
131 // RT-36855 - take into account the column header text / graphic widths.
132 // Magic 10 is to allow for sort arrow to appear without text truncation.
133 TableColumnHeader header = tableSkin.getTableHeaderRow().getColumnHeaderFor(tc);
134 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
135 Node graphic = header.label.getGraphic();
136 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
137 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
138 maxWidth = Math.max(maxWidth, headerWidth);
139
140 // RT-23486
141 maxWidth += padding;
142 if(tv.getColumnResizePolicy() == TableView.CONSTRAINED_RESIZE_POLICY) {
143 maxWidth = Math.max(maxWidth, tc.getWidth());
144 }
145
146 tc.impl_setWidth(maxWidth);
147 }
148
149
150 /*
151 * FIXME: Naive implementation ahead
152 * Attempts to resize column based on the pref width of all items contained
153 * in this column. This can be potentially very expensive if the number of
154 * rows is large.
155 */
156 private static <T,S> void resizeColumnToFitContent(TreeTableView<T> ttv, TreeTableColumn<T,S> tc, TableViewSkinBase tableSkin, int maxRows) {
157 List<?> items = new TreeTableViewBackingList(ttv);
158 if (items == null || items.isEmpty()) return;
159
160 Callback cellFactory = tc.getCellFactory();
161 if (cellFactory == null) return;
162
163 TreeTableCell<T,S> cell = (TreeTableCell) cellFactory.call(tc);
164 if (cell == null) return;
165
166 // set this property to tell the TableCell we want to know its actual
201 }
202
203 // dispose of the cell to prevent it retaining listeners (see RT-31015)
204 cell.updateIndex(-1);
205
206 // RT-36855 - take into account the column header text / graphic widths.
207 // Magic 10 is to allow for sort arrow to appear without text truncation.
208 TableColumnHeader header = tableSkin.getTableHeaderRow().getColumnHeaderFor(tc);
209 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
210 Node graphic = header.label.getGraphic();
211 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
212 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
213 maxWidth = Math.max(maxWidth, headerWidth);
214
215 // RT-23486
216 maxWidth += padding;
217 if(ttv.getColumnResizePolicy() == TreeTableView.CONSTRAINED_RESIZE_POLICY) {
218 maxWidth = Math.max(maxWidth, tc.getWidth());
219 }
220
221 tc.impl_setWidth(maxWidth);
222 }
223
224 public static ObjectProperty<Callback<ResizeFeaturesBase,Boolean>> columnResizePolicyProperty(TableViewSkinBase<?,?,?,?,?> tableSkin) {
225 Object control = tableSkin.getSkinnable();
226 if (control instanceof TableView) {
227 return ((TableView)control).columnResizePolicyProperty();
228 } else if (control instanceof TreeTableView) {
229 return ((TreeTableView)control).columnResizePolicyProperty();
230 }
231 return null;
232 }
233
234 public static BooleanProperty tableMenuButtonVisibleProperty(TableViewSkinBase<?,?,?,?,?> tableSkin) {
235 Object control = tableSkin.getSkinnable();
236 if (control instanceof TableView) {
237 return ((TableView)control).tableMenuButtonVisibleProperty();
238 } else if (control instanceof TreeTableView) {
239 return ((TreeTableView)control).tableMenuButtonVisibleProperty();
240 }
241 return null;
|
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
23 * questions.
24 */
25 package javafx.scene.control.skin;
26
27 import com.sun.javafx.scene.control.Properties;
28 import com.sun.javafx.scene.control.TableColumnBaseHelper;
29 import com.sun.javafx.scene.control.TreeTableViewBackingList;
30 import com.sun.javafx.scene.control.skin.Utils;
31 import javafx.beans.property.BooleanProperty;
32 import javafx.beans.property.ObjectProperty;
33 import javafx.beans.property.SimpleObjectProperty;
34 import javafx.collections.FXCollections;
35 import javafx.collections.ObservableList;
36 import javafx.scene.Node;
37 import javafx.scene.control.Control;
38 import javafx.scene.control.IndexedCell;
39 import javafx.scene.control.ResizeFeaturesBase;
40 import javafx.scene.control.TableCell;
41 import javafx.scene.control.TableColumn;
42 import javafx.scene.control.TableColumnBase;
43 import javafx.scene.control.TableFocusModel;
44 import javafx.scene.control.TablePositionBase;
45 import javafx.scene.control.TableSelectionModel;
46 import javafx.scene.control.TableView;
47 import javafx.scene.control.TreeTableCell;
48 import javafx.scene.control.TreeTableColumn;
127 }
128
129 // dispose of the cell to prevent it retaining listeners (see RT-31015)
130 cell.updateIndex(-1);
131
132 // RT-36855 - take into account the column header text / graphic widths.
133 // Magic 10 is to allow for sort arrow to appear without text truncation.
134 TableColumnHeader header = tableSkin.getTableHeaderRow().getColumnHeaderFor(tc);
135 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
136 Node graphic = header.label.getGraphic();
137 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
138 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
139 maxWidth = Math.max(maxWidth, headerWidth);
140
141 // RT-23486
142 maxWidth += padding;
143 if(tv.getColumnResizePolicy() == TableView.CONSTRAINED_RESIZE_POLICY) {
144 maxWidth = Math.max(maxWidth, tc.getWidth());
145 }
146
147 TableColumnBaseHelper.setWidth(tc, maxWidth);
148 }
149
150
151 /*
152 * FIXME: Naive implementation ahead
153 * Attempts to resize column based on the pref width of all items contained
154 * in this column. This can be potentially very expensive if the number of
155 * rows is large.
156 */
157 private static <T,S> void resizeColumnToFitContent(TreeTableView<T> ttv, TreeTableColumn<T,S> tc, TableViewSkinBase tableSkin, int maxRows) {
158 List<?> items = new TreeTableViewBackingList(ttv);
159 if (items == null || items.isEmpty()) return;
160
161 Callback cellFactory = tc.getCellFactory();
162 if (cellFactory == null) return;
163
164 TreeTableCell<T,S> cell = (TreeTableCell) cellFactory.call(tc);
165 if (cell == null) return;
166
167 // set this property to tell the TableCell we want to know its actual
202 }
203
204 // dispose of the cell to prevent it retaining listeners (see RT-31015)
205 cell.updateIndex(-1);
206
207 // RT-36855 - take into account the column header text / graphic widths.
208 // Magic 10 is to allow for sort arrow to appear without text truncation.
209 TableColumnHeader header = tableSkin.getTableHeaderRow().getColumnHeaderFor(tc);
210 double headerTextWidth = Utils.computeTextWidth(header.label.getFont(), tc.getText(), -1);
211 Node graphic = header.label.getGraphic();
212 double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
213 double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
214 maxWidth = Math.max(maxWidth, headerWidth);
215
216 // RT-23486
217 maxWidth += padding;
218 if(ttv.getColumnResizePolicy() == TreeTableView.CONSTRAINED_RESIZE_POLICY) {
219 maxWidth = Math.max(maxWidth, tc.getWidth());
220 }
221
222 TableColumnBaseHelper.setWidth(tc, maxWidth);
223 }
224
225 public static ObjectProperty<Callback<ResizeFeaturesBase,Boolean>> columnResizePolicyProperty(TableViewSkinBase<?,?,?,?,?> tableSkin) {
226 Object control = tableSkin.getSkinnable();
227 if (control instanceof TableView) {
228 return ((TableView)control).columnResizePolicyProperty();
229 } else if (control instanceof TreeTableView) {
230 return ((TreeTableView)control).columnResizePolicyProperty();
231 }
232 return null;
233 }
234
235 public static BooleanProperty tableMenuButtonVisibleProperty(TableViewSkinBase<?,?,?,?,?> tableSkin) {
236 Object control = tableSkin.getSkinnable();
237 if (control instanceof TableView) {
238 return ((TableView)control).tableMenuButtonVisibleProperty();
239 } else if (control instanceof TreeTableView) {
240 return ((TreeTableView)control).tableMenuButtonVisibleProperty();
241 }
242 return null;
|