Java Code Examples for javax.swing.text.DefaultEditorKit#cutAction()

The following examples show how to use javax.swing.text.DefaultEditorKit#cutAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputDefaultsInitTask.java    From darklaf with MIT License 5 votes vote down vote up
private void installCutCopyPasteShortcuts(final InputMap inputMap,
                                          final boolean useSimpleActionKeys) {
    final String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
    final String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
    final String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
    final int mask = SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
    // Ctrl+Ins, Shift+Ins, Shift+Del
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_DOWN_MASK), copyActionKey);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_DOWN_MASK), pasteActionKey);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK), cutActionKey);
    // Ctrl+C, Ctrl+V, Ctrl+X
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask), copyActionKey);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, mask), pasteActionKey);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, mask), DefaultEditorKit.cutAction);
}
 
Example 2
Source File: DarculaLaf.java    From Darcula with Apache License 2.0 5 votes vote down vote up
private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
  String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
  String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
  String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
  // Ctrl+Ins, Shift+Ins, Shift+Del
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), cutActionKey);
  // Ctrl+C, Ctrl+V, Ctrl+X
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), DefaultEditorKit.cutAction);
}
 
Example 3
Source File: LafManagerImplUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
  String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
  String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
  String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
  // Ctrl+Ins, Shift+Ins, Shift+Del
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), cutActionKey);
  // Ctrl+C, Ctrl+V, Ctrl+X
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), DefaultEditorKit.cutAction);
}
 
Example 4
Source File: GUIMain.java    From PacketProxy with Apache License 2.0 4 votes vote down vote up
/**
 * JTextPane上でCommand+Cとかでコピペをできるようにする
 */
private void addShortcutForMac() {
	if (!PacketProxyUtility.getInstance().isMac()) {
		return;
	}
	JPanel p = (JPanel) getContentPane();
	InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	ActionMap am = p.getActionMap();
	int hotkey = (KeyEvent.CTRL_MASK | KeyEvent.META_MASK);
	registerTabShortcut(KeyEvent.VK_H, hotkey, im, am, Panes.HISTORY.ordinal());
	registerTabShortcut(KeyEvent.VK_I, hotkey, im, am, Panes.INTERCEPT.ordinal());
	registerTabShortcut(KeyEvent.VK_R, hotkey, im, am, Panes.REPEATER.ordinal());
	registerTabShortcut(KeyEvent.VK_B, hotkey, im, am, Panes.BULKSENDER.ordinal());
	registerTabShortcut(KeyEvent.VK_O, hotkey, im, am, Panes.OPTIONS.ordinal());
	registerTabShortcut(KeyEvent.VK_L, hotkey, im, am, Panes.LOG.ordinal());

	JTextComponent.KeyBinding[] bindings1 = {
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.copyAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.pasteAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.cutAction),
		new JTextComponent.KeyBinding(
				KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
				DefaultEditorKit.selectAllAction),
	};

	JTextPane component_tp = new JTextPane();
	Keymap keymap_tp = component_tp.getKeymap();
	JTextComponent.loadKeymap(keymap_tp, bindings1, component_tp.getActions());

	JTextField component_tf = new JTextField();
	Keymap keymap_tf = component_tf.getKeymap();
	JTextComponent.loadKeymap(keymap_tf, bindings1, component_tf.getActions());

	JTextArea component_ta = new JTextArea();
	Keymap keymap_ta = component_ta.getKeymap();
	JTextComponent.loadKeymap(keymap_ta, bindings1, component_ta.getActions());
}
 
Example 5
Source File: CallbackSystemActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Object getActionMapKey() {
    return DefaultEditorKit.cutAction;
}
 
Example 6
Source File: UI.java    From whyline with MIT License 4 votes vote down vote up
public static void setOSXFieldShortcuts() {
	
	String lowercaseOSName = System.getProperty("os.name").toLowerCase();
	boolean MAC_OS_X = lowercaseOSName.startsWith("mac os x");

	if(MAC_OS_X) {
		
        Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {
        		"meta C", DefaultEditorKit.copyAction,
                "meta V", DefaultEditorKit.pasteAction,
                "meta X", DefaultEditorKit.cutAction,
                  "COPY", DefaultEditorKit.copyAction,
                 "PASTE", DefaultEditorKit.pasteAction,
                 "CUT", DefaultEditorKit.cutAction,
                 "shift LEFT", DefaultEditorKit.selectionBackwardAction,
                 "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
                 "shift RIGHT", DefaultEditorKit.selectionForwardAction,
                 "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
                 "alt LEFT", DefaultEditorKit.previousWordAction,
                 "alt KP_LEFT", DefaultEditorKit.previousWordAction,
                 "alt RIGHT", DefaultEditorKit.nextWordAction,
                 "alt KP_RIGHT", DefaultEditorKit.nextWordAction,
                 "alt shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
                 "alt shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
                 "alt shift RIGHT", DefaultEditorKit.selectionNextWordAction,
                 "alt shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
                 "meta A", DefaultEditorKit.selectAllAction,
                 "HOME", DefaultEditorKit.beginLineAction,
                 "meta LEFT", DefaultEditorKit.beginLineAction,
                 "END", DefaultEditorKit.endLineAction,
                 "meta RIGHT", DefaultEditorKit.endLineAction,
                 "shift HOME", DefaultEditorKit.selectionBeginLineAction,
                 "meta shift LEFT", DefaultEditorKit.selectionBeginLineAction,
                 "meta shift RIGHT", DefaultEditorKit.selectionEndLineAction,
                 "shift END", DefaultEditorKit.selectionEndLineAction,
                 "typed \010", DefaultEditorKit.deletePrevCharAction,
                 "DELETE", DefaultEditorKit.deleteNextCharAction,
                  //    "alt DELETE", DefaultEditorKit.deleteNextWordAction,
                  // "alt BACKSPACE", DefaultEditorKit.deletePrevWordAction,
                 "RIGHT", DefaultEditorKit.forwardAction,
                 "LEFT", DefaultEditorKit.backwardAction,
                 "UP", DefaultEditorKit.beginAction,
                 "DOWN", DefaultEditorKit.endAction,
                 "shift UP", DefaultEditorKit.selectionBeginAction,
                 "shift DOWN", DefaultEditorKit.selectionEndAction,
                 "KP_RIGHT", DefaultEditorKit.forwardAction,
                 "KP_LEFT", DefaultEditorKit.backwardAction,
                 "ENTER", JTextField.notifyAction,
                 "meta shift A", "unselect"/*DefaultEditorKit.unselectAction*/,
                 "control shift O",
                 "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
        	});

        UIManager.put("TextField.focusInputMap", fieldInputMap);
        UIManager.put("TextArea.focusInputMap", fieldInputMap);
        UIManager.put("TextPane.focusInputMap", fieldInputMap);

	}

}