modules/web/src/main/java/com/sun/javafx/scene/web/behavior/HTMLEditorBehavior.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
@@ -23,51 +23,47 @@
* questions.
*/
package com.sun.javafx.scene.web.behavior;
-import javafx.scene.web.HTMLEditor;
-import java.util.ArrayList;
-import java.util.List;
import com.sun.javafx.scene.control.behavior.BehaviorBase;
-import com.sun.javafx.scene.control.behavior.KeyBinding;
+import com.sun.javafx.scene.control.inputmap.InputMap;
+import com.sun.javafx.scene.control.inputmap.KeyBinding;
+import javafx.scene.web.HTMLEditor;
import com.sun.javafx.scene.web.skin.HTMLEditorSkin;
-import static javafx.scene.input.KeyCode.B;
-import static javafx.scene.input.KeyCode.F12;
-import static javafx.scene.input.KeyCode.I;
-import static javafx.scene.input.KeyCode.TAB;
-import static javafx.scene.input.KeyCode.U;
+import com.sun.javafx.scene.control.behavior.FocusTraversalInputMap;
+import static javafx.scene.input.KeyCode.*;
+import static com.sun.javafx.scene.control.inputmap.InputMap.KeyMapping;
/**
* HTML editor behavior.
*/
public class HTMLEditorBehavior extends BehaviorBase<HTMLEditor> {
- protected static final List<KeyBinding> HTML_EDITOR_BINDINGS = new ArrayList<KeyBinding>();
+ private final InputMap<HTMLEditor> inputMap;
- static {
- HTML_EDITOR_BINDINGS.add(new KeyBinding(B, "bold").shortcut());
- HTML_EDITOR_BINDINGS.add(new KeyBinding(I, "italic").shortcut());
- HTML_EDITOR_BINDINGS.add(new KeyBinding(U, "underline").shortcut());
-
- HTML_EDITOR_BINDINGS.add(new KeyBinding(F12, "F12"));
- HTML_EDITOR_BINDINGS.add(new KeyBinding(TAB, "TraverseNext").ctrl());
- HTML_EDITOR_BINDINGS.add(new KeyBinding(TAB, "TraversePrevious").ctrl().shift());
- }
public HTMLEditorBehavior(HTMLEditor htmlEditor) {
- super(htmlEditor, HTML_EDITOR_BINDINGS);
+ super(htmlEditor);
+
+ this.inputMap = createInputMap();
+ addDefaultMapping(inputMap,
+ new KeyMapping(new KeyBinding(B).shortcut(), e -> keyboardShortcuts("bold")),
+ new KeyMapping(new KeyBinding(I).shortcut(), e -> keyboardShortcuts("italic")),
+ new KeyMapping(new KeyBinding(U).shortcut(), e -> keyboardShortcuts("underline")),
+
+ new KeyMapping(new KeyBinding(F12), e -> getNode().getImpl_traversalEngine().selectFirst().requestFocus()),
+ new KeyMapping(new KeyBinding(TAB).ctrl(), FocusTraversalInputMap::traverseNext),
+ new KeyMapping(new KeyBinding(TAB).ctrl().shift(), FocusTraversalInputMap::traversePrevious)
+ );
}
- @Override
- protected void callAction(String name) {
- if ("bold".equals(name) || "italic".equals(name) || "underline".equals(name)) {
- HTMLEditor editor = getControl();
+ @Override public InputMap<HTMLEditor> getInputMap() {
+ return inputMap;
+ }
+
+ private void keyboardShortcuts(String name) {
+ HTMLEditor editor = getNode();
HTMLEditorSkin editorSkin = (HTMLEditorSkin)editor.getSkin();
editorSkin.keyboardShortcuts(name);
- } else if ("F12".equals(name)) {
- getControl().getImpl_traversalEngine().selectFirst().requestFocus();
- } else {
- super.callAction(name);
- }
}
}