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.ParentHelper;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32
33 import com.sun.javafx.scene.control.behavior.BehaviorBase;
34 import com.sun.javafx.scene.traversal.Algorithm;
35 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
36 import com.sun.javafx.scene.traversal.TraversalContext;
37
38 import javafx.beans.property.ObjectProperty;
39 import javafx.beans.property.DoubleProperty;
40 import javafx.beans.value.WritableValue;
41 import javafx.collections.FXCollections;
42 import javafx.collections.ListChangeListener;
43 import javafx.collections.ObservableList;
44 import javafx.geometry.HPos;
45 import javafx.geometry.Orientation;
46 import javafx.geometry.Pos;
47 import javafx.geometry.Side;
118 * well as the necessary input mappings for handling key, mouse, etc events.
119 *
120 * @param control The control that this skin should be installed onto.
121 */
122 public ToolBarSkin(ToolBar control) {
123 super(control);
124
125 // install default input map for the ToolBar control
126 behavior = new ToolBarBehavior(control);
127 // control.setInputMap(behavior.getInputMap());
128
129 overflowMenuItems = FXCollections.observableArrayList();
130 initialize();
131 registerChangeListener(control.orientationProperty(), e -> initialize());
132
133 engine = new ParentTraversalEngine(getSkinnable(), new Algorithm() {
134
135 private Node selectPrev(int from, TraversalContext context) {
136 for (int i = from; i >= 0; --i) {
137 Node n = box.getChildren().get(i);
138 if (n.isDisabled() || !n.impl_isTreeVisible()) continue;
139 if (n instanceof Parent) {
140 Node selected = context.selectLastInParent((Parent)n);
141 if (selected != null) return selected;
142 }
143 if (n.isFocusTraversable() ) {
144 return n;
145 }
146 }
147 return null;
148 }
149
150 private Node selectNext(int from, TraversalContext context) {
151 for (int i = from, max = box.getChildren().size(); i < max; ++i) {
152 Node n = box.getChildren().get(i);
153 if (n.isDisabled() || !n.impl_isTreeVisible()) continue;
154 if (n.isFocusTraversable()) {
155 return n;
156 }
157 if (n instanceof Parent) {
158 Node selected = context.selectFirstInParent((Parent)n);
159 if (selected != null) return selected;
160 }
161 }
162 return null;
163 }
164
165 @Override
166 public Node select(Node owner, Direction dir, TraversalContext context) {
167 final ObservableList<Node> boxChildren = box.getChildren();
168 if (owner == overflowMenu) {
169 if (dir.isForward()) {
170 return null;
171 } else {
172 Node selected = selectPrev(boxChildren.size() - 1, context);
173 if (selected != null) return selected;
|
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.NodeHelper;
29 import com.sun.javafx.scene.ParentHelper;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33
34 import com.sun.javafx.scene.control.behavior.BehaviorBase;
35 import com.sun.javafx.scene.traversal.Algorithm;
36 import com.sun.javafx.scene.traversal.ParentTraversalEngine;
37 import com.sun.javafx.scene.traversal.TraversalContext;
38
39 import javafx.beans.property.ObjectProperty;
40 import javafx.beans.property.DoubleProperty;
41 import javafx.beans.value.WritableValue;
42 import javafx.collections.FXCollections;
43 import javafx.collections.ListChangeListener;
44 import javafx.collections.ObservableList;
45 import javafx.geometry.HPos;
46 import javafx.geometry.Orientation;
47 import javafx.geometry.Pos;
48 import javafx.geometry.Side;
119 * well as the necessary input mappings for handling key, mouse, etc events.
120 *
121 * @param control The control that this skin should be installed onto.
122 */
123 public ToolBarSkin(ToolBar control) {
124 super(control);
125
126 // install default input map for the ToolBar control
127 behavior = new ToolBarBehavior(control);
128 // control.setInputMap(behavior.getInputMap());
129
130 overflowMenuItems = FXCollections.observableArrayList();
131 initialize();
132 registerChangeListener(control.orientationProperty(), e -> initialize());
133
134 engine = new ParentTraversalEngine(getSkinnable(), new Algorithm() {
135
136 private Node selectPrev(int from, TraversalContext context) {
137 for (int i = from; i >= 0; --i) {
138 Node n = box.getChildren().get(i);
139 if (n.isDisabled() || !NodeHelper.isTreeVisible(n)) continue;
140 if (n instanceof Parent) {
141 Node selected = context.selectLastInParent((Parent)n);
142 if (selected != null) return selected;
143 }
144 if (n.isFocusTraversable() ) {
145 return n;
146 }
147 }
148 return null;
149 }
150
151 private Node selectNext(int from, TraversalContext context) {
152 for (int i = from, max = box.getChildren().size(); i < max; ++i) {
153 Node n = box.getChildren().get(i);
154 if (n.isDisabled() || !NodeHelper.isTreeVisible(n)) continue;
155 if (n.isFocusTraversable()) {
156 return n;
157 }
158 if (n instanceof Parent) {
159 Node selected = context.selectFirstInParent((Parent)n);
160 if (selected != null) return selected;
161 }
162 }
163 return null;
164 }
165
166 @Override
167 public Node select(Node owner, Direction dir, TraversalContext context) {
168 final ObservableList<Node> boxChildren = box.getChildren();
169 if (owner == overflowMenu) {
170 if (dir.isForward()) {
171 return null;
172 } else {
173 Node selected = selectPrev(boxChildren.size() - 1, context);
174 if (selected != null) return selected;
|