下面列出了java.awt.event.InputEvent#isShiftDown() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String buildModifiersText(InputEvent e) {
StringBuilder sb = new StringBuilder();
if (e.isAltDown()) {
sb.append("Alt+");
}
if (e.isControlDown()) {
sb.append("Ctrl+");
}
if (e.isMetaDown()) {
sb.append("Meta+");
}
if (e.isShiftDown()) {
sb.append("Shift+");
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
String mtext = sb.toString();
return mtext;
}
@Override
public void update(AnActionEvent e) {
super.update(e);
Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
e.getPresentation().setEnabled(false);
return;
}
Project project = getEventProject(e);
if (project != null) {
InputEvent inputEvent = e.getInputEvent();
boolean onlyAltDown = false;
if (inputEvent != null) {
onlyAltDown = inputEvent.isAltDown() && !inputEvent.isShiftDown() && !inputEvent.isMetaDown() && !inputEvent.isControlDown();
}
LookupEx activeLookup = LookupManager.getInstance(project).getActiveLookup();
boolean dialogOpen = isFromDialog(project);
boolean popupCheck = activeLookup == null || (activeLookup != null && !onlyAltDown);
boolean dialogCheck = !dialogOpen || (dialogOpen && !onlyAltDown);
e.getPresentation().setEnabled((popupCheck && dialogCheck));
}
}
public int recordModifiers(final InputEvent e) {
final int shiftValue = e.isShiftDown() ? KEYBOARD.SHIFT : 0;
final int ctrlValue = e.isControlDown() ? KEYBOARD.CTRL : 0;
final int optValue = e.isAltDown() || e.isAltGraphDown() ? KEYBOARD.ALT : 0;
final int cmdValue = e.isMetaDown() ? KEYBOARD.CMD : 0;
final int modifiers = shiftValue + ctrlValue + optValue + cmdValue;
buttons = buttons & ~KEYBOARD.ALL | modifiers;
return modifiers;
}
@Override
public void handleSelect(boolean handleFinalChoices, InputEvent e) {
if (e instanceof MouseEvent && e.isShiftDown()) {
handleShiftClick(handleFinalChoices, e, this);
return;
}
_handleSelect(handleFinalChoices, e);
}
/**
* {@code isShiftLeftMouseButton} detects SHIFT-BUTTON1
* events for flipping pane shortcuts.
*
* @param e {@code MouseEvent}, the event
*
* @return {@code boolean}, the condition
*/
@Contract(pure = true)
static boolean isShiftLeftMouseButton(InputEvent e)
{
return ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) && e.isShiftDown();
}
/**
* {@code isShiftLeftMouseButton} detects SHIFT-BUTTON1
* events for flipping pane shortcuts.
*
* @param e {@code MouseEvent}, the event
*
* @return {@code boolean}, the condition
*/
@Contract(pure = true)
static boolean isShiftLeftMouseButton(InputEvent e)
{
return ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) && e.isShiftDown();
}