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


   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.web.behavior;
  27 
  28 import javafx.scene.web.HTMLEditor;
  29 import java.util.ArrayList;
  30 import java.util.List;
  31 import com.sun.javafx.scene.control.behavior.BehaviorBase;
  32 import com.sun.javafx.scene.control.behavior.KeyBinding;


  33 import com.sun.javafx.scene.web.skin.HTMLEditorSkin;
  34 import static javafx.scene.input.KeyCode.B;
  35 import static javafx.scene.input.KeyCode.F12;
  36 import static javafx.scene.input.KeyCode.I;
  37 import static javafx.scene.input.KeyCode.TAB;
  38 import static javafx.scene.input.KeyCode.U;
  39 


  40 
  41 /**
  42  * HTML editor behavior.
  43  */
  44 public class HTMLEditorBehavior extends BehaviorBase<HTMLEditor> {
  45     protected static final List<KeyBinding> HTML_EDITOR_BINDINGS = new ArrayList<KeyBinding>();
  46 
  47     static {
  48         HTML_EDITOR_BINDINGS.add(new KeyBinding(B, "bold").shortcut());
  49         HTML_EDITOR_BINDINGS.add(new KeyBinding(I, "italic").shortcut());
  50         HTML_EDITOR_BINDINGS.add(new KeyBinding(U, "underline").shortcut());
  51         
  52         HTML_EDITOR_BINDINGS.add(new KeyBinding(F12, "F12"));
  53         HTML_EDITOR_BINDINGS.add(new KeyBinding(TAB, "TraverseNext").ctrl());
  54         HTML_EDITOR_BINDINGS.add(new KeyBinding(TAB, "TraversePrevious").ctrl().shift());
  55     }
  56 
  57     public HTMLEditorBehavior(HTMLEditor htmlEditor) {
  58         super(htmlEditor, HTML_EDITOR_BINDINGS);











  59     }
  60 
  61     @Override
  62     protected void callAction(String name) {
  63         if ("bold".equals(name) || "italic".equals(name) || "underline".equals(name)) {
  64             HTMLEditor editor = getControl();


  65             HTMLEditorSkin editorSkin = (HTMLEditorSkin)editor.getSkin();
  66             editorSkin.keyboardShortcuts(name);
  67         } else if ("F12".equals(name)) {
  68             getControl().getImpl_traversalEngine().selectFirst().requestFocus();
  69         } else {
  70             super.callAction(name);
  71         }
  72     }
  73 }


   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.web.behavior;
  27 



  28 import com.sun.javafx.scene.control.behavior.BehaviorBase;
  29 import com.sun.javafx.scene.control.inputmap.InputMap;
  30 import com.sun.javafx.scene.control.inputmap.KeyBinding;
  31 import javafx.scene.web.HTMLEditor;
  32 import com.sun.javafx.scene.web.skin.HTMLEditorSkin;
  33 import com.sun.javafx.scene.control.behavior.FocusTraversalInputMap;




  34 
  35 import static javafx.scene.input.KeyCode.*;
  36 import static com.sun.javafx.scene.control.inputmap.InputMap.KeyMapping;
  37 
  38 /**
  39  * HTML editor behavior.
  40  */
  41 public class HTMLEditorBehavior extends BehaviorBase<HTMLEditor> {
  42     private final InputMap<HTMLEditor> inputMap;
  43 









  44 
  45     public HTMLEditorBehavior(HTMLEditor htmlEditor) {
  46         super(htmlEditor);
  47 
  48         this.inputMap = createInputMap();
  49         addDefaultMapping(inputMap,
  50             new KeyMapping(new KeyBinding(B).shortcut(), e -> keyboardShortcuts("bold")),
  51             new KeyMapping(new KeyBinding(I).shortcut(), e -> keyboardShortcuts("italic")),
  52             new KeyMapping(new KeyBinding(U).shortcut(), e -> keyboardShortcuts("underline")),
  53 
  54             new KeyMapping(new KeyBinding(F12), e -> getNode().getImpl_traversalEngine().selectFirst().requestFocus()),
  55             new KeyMapping(new KeyBinding(TAB).ctrl(), FocusTraversalInputMap::traverseNext),
  56             new KeyMapping(new KeyBinding(TAB).ctrl().shift(), FocusTraversalInputMap::traversePrevious)
  57         );
  58     }
  59 
  60     @Override public InputMap<HTMLEditor> getInputMap() {
  61         return inputMap;
  62     }
  63 
  64     private void keyboardShortcuts(String name) {
  65         HTMLEditor editor = getNode();
  66         HTMLEditorSkin editorSkin = (HTMLEditorSkin)editor.getSkin();
  67         editorSkin.keyboardShortcuts(name);





  68     }
  69 }