List of usage examples for org.eclipse.jface.bindings.keys KeyStroke NO_KEY
int NO_KEY
To view the source code for org.eclipse.jface.bindings.keys KeyStroke NO_KEY.
Click Source Link
From source file:custom.jface.widgets.ContentProposalAdapterPlus.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/*w ww .j a v a 2 s.c o m*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // See // https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // If the popup is open and this is a valid character, // we // want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation // delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 case SWT.Modify: case SWT.MouseUp: if (allowsAutoActivate() && (watchModify || e.type == SWT.MouseUp)) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { // see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 closeProposalPopup(); } else { // See // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // Given that we will close the popup when there are // no valid proposals, we must consider reopening it // on any // content change when there are no particular // autoActivation // characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but // this // modify event does not involve one of them. // See // if any of the autoactivation characters are // left // in the content and close the popup if none // remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); control.addListener(SWT.MouseUp, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:cz.zcu.yafmt.clang.bcl.ui.externals.CompletionProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/* ww w . j av a 2 s.c om*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. // if (popup != null) { // popup.getTargetControlListener().handleEvent(e); // if (DEBUG) { // StringBuffer sb; // if (e.type == SWT.Traverse) { // sb = new StringBuffer("Traverse"); //$NON-NLS-1$ // } else { // sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ // } // sb.append(" after being handled by popup"); //$NON-NLS-1$ // dump(sb.toString(), e); // } // // See // https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // // If the popup is open and this is a valid character, we // // want to watch for the modified text. // if (propagateKeys && e.character != 0) // watchModify = true; // // return; // } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content // watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { // watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation // delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 // case SWT.Modify: // if (allowsAutoActivate() && watchModify) { // if (DEBUG) { // dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ // } // watchModify = false; // // We are in autoactivation mode, either for specific // // characters or for all characters. In either case, // // we should close the proposal popup when there is no // // content in the control. // if (isControlContentEmpty()) { // // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // closeProposalPopup(); // } else { // // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // // Given that we will close the popup when there are // // no valid proposals, we must consider reopening it on any // // content change when there are no particular autoActivation // // characters // if (autoActivateString == null) { // autoActivate(); // } else { // // Autoactivation characters are defined, but this // // modify event does not involve one of them. See // // if any of the autoactivation characters are left // // in the content and close the popup if none remain. // if (!shouldPopupRemainOpen()) // closeProposalPopup(); // } // } // } // break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:eu.transkribus.swt_gui.transcription.autocomplete.MyContentProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/* ww w. j a v a 2 s . c o m*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { @Override public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { if (isAutoCloseOnSpace() && e.character == SWT.SPACE) { closeProposalPopup(); receivedKeyDown = true; watchModify = true; return; } popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // If the popup is open and this is a valid character, we // want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { // logger.debug("e.character: "+e.character+ " is letterordigit: "+Character.isLetterOrDigit(e.character) // +" autoactivateonletter: "+isAutoActivateOnLetter()); if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else if (isAutoActivateOnLetter()) { if (Character.isLetterOrDigit(e.character)) autoActivate(); } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 case SWT.Modify: if (allowsAutoActivate() && watchModify) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 closeProposalPopup(); } else { // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // Given that we will close the popup when there are // no valid proposals, we must consider reopening it on any // content change when there are no particular autoActivation // characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but this // modify event does not involve one of them. See // if any of the autoactivation characters are left // in the content and close the popup if none remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:gda.rcp.views.ContentProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/*from ww w . j a v a 2s. c o m*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { @Override public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // If the popup is open and this is a valid character, we // want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character was typed, compare it to the * autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 case SWT.Modify: if (allowsAutoActivate() && watchModify) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 closeProposalPopup(); } else { // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // Given that we will close the popup when there are // no valid proposals, we must consider reopening it on any // content change when there are no particular autoActivation // characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but this // modify event does not involve one of them. See // if any of the autoactivation characters are left // in the content and close the popup if none remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:hydrograph.ui.expression.editor.sourceviewer.SourceViewer.java
License:Apache License
private void handleVerifyKeyPressed(VerifyEvent event) { if (!event.doit) { return;/* www . j a va 2 s. co m*/ } try { KeyStroke triggerKeyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist); if (triggerKeyStroke != null) { if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == event.character) || (((triggerKeyStroke.getNaturalKey() == event.keyCode) || (Character.toLowerCase(triggerKeyStroke.getNaturalKey()) == event.keyCode) || (Character.toUpperCase(triggerKeyStroke.getNaturalKey()) == event.keyCode)) && ((triggerKeyStroke.getModifierKeys() & event.stateMask) == triggerKeyStroke .getModifierKeys()))) { doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); event.doit = false; return; } } } catch (Exception e) { } if (event.stateMask != SWT.CTRL) { return; } switch (event.character) { case ' ': doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); event.doit = false; break; case '.': doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); event.doit = false; break; case 'y' - 'a' + 1: doOperation(ITextOperationTarget.REDO); event.doit = false; break; case 'z' - 'a' + 1: doOperation(ITextOperationTarget.UNDO); event.doit = false; break; default: } }
From source file:org.bonitasoft.studio.expression.editor.autocompletion.BonitaContentProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {//from ww w . ja v a 2 s . c o m System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // See // https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // If the popup is open and this is a valid character, // we // want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation // delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 case SWT.Modify: if (allowsAutoActivate() && watchModify) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { // see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 closeProposalPopup(); } else { // See // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // Given that we will close the popup when there are // no valid proposals, we must consider reopening it // on any // content change when there are no particular // autoActivation // characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but // this // modify event does not involve one of them. // See // if any of the autoactivation characters are // left // in the content and close the popup if none // remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:org.cs3.pdt.console.internal.views.completion.ContentProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/* ww w . j ava 2s . co m*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 // If the popup is open and this is a valid character, we // want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStrokes != null) { // Either there are no modifiers for the trigger and we // check the character field... for (KeyStroke triggerKeyStroke : triggerKeyStrokes) { if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the // keycode and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStrokes == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=183650 case SWT.Modify: if (allowsAutoActivate() && watchModify) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192633 closeProposalPopup(); } else { // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=147377 // Given that we will close the popup when there are // no valid proposals, we must consider reopening it on any // content change when there are no particular autoActivation // characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but this // modify event does not involve one of them. See // if any of the autoactivation characters are left // in the content and close the popup if none remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. * * @param who * who is dumping the event * @param e * the event */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:org.csstudio.autocomplete.ui.content.ContentProposalAdapter.java
License:Open Source License
private void addControlListener(Control control) { if (DEBUG) {/*ww w . j a v a 2 s . c om*/ System.out.println("ContentProposalListener#installControlListener()"); //$NON-NLS-1$ } if (controlListener != null) { return; } controlListener = new Listener() { public void handleEvent(Event e) { if (!isEnabled) { return; } switch (e.type) { case SWT.Traverse: case SWT.KeyDown: if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" received by adapter"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open, it gets first shot at the // keystroke and should set the doit flags appropriately. if (popup != null) { popup.getTargetControlListener().handleEvent(e); if (DEBUG) { StringBuffer sb; if (e.type == SWT.Traverse) { sb = new StringBuffer("Traverse"); //$NON-NLS-1$ } else { sb = new StringBuffer("KeyDown"); //$NON-NLS-1$ } sb.append(" after being handled by popup"); //$NON-NLS-1$ dump(sb.toString(), e); } // If the popup is open and this is a valid character, // we want to watch for the modified text. if (propagateKeys && e.character != 0) watchModify = true; return; } // We were only listening to traverse events for the popup if (e.type == SWT.Traverse) { return; } if (e.keyCode == SWT.ARROW_RIGHT) { int pos = getControlContentAdapter().getCursorPosition(getControl()); String contents = getControlContentAdapter().getControlContents(getControl()); if (pos == contents.length()) { e.doit = false; openProposalPopup(false); return; } } // The popup is not open. We are looking at keydown events // for a trigger to open the popup. if (triggerKeyStroke != null) { // Either there are no modifiers for the trigger and we // check the character field... if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == e.character) || // ...or there are modifiers, in which case the keycode // and state must match (triggerKeyStroke.getNaturalKey() == e.keyCode && ((triggerKeyStroke.getModifierKeys() & e.stateMask) == triggerKeyStroke .getModifierKeys()))) { // We never propagate the keystroke for an explicit // keystroke invocation of the popup e.doit = false; openProposalPopup(false); return; } } /* * The triggering keystroke was not invoked. If a character * was typed, compare it to the autoactivation characters. */ if (e.character != 0) { if (autoActivateString != null) { if (autoActivateString.indexOf(e.character) >= 0) { // Prevent weird behavior with top proposals if (e.character == '\b') setPreventTopProposalSelection(true); autoActivate(); } else { // No autoactivation occurred, so record the key // down as a means to interrupt any // autoactivation that is pending due to // autoactivation delay. receivedKeyDown = true; // watch the modify so we can close the popup in // cases where there is no longer a trigger // character in the content watchModify = true; } } else { // The autoactivate string is null. If the trigger // is also null, we want to act on any modification // to the content. Set a flag so we'll catch this // in the modify event. if (triggerKeyStroke == null) { watchModify = true; } } } else { // A non-character key has been pressed. Interrupt any // autoactivation that is pending due to autoactivation // delay. receivedKeyDown = true; } break; // There are times when we want to monitor content changes // rather than individual keystrokes to determine whether // the popup should be closed or opened based on the entire // content of the control. // The watchModify flag ensures that we don't autoactivate if // the content change was caused by something other than typing. case SWT.Modify: if (allowsAutoActivate() && watchModify) { if (DEBUG) { dump("Modify event triggers popup open or close", e); //$NON-NLS-1$ } watchModify = false; // We are in autoactivation mode, either for specific // characters or for all characters. In either case, // we should close the proposal popup when there is no // content in the control. if (isControlContentEmpty()) { closeProposalPopup(); } else { // Given that we will close the popup when there are // no valid proposals, we must consider reopening it // on any content change when there are no // particular autoActivation characters if (autoActivateString == null) { autoActivate(); } else { // Autoactivation characters are defined, but // this modify event does not involve one of // them. See if any of the autoactivation // characters are left in the content // and close the popup if none remain. if (!shouldPopupRemainOpen()) closeProposalPopup(); } } } break; default: break; } } /** * Dump the given events to "standard" output. */ private void dump(String who, Event e) { StringBuffer sb = new StringBuffer("--- [ContentProposalAdapter]\n"); //$NON-NLS-1$ sb.append(who); sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode)); //$NON-NLS-1$ sb.append("; character=" + e.character + hex(e.character)); //$NON-NLS-1$ sb.append("; stateMask=" + e.stateMask + hex(e.stateMask)); //$NON-NLS-1$ sb.append("; doit=" + e.doit); //$NON-NLS-1$ sb.append("; detail=" + e.detail + hex(e.detail)); //$NON-NLS-1$ sb.append("; widget=" + e.widget); //$NON-NLS-1$ System.out.println(sb); } private String hex(int i) { return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$ } }; control.addListener(SWT.KeyDown, controlListener); control.addListener(SWT.Traverse, controlListener); control.addListener(SWT.Modify, controlListener); if (DEBUG) { System.out.println("ContentProposalAdapter#installControlListener() - installed"); //$NON-NLS-1$ } }
From source file:org.eclipse.cdt.debug.internal.ui.CDebugUIUtils.java
License:Open Source License
/** * Formats the given key stroke or click name and the modifier keys * to a key binding string that can be used in action texts. * //from ww w.j a va2 s. c om * @param modifierKeys the modifier keys * @param keyOrClick a key stroke or click, e.g. "Double Click" * @return the formatted keyboard shortcut string, e.g. "Shift+Double Click" * * @since 8.1 */ public static final String formatKeyBindingString(int modifierKeys, String keyOrClick) { // this should actually all be delegated to KeyStroke class return KeyStroke.getInstance(modifierKeys, KeyStroke.NO_KEY).format() + keyOrClick; }
From source file:org.eclipse.eclipsemonkey.actions.RecreateMonkeyMenuAction.java
License:Open Source License
private int getAccelerator(String accelerator) { try {//from w ww . j a v a 2 s. co m KeyStroke instance = KeyStroke.getInstance(accelerator); if (instance != null) { return instance.getNaturalKey() | instance.getModifierKeys(); } } catch (ParseException e) { reportKeyStrokeInvalid(accelerator); } catch (IllegalArgumentException e) { reportKeyStrokeInvalid(accelerator); } return KeyStroke.NO_KEY; }