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.behavior;
27
28 import javafx.scene.Node;
29 import javafx.scene.Parent;
30
31 import javafx.scene.Scene;
32 import javafx.scene.input.KeyEvent;
33
34 import javafx.beans.value.ChangeListener;
35 import javafx.event.Event;
36 import javafx.event.EventDispatcher;
37 import javafx.event.EventHandler;
38 import javafx.scene.input.MouseEvent;
39
40 import com.sun.javafx.scene.control.skin.ComboBoxPopupControl;
41
42 public class TwoLevelFocusListBehavior extends TwoLevelFocusBehavior {
43
44 public TwoLevelFocusListBehavior(Node node) {
45
46 tlNode = node;
47
48 // listen to all keyevents, maybe
49 tlNode.addEventHandler(KeyEvent.ANY, keyEventListener);
50 tlNode.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventListener);
51 tlNode.focusedProperty().addListener(focusListener);
52
53 // block ScrollEvent from being passed down to scrollbar's skin
54 origEventDispatcher = tlNode.getEventDispatcher();
55 tlNode.setEventDispatcher(tlfEventDispatcher);
56 }
57
58 /**
59 * Invoked by the behavior when it is disposed, so that any listeners installed by
60 * the TwoLevelFocusBehavior can also be uninstalled
61 */
173 };
174
175
176 /*
177 ** When a node gets focus, put it in external-focus mode.
178 */
179 final ChangeListener<Boolean> focusListener = (observable, oldVal, newVal) -> {
180
181 if (newVal && tlPopup != null) {
182 setExternalFocus(false);
183 }
184 else {
185 boolean b = true;
186 if (tlNode != null) {
187 /*
188 ** if the ListView is actually the popup for a combobox then
189 ** we go straight to internal-focus
190 */
191 Parent p = tlNode.getParent();
192 if (p != null) {
193 if (ComboBoxPopupControl.COMBO_BOX_STYLE_CLASS.equals(p.getStyleClass().toString())) {
194 b = false;
195 }
196 }
197 }
198
199 setExternalFocus(b);
200 }
201 };
202
203 private final EventHandler<MouseEvent> mouseEventListener = e -> {
204 setExternalFocus(false);
205 };
206 }
|
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.behavior;
27
28 import com.sun.javafx.scene.control.Properties;
29 import javafx.scene.Node;
30 import javafx.scene.Parent;
31
32 import javafx.scene.Scene;
33 import javafx.scene.control.skin.ComboBoxPopupControl;
34 import javafx.scene.input.KeyEvent;
35
36 import javafx.beans.value.ChangeListener;
37 import javafx.event.Event;
38 import javafx.event.EventDispatcher;
39 import javafx.event.EventHandler;
40 import javafx.scene.input.MouseEvent;
41
42 public class TwoLevelFocusListBehavior extends TwoLevelFocusBehavior {
43
44 public TwoLevelFocusListBehavior(Node node) {
45
46 tlNode = node;
47
48 // listen to all keyevents, maybe
49 tlNode.addEventHandler(KeyEvent.ANY, keyEventListener);
50 tlNode.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventListener);
51 tlNode.focusedProperty().addListener(focusListener);
52
53 // block ScrollEvent from being passed down to scrollbar's skin
54 origEventDispatcher = tlNode.getEventDispatcher();
55 tlNode.setEventDispatcher(tlfEventDispatcher);
56 }
57
58 /**
59 * Invoked by the behavior when it is disposed, so that any listeners installed by
60 * the TwoLevelFocusBehavior can also be uninstalled
61 */
173 };
174
175
176 /*
177 ** When a node gets focus, put it in external-focus mode.
178 */
179 final ChangeListener<Boolean> focusListener = (observable, oldVal, newVal) -> {
180
181 if (newVal && tlPopup != null) {
182 setExternalFocus(false);
183 }
184 else {
185 boolean b = true;
186 if (tlNode != null) {
187 /*
188 ** if the ListView is actually the popup for a combobox then
189 ** we go straight to internal-focus
190 */
191 Parent p = tlNode.getParent();
192 if (p != null) {
193 if (Properties.COMBO_BOX_STYLE_CLASS.equals(p.getStyleClass().toString())) {
194 b = false;
195 }
196 }
197 }
198
199 setExternalFocus(b);
200 }
201 };
202
203 private final EventHandler<MouseEvent> mouseEventListener = e -> {
204 setExternalFocus(false);
205 };
206 }
|