forked from fanruan/design
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.7 KiB
45 lines
1.7 KiB
8 years ago
|
package com.fr.common.inputevent;
|
||
|
|
||
|
import com.fr.stable.OperatingSystem;
|
||
8 years ago
|
|
||
8 years ago
|
import javax.swing.*;
|
||
|
import javax.swing.text.DefaultEditorKit;
|
||
8 years ago
|
import java.awt.event.KeyEvent;
|
||
|
import java.awt.event.MouseEvent;
|
||
|
|
||
8 years ago
|
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
|
||
|
|
||
8 years ago
|
/**
|
||
8 years ago
|
* Created by hzzz on 2017/5/26.
|
||
8 years ago
|
*/
|
||
8 years ago
|
public class InputEventBaseOnOS {
|
||
|
private static final boolean IS_MACOS = OperatingSystem.isMacOS();
|
||
8 years ago
|
|
||
8 years ago
|
public static boolean isControlDown(MouseEvent e) {
|
||
|
return IS_MACOS ? e.isMetaDown() : e.isControlDown();
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
public static boolean isControlDown(KeyEvent e) {
|
||
|
return IS_MACOS ? e.isMetaDown() : e.isControlDown();
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
public static void addBasicEditInputMap(JComponent jComponent) {
|
||
|
InputMap inputMap = jComponent.getInputMap();
|
||
|
while (inputMap.getParent() != null) {
|
||
|
inputMap = inputMap.getParent();
|
||
|
}
|
||
|
if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) {
|
||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction);
|
||
|
}
|
||
|
if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) {
|
||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction);
|
||
|
}
|
||
|
if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) {
|
||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction);
|
||
|
}
|
||
|
if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) {
|
||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction);
|
||
|
}
|
||
|
}
|
||
8 years ago
|
}
|