Java Code Examples for java.awt.event.KeyEvent#consume()

The following examples show how to use java.awt.event.KeyEvent#consume() . 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: TextEditorComponentProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Overridden so that our text area will properly consume key events for registered
 * actions.  By default the JComponents will not process a keystroke with an
 * assigned keybinding *if the assigned action is not enabled*.  We want to always
 * process registered keystrokes so that they do not get handled elsewhere in
 * Ghidra accidentally. For example, Ctrl-S is bound to save for this text area.  If
 * there have been no changes in the data, then the save action is not enabled.  So,
 * when the user presses Ctrl-S in this window, then, by default, the text area will
 * not consume the event and the event will end up moving up to the tool level and
 * executing a save there, which is clearly not the intended effect.  In this example
 * we really just want this window to do nothing if the save is not enabled.
 */
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition,
		boolean pressed) {

	InputMap map = getInputMap(condition);
	ActionMap am = getActionMap();
	if (map != null && am != null && isEnabled()) {
		Object binding = map.get(ks);
		Action action = (binding == null) ? null : am.get(binding);
		if (action != null) {
			if (!action.isEnabled()) {
				// we want to consume the event here, so Ghidra doesn't get to
				// process it when the actions are disabled
				e.consume();
				return true;
			}

			return SwingUtilities.notifyAction(action, ks, e, this, e.getModifiersEx());
		}
	}
	return false;
}
 
Example 2
Source File: SpringXMLConfigCompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if(evt.getKeyChar() == '.') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent)evt.getSource();
            int caretOffset = component.getSelectionEnd();
            int len = caretOffset - substitutionOffset;
            if (len >= 0) {
                substituteText(component, substitutionOffset, len, Character.toString(evt.getKeyChar()));
                Completion.get().showCompletion();
                evt.consume();
            }
        }
    }
}
 
Example 3
Source File: CheckListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() != KeyEvent.VK_SPACE) {
        return;
    }
    if (!(e.getSource() instanceof JList)) {
        return;
    }
    JList list = (JList) e.getSource();
    Object selected = list.getSelectedValue();
    if (selected == null) {
        return;
    }
    toggle(selected);
    e.consume();
}
 
Example 4
Source File: PdfPanel.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void keyTyped(KeyEvent event) {
    if (!event.isConsumed() && (event.getModifiersEx() & getToolkit().getMenuShortcutKeyMaskEx()) == 0) {
        char ch = event.getKeyChar();
        switch (ch) {
        case '-':
            zoomOut();
            break;
        case '=':
            zoomIn();
            break;
        case '1':
            actualSize();
            break;
        default:
            return;
        }
        event.consume();
    }
}
 
Example 5
Source File: ChatboxTextMenuInput.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
	{
		e.consume();
	}
}
 
Example 6
Source File: KeyRemappingListener.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void keyTyped(KeyEvent e)
{
	char keyChar = e.getKeyChar();
	if (keyChar != KeyEvent.CHAR_UNDEFINED && blockedChars.contains(keyChar) && plugin.chatboxFocused())
	{
		e.consume();
	}
}
 
Example 7
Source File: DefaultKeyboardFocusManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean consumeProcessedKeyEvent(KeyEvent e) {
    if ((e.getID() == KeyEvent.KEY_TYPED) && consumeNextKeyTyped) {
        e.consume();
        consumeNextKeyTyped = false;
        return true;
    }
    return false;
}
 
Example 8
Source File: Keyboard.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(InstanceState state, KeyEvent e) {
	KeyboardData data = getKeyboardState(state);
	boolean changed = false;
	boolean used = true;
	synchronized (data) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_DELETE:
			changed = data.delete();
			break;
		case KeyEvent.VK_LEFT:
			data.moveCursorBy(-1);
			break;
		case KeyEvent.VK_RIGHT:
			data.moveCursorBy(1);
			break;
		case KeyEvent.VK_HOME:
			data.setCursor(0);
			break;
		case KeyEvent.VK_END:
			data.setCursor(Integer.MAX_VALUE);
			break;
		default:
			used = false;
		}
	}
	if (used)
		e.consume();
	if (changed)
		state.getInstance().fireInvalidated();
}
 
Example 9
Source File: Treeline.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {
	if (isTagging()) {
		super.keyPressed(ke);
		return;
	}
	final int tool = ProjectToolbar.getToolId();
	try {
		if (ProjectToolbar.PEN == tool) {
			final Object origin = ke.getSource();
			if (! (origin instanceof DisplayCanvas)) {
				ke.consume();
				return;
			}
			final DisplayCanvas dc = (DisplayCanvas)origin;
			final Layer layer = dc.getDisplay().getLayer();
			final Point p = dc.getCursorLoc(); // as offscreen coords

			switch (ke.getKeyCode()) {
				case KeyEvent.VK_O:
					if (askAdjustRadius(p.x, p.y, layer, dc.getMagnification())) {
						ke.consume();
					}
					break;
			}
		}
	} finally {
		if (!ke.isConsumed()) {
			super.keyPressed(ke);
		}
	}
}
 
Example 10
Source File: IOLocationTileList.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void keyTyped(KeyEvent e) {
	char c = e.getKeyChar();
	if (Character.isDefined(c)) {
		sb.append(c);

		stringTyped(sb.toString());

		lastType = System.currentTimeMillis();
		purgeText.start();
		e.consume();
	}
}
 
Example 11
Source File: ETable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_ESCAPE) {
        removeSearchField();
        ETable.this.requestFocus();
    } else if (keyCode == KeyEvent.VK_UP) {
        currentSelectionIndex--;
        displaySearchResult();
        // Stop processing the event here. Otherwise it's dispatched
        // to the table too (which scrolls)
        e.consume();
    } else if (keyCode == KeyEvent.VK_DOWN) {
        currentSelectionIndex++;
        displaySearchResult();
        // Stop processing the event here. Otherwise it's dispatched
        // to the table too (which scrolls)
        e.consume();
    } else if (keyCode == KeyEvent.VK_TAB) {
        if (maxPrefix != null) {
            searchTextField.setText(maxPrefix);
        }
        e.consume();
    } else if (keyCode == KeyEvent.VK_ENTER) {
        removeSearchField();
        
        // TODO: do something on hitting enter???
        e.consume();
        ETable.this.requestFocus();
    }
}
 
Example 12
Source File: CompletionLayout.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void processKeyEvent(KeyEvent evt) {
          if (isVisible()) {
if (KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0).equals(
	KeyStroke.getKeyStrokeForEvent(evt))
) {
    evt.consume();
    CompletionImpl.get().hideToolTip();
}
          }
      }
 
Example 13
Source File: LogFilterTextField.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected boolean preprocessEventForTextField(KeyEvent e) {
  if ((KeyEvent.VK_ENTER == e.getKeyCode()) || ('\n' == e.getKeyChar())) {
    e.consume();
    addCurrentTextToHistory();
  }
  return super.preprocessEventForTextField(e);
}
 
Example 14
Source File: InitializrProjectPanelVisual2.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
        // if empty let the event bubble up to parent components
        if (!txFilter.getText().isEmpty()) {
            clearFilter();
            e.consume();
        }
    }
}
 
Example 15
Source File: DisabledGlassPane.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    e.consume();
}
 
Example 16
Source File: DefaultKeyboardFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void consumeTraversalKey(KeyEvent e) {
    e.consume();
    consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
                          !e.isActionKey();
}
 
Example 17
Source File: Keyboard.java    From hack-a-drone with Apache License 2.0 4 votes vote down vote up
/**
 * Handles a key event.
 *
 * @param keyEvent the key event to handle
 * @param isPressed if the key is pressed or not
 */
private void onKeyEvent(KeyEvent keyEvent, boolean isPressed) {
    int value = isPressed ? 127 : 0;
    boolean input = true;

    switch (keyEvent.getKeyCode()) {
        case VK_W:
            command.setPitch(value);
            break;
        case VK_S:
            command.setPitch(-value);
            break;
        case VK_A:
            command.setRoll(-value);
            break;
        case VK_D:
            command.setRoll(value);
            break;
        case VK_Q:
            command.setYaw(-value);
            break;
        case VK_E:
            command.setYaw(value);
            break;
        case VK_LEFT:
            command.setTakeOff(isPressed);
            break;
        case VK_RIGHT:
            command.setLand(isPressed);
            break;
        case VK_UP:
            command.setThrottle(value);
            break;
        case VK_DOWN:
            command.setThrottle(-value);
            break;
        default:
            input = false;
    }

    if (commandListener != null && input) {
        commandListener.onCommandReceived(command);
    }

    keyEvent.consume();
}
 
Example 18
Source File: ShortcutEnterPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void keyTyped(KeyEvent e) {
    e.consume();
}
 
Example 19
Source File: DefaultKeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void consumeTraversalKey(KeyEvent e) {
    e.consume();
    consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
                          !e.isActionKey();
}
 
Example 20
Source File: DefaultKeyboardFocusManager.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void consumeTraversalKey(KeyEvent e) {
    e.consume();
    consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
                          !e.isActionKey();
}