use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.
the class UIManager method initialize.
/*
* Only called by maybeInitialize().
*/
private static void initialize() {
Properties swingProps = loadSwingProperties();
initializeSystemDefaults(swingProps);
initializeDefaultLAF(swingProps);
initializeAuxiliaryLAFs(swingProps);
initializeInstalledLAFs(swingProps);
// Install Swing's PaintEventDispatcher
if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
sun.awt.PaintEventDispatcher.setPaintEventDispatcher(new SwingPaintEventDispatcher());
}
// Install a hook that will be invoked if no one consumes the
// KeyEvent. If the source isn't a JComponent this will process
// key bindings, if the source is a JComponent it implies that
// processKeyEvent was already invoked and thus no need to process
// the bindings again, unless the Component is disabled, in which
// case KeyEvents will no longer be dispatched to it so that we
// handle it here.
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor() {
public boolean postProcessKeyEvent(KeyEvent e) {
Component c = e.getComponent();
if ((!(c instanceof JComponent) || (c != null && !c.isEnabled())) && JComponent.KeyboardState.shouldProcess(e) && SwingUtilities.processKeyBindings(e)) {
e.consume();
return true;
}
return false;
}
});
AWTAccessor.getComponentAccessor().setRequestFocusController(JComponent.focusController);
}
use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.
the class InputMethodContext method dispatchCommittedText.
/**
* Dispatches committed text to a client component.
* Called by composition window.
*
* @param client The component that the text should get dispatched to.
* @param text The iterator providing access to the committed
* (and possible composed) text.
* @param committedCharacterCount The number of committed characters in the text.
*/
synchronized void dispatchCommittedText(Component client, AttributedCharacterIterator text, int committedCharacterCount) {
// the event was in the queue.
if (committedCharacterCount == 0 || text.getEndIndex() <= text.getBeginIndex()) {
return;
}
long time = System.currentTimeMillis();
dispatchingCommittedText = true;
try {
InputMethodRequests req = client.getInputMethodRequests();
if (req != null) {
// active client -> send text as InputMethodEvent
int beginIndex = text.getBeginIndex();
AttributedCharacterIterator toBeCommitted = (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();
InputMethodEvent inputEvent = new InputMethodEvent(client, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, toBeCommitted, committedCharacterCount, null, null);
client.dispatchEvent(inputEvent);
} else {
// passive client -> send text as KeyEvents
char keyChar = text.first();
while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED, time, 0, KeyEvent.VK_UNDEFINED, keyChar);
client.dispatchEvent(keyEvent);
keyChar = text.next();
}
}
} finally {
dispatchingCommittedText = false;
}
}
use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.
the class KeyboardFocusManager method retargetFocusEvent.
static AWTEvent retargetFocusEvent(AWTEvent event) {
if (clearingCurrentLightweightRequests) {
return event;
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
if (event instanceof FocusEvent || event instanceof WindowEvent) {
focusLog.finer(">>> {0}", String.valueOf(event));
}
if (focusLog.isLoggable(PlatformLogger.Level.FINER) && event instanceof KeyEvent) {
focusLog.finer(" focus owner is {0}", String.valueOf(manager.getGlobalFocusOwner()));
focusLog.finer(">>> {0}", String.valueOf(event));
}
}
synchronized (heavyweightRequests) {
/*
* This code handles FOCUS_LOST event which is generated by
* DefaultKeyboardFocusManager for FOCUS_GAINED.
*
* This code based on knowledge of DefaultKeyboardFocusManager's
* implementation and might be not applicable for another
* KeyboardFocusManager.
*
* Fix for 4472032
*/
if (newFocusOwner != null && event.getID() == FocusEvent.FOCUS_LOST) {
FocusEvent fe = (FocusEvent) event;
if (manager.getGlobalFocusOwner() == fe.getComponent() && fe.getOppositeComponent() == newFocusOwner) {
newFocusOwner = null;
return event;
}
}
}
processCurrentLightweightRequests();
switch(event.getID()) {
case FocusEvent.FOCUS_GAINED:
{
event = retargetFocusGained((FocusEvent) event);
break;
}
case FocusEvent.FOCUS_LOST:
{
event = retargetFocusLost((FocusEvent) event);
break;
}
default:
}
return event;
}
use of java.awt.event.KeyEvent in project intellij-plugins by JetBrains.
the class ChooseBuildConfigurationDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
List<Module> modules = new ArrayList<>(myTreeItems.keySet());
Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
for (Module module : modules) {
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
root.add(moduleNode);
List<FlexBCConfigurable> bcs = myTreeItems.get(module);
Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
for (FlexBCConfigurable bc : bcs) {
DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
moduleNode.add(bcNode);
}
}
myTree.setModel(new DefaultTreeModel(root));
myTree.setRootVisible(false);
new TreeSpeedSearch(myTree, o -> {
Object lastPathComponent = o.getLastPathComponent();
return getText((DefaultMutableTreeNode) lastPathComponent);
}, true).setComparator(new SpeedSearchComparator(false));
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
updateOnSelectionChange();
}
});
myTree.setCellRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
Object object = treeNode.getUserObject();
if (object instanceof Module) {
Module module = (Module) object;
setIcon(ModuleType.get(module).getIcon());
append(module.getName());
} else if (object instanceof FlexBCConfigurable) {
FlexBCConfigurable configurable = (FlexBCConfigurable) object;
setIcon(configurable.getIcon());
BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
}
}
});
TreeUtil.expandAll(myTree);
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (mySelection != null) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
doOKAction();
}
}
});
updateOnSelectionChange();
return myContentPane;
}
use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.
the class DefaultKeyboardFocusManager method purgeStampedEvents.
// Notes:
// * must be called inside a synchronized block
// * if 'start' is < 0, then this function does nothing
// * if 'end' is < 0, then all KeyEvents from 'start' to the end of the
// queue will be removed
private void purgeStampedEvents(long start, long end) {
if (start < 0) {
return;
}
for (Iterator<KeyEvent> iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
KeyEvent ke = iter.next();
long time = ke.getWhen();
if (start < time && (end < 0 || time <= end)) {
iter.remove();
}
if (end >= 0 && time > end) {
break;
}
}
}
Aggregations