1 /*
2 * Copyright (c) 2012, 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
23 * questions.
24 */
25
26 package com.sun.javafx.scene.control.skin;
27
28 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
29 import java.util.Map;
30 import javafx.beans.property.BooleanProperty;
31 import javafx.beans.property.ReadOnlyDoubleProperty;
32 import javafx.scene.Node;
33 import javafx.scene.control.Control;
34 import javafx.scene.control.TreeItem;
35 import javafx.scene.control.TreeTableCell;
36 import javafx.scene.control.TreeTableColumn;
37 import javafx.scene.control.TreeTableRow;
38 import javafx.scene.control.TreeTableView;
39
40 /**
41 */
42 public class TreeTableCellSkin<S,T> extends TableCellSkinBase<TreeTableCell<S,T>, TreeTableCellBehavior<S,T>> {
43
44 private final TreeTableCell<S,T> treeTableCell;
45 private final TreeTableColumn<S,T> tableColumn;
46
47 public TreeTableCellSkin(TreeTableCell<S,T> treeTableCell) {
48 super(treeTableCell, new TreeTableCellBehavior<S,T>(treeTableCell));
49
50 this.treeTableCell = treeTableCell;
51 this.tableColumn = treeTableCell.getTableColumn();
52
53 super.init(treeTableCell);
54 }
55
56 @Override protected BooleanProperty columnVisibleProperty() {
57 return tableColumn.visibleProperty();
58 }
59
60 @Override protected ReadOnlyDoubleProperty columnWidthProperty() {
61 return tableColumn.widthProperty();
62 }
63
64 @Override protected double leftLabelPadding() {
65 double leftPadding = super.leftLabelPadding();
66
67 // RT-27167: we must take into account the disclosure node and the
68 // indentation (which is not taken into account by the LabeledSkinBase.
69 final double height = getCellSize();
70
71 TreeTableCell<S,T> cell = getSkinnable();
72
73 TreeTableColumn<S,T> tableColumn = cell.getTableColumn();
74 if (tableColumn == null) return leftPadding;
75
76 // check if this column is the TreeTableView treeColumn (i.e. the
77 // column showing the disclosure node and graphic).
78 TreeTableView<S> treeTable = cell.getTreeTableView();
79 if (treeTable == null) return leftPadding;
80
81 int columnIndex = treeTable.getVisibleLeafIndex(tableColumn);
82
83 TreeTableColumn<S,?> treeColumn = treeTable.getTreeColumn();
84 if ((treeColumn == null && columnIndex != 0) || (treeColumn != null && ! tableColumn.equals(treeColumn))) {
94 int nodeLevel = treeTable.getTreeItemLevel(treeItem);
95 if (! treeTable.isShowRoot()) nodeLevel--;
96
97 double indentPerLevel = 10;
98 if (treeTableRow.getSkin() instanceof TreeTableRowSkin) {
99 indentPerLevel = ((TreeTableRowSkin<?>)treeTableRow.getSkin()).getIndentationPerLevel();
100 }
101 leftPadding += nodeLevel * indentPerLevel;
102
103 // add in the width of the disclosure node, if one exists
104 Map<Control, Double> mdwp = TableRowSkinBase.maxDisclosureWidthMap;
105 leftPadding += mdwp.containsKey(treeTable) ? mdwp.get(treeTable) : 0;
106
107 // adding in the width of the graphic on the tree item
108 Node graphic = treeItem.getGraphic();
109 leftPadding += graphic == null ? 0 : graphic.prefWidth(height);
110
111 return leftPadding;
112 }
113
114 @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
115 if (isDeferToParentForPrefWidth) {
116 // RT-27167: we must take into account the disclosure node and the
117 // indentation (which is not taken into account by the LabeledSkinBase.
118 return super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset);
119 }
120 return columnWidthProperty().get();
121 }
122 }
|
1 /*
2 * Copyright (c) 2012, 2015, 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
23 * questions.
24 */
25
26 package javafx.scene.control.skin;
27
28 import com.sun.javafx.scene.control.behavior.BehaviorBase;
29 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
30 import java.util.Map;
31 import javafx.beans.property.BooleanProperty;
32 import javafx.beans.property.ReadOnlyDoubleProperty;
33 import javafx.scene.Node;
34 import javafx.scene.control.Button;
35 import javafx.scene.control.Control;
36 import javafx.scene.control.TreeItem;
37 import javafx.scene.control.TreeTableCell;
38 import javafx.scene.control.TreeTableColumn;
39 import javafx.scene.control.TreeTableRow;
40 import javafx.scene.control.TreeTableView;
41
42 /**
43 * Default skin implementation for the {@link TreeTableCell} control.
44 *
45 * @see TreeTableCell
46 * @since 9
47 */
48 public class TreeTableCellSkin<S,T> extends TableCellSkinBase<TreeTableCell<S,T>> {
49
50 /***************************************************************************
51 * *
52 * Private Fields *
53 * *
54 **************************************************************************/
55
56 private final BehaviorBase<TreeTableCell<S,T>> behavior;
57
58
59
60 /***************************************************************************
61 * *
62 * Constructors *
63 * *
64 **************************************************************************/
65
66 /**
67 * Creates a new TreeTableCellSkin instance, installing the necessary child
68 * nodes into the Control {@link Control#getChildren() children} list, as
69 * well as the necessary input mappings for handling key, mouse, etc events.
70 *
71 * @param control The control that this skin should be installed onto.
72 */
73 public TreeTableCellSkin(TreeTableCell<S,T> control) {
74 super(control);
75
76 // install default input map for the TreeTableCell control
77 behavior = new TreeTableCellBehavior<>(control);
78 // control.setInputMap(behavior.getInputMap());
79 }
80
81
82
83 /***************************************************************************
84 * *
85 * Public API *
86 * *
87 **************************************************************************/
88
89 /** {@inheritDoc} */
90 @Override public void dispose() {
91 super.dispose();
92
93 if (behavior != null) {
94 behavior.dispose();
95 }
96 }
97
98
99
100 /***************************************************************************
101 * *
102 * Private implementation *
103 * *
104 **************************************************************************/
105
106 /** {@inheritDoc} */
107 @Override BooleanProperty columnVisibleProperty() {
108 return getSkinnable().getTableColumn().visibleProperty();
109 }
110
111 /** {@inheritDoc} */
112 @Override ReadOnlyDoubleProperty columnWidthProperty() {
113 return getSkinnable().getTableColumn().widthProperty();
114 }
115
116 /** {@inheritDoc} */
117 @Override double leftLabelPadding() {
118 double leftPadding = super.leftLabelPadding();
119
120 // RT-27167: we must take into account the disclosure node and the
121 // indentation (which is not taken into account by the LabeledSkinBase.
122 final double height = getCellSize();
123
124 TreeTableCell<S,T> cell = getSkinnable();
125
126 TreeTableColumn<S,T> tableColumn = cell.getTableColumn();
127 if (tableColumn == null) return leftPadding;
128
129 // check if this column is the TreeTableView treeColumn (i.e. the
130 // column showing the disclosure node and graphic).
131 TreeTableView<S> treeTable = cell.getTreeTableView();
132 if (treeTable == null) return leftPadding;
133
134 int columnIndex = treeTable.getVisibleLeafIndex(tableColumn);
135
136 TreeTableColumn<S,?> treeColumn = treeTable.getTreeColumn();
137 if ((treeColumn == null && columnIndex != 0) || (treeColumn != null && ! tableColumn.equals(treeColumn))) {
147 int nodeLevel = treeTable.getTreeItemLevel(treeItem);
148 if (! treeTable.isShowRoot()) nodeLevel--;
149
150 double indentPerLevel = 10;
151 if (treeTableRow.getSkin() instanceof TreeTableRowSkin) {
152 indentPerLevel = ((TreeTableRowSkin<?>)treeTableRow.getSkin()).getIndentationPerLevel();
153 }
154 leftPadding += nodeLevel * indentPerLevel;
155
156 // add in the width of the disclosure node, if one exists
157 Map<Control, Double> mdwp = TableRowSkinBase.maxDisclosureWidthMap;
158 leftPadding += mdwp.containsKey(treeTable) ? mdwp.get(treeTable) : 0;
159
160 // adding in the width of the graphic on the tree item
161 Node graphic = treeItem.getGraphic();
162 leftPadding += graphic == null ? 0 : graphic.prefWidth(height);
163
164 return leftPadding;
165 }
166
167 /** {@inheritDoc} */
168 @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
169 if (isDeferToParentForPrefWidth) {
170 // RT-27167: we must take into account the disclosure node and the
171 // indentation (which is not taken into account by the LabeledSkinBase.
172 return super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset);
173 }
174 return columnWidthProperty().get();
175 }
176 }
|