Java Code Examples for org.eclipse.swt.widgets.Control#addKeyListener()

The following examples show how to use org.eclipse.swt.widgets.Control#addKeyListener() . These examples are extracted from open source projects. 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
@Override
protected Control createDialogArea(Composite parent) {
	Composite panel = new Composite(parent, SWT.NONE);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);

	GridLayout panelLayout = new GridLayout(allowIncrementDecrement ? 2 : 1,false);
	panel.setLayout(panelLayout);

	if (allowIncrementDecrement) {
		createUpdateCombo(panel);
	}

	ActiveCellEditor.close();
	ActiveCellEditor.activate(cellEditor, panel, originalCanonicalValue, initialEditValue, dataTypeConverter, cellStyle, dataValidator, new MultiEditHandler(), 0, 0, 0, 0);
	Control editorControl = ActiveCellEditor.getControl();
	// propagate the ESC event from the editor to the dialog
	editorControl.addKeyListener(getEscKeyListener());

	final GridDataFactory layoutData = GridDataFactory.fillDefaults().grab(true, false).hint(100, 20);
	if (allowIncrementDecrement) {
		layoutData.indent(5, 0);
	}
	layoutData.applyTo(editorControl);

	return panel;
}
 
Example 2
@Override
protected Control createDialogArea(Composite parent) {
	Composite panel = new Composite(parent, SWT.NONE);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);

	GridLayout panelLayout = new GridLayout(allowIncrementDecrement ? 2 : 1,false);
	panel.setLayout(panelLayout);

	if (allowIncrementDecrement) {
		createUpdateCombo(panel);
	}

	ActiveCellEditor.close();
	ActiveCellEditor.activate(cellEditor, panel, originalCanonicalValue, initialEditValue, dataTypeConverter, cellStyle, dataValidator, new MultiEditHandler(), 0, 0, 0, 0);
	Control editorControl = ActiveCellEditor.getControl();
	// propagate the ESC event from the editor to the dialog
	editorControl.addKeyListener(getEscKeyListener());

	final GridDataFactory layoutData = GridDataFactory.fillDefaults().grab(true, false).hint(100, 20);
	if (allowIncrementDecrement) {
		layoutData.indent(5, 0);
	}
	layoutData.applyTo(editorControl);

	return panel;
}
 
Example 3
Source Project: hop   File: HopGui.java    License: Apache License 2.0 5 votes vote down vote up
public void replaceKeyboardShortcutListeners( Control control, HopGuiKeyHandler keyHandler ) {

    control.removeKeyListener( keyHandler );
    control.addKeyListener( keyHandler );

    // Add it to all the children as well so we don't have any focus issues
    //
    if ( control instanceof Composite ) {
      for ( Control child : ( (Composite) control ).getChildren() ) {
        replaceKeyboardShortcutListeners( child, keyHandler );
      }
    }
  }
 
Example 4
Source Project: nebula   File: TableRow.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Add listeners to each control.
 * 
 * @param control The control to listen to.
 */
private void addListeners(Control control) {
	control.addKeyListener(keyListener);
	control.addFocusListener(focusListener);
	control.addTraverseListener(traverseListener);
}
 
Example 5
/**
 * Add key listeners
 */
private void addKeyListeners() {
	keyListener = new KeyAdapter() {

		/**
		 * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
		 */
		@Override
		public void keyPressed(final KeyEvent e) {
			switch (e.character) {
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					behaviourEngine.addDigitToDisplay(Integer.parseInt(String.valueOf(e.character)));
					return;
				case '.':
					behaviourEngine.addDecimalPoint();
					return;
				case '+':
					engine.processOperation(CalculatorEngine.OPERATOR_PLUS);
					return;
				case '-':
					engine.processOperation(CalculatorEngine.OPERATOR_MINUS);
					return;
				case '*':
					engine.processOperation(CalculatorEngine.OPERATOR_MULTIPLY);
					return;
				case '/':
					engine.processOperation(CalculatorEngine.OPERATOR_DIVIDE);
					return;
				case '=':
					engine.processEquals();
					return;
				case '%':
					engine.processPerCentageOperation();
					return;

			}

			switch (e.keyCode) {
				case SWT.KEYPAD_0:
				case SWT.KEYPAD_1:
				case SWT.KEYPAD_2:
				case SWT.KEYPAD_3:
				case SWT.KEYPAD_4:
				case SWT.KEYPAD_5:
				case SWT.KEYPAD_6:
				case SWT.KEYPAD_7:
				case SWT.KEYPAD_8:
				case SWT.KEYPAD_9:
					final int digit = e.keyCode - SWT.KEYCODE_BIT - 47;
					behaviourEngine.addDigitToDisplay(digit);
					return;
				case SWT.KEYPAD_ADD:
					engine.processOperation(CalculatorEngine.OPERATOR_PLUS);
					return;
				case SWT.KEYPAD_SUBTRACT:
					engine.processOperation(CalculatorEngine.OPERATOR_MINUS);
					return;
				case SWT.KEYPAD_DIVIDE:
					engine.processOperation(CalculatorEngine.OPERATOR_DIVIDE);
					return;
				case SWT.KEYPAD_MULTIPLY:
					engine.processOperation(CalculatorEngine.OPERATOR_MULTIPLY);
					return;
				case SWT.KEYPAD_CR:
				case SWT.KEYPAD_EQUAL:
				case SWT.CR:
					engine.processEquals();
					return;
				case SWT.BS:
					behaviourEngine.processBackSpace();
					return;
				case SWT.ESC:
					behaviourEngine.clearResult();
					engine.cancel();
					return;
			}
		}
	};

	for (final Control control : getChildren()) {
		control.addKeyListener(keyListener);
	}
	addKeyListener(keyListener);

}