Java Code Examples for org.eclipse.swt.SWT#KEYPAD_SUBTRACT

The following examples show how to use org.eclipse.swt.SWT#KEYPAD_SUBTRACT . 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: CalculatorButtonsComposite.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * 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);

}
 
Example 2
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The Key event handler
 * 
 * @param event
 *            the event
 */
void handleKey(Event event) {
	if (event.stateMask != 0 && event.stateMask != SWT.SHIFT) {
		return;
	}
	if ('\r' == event.keyCode || SWT.KEYPAD_CR == event.keyCode) {
		fieldNext();
		fireSelectionChanged(true);
	} else if (SWT.BS == event.keyCode || SWT.DEL == event.keyCode) {
		event.doit = false;
		setSelection((Date) null);
		fireSelectionChanged();
	} else if (!hasField(activeField) && !hasSelection()) {
		event.doit = false;
	} else {
		switch (event.keyCode) {
		case '-':
		case SWT.KEYPAD_SUBTRACT:
			fieldAdjust(-1);
			break;
		case '=':
		case '+':
		case SWT.KEYPAD_ADD:
			fieldAdjust(1);
			break;
		case SWT.BS:
			if (editField != null) {
				editField.removeLastCharacter();
			}
			break;
		case SWT.CR:
			fieldNext();
			fireSelectionChanged();
			break;
		case SWT.ARROW_DOWN:
			fieldAdjust(-1);
			updateText(true);
			break;
		case SWT.ARROW_UP:
			fieldAdjust(1);
			updateText(true);
			break;
		case SWT.ARROW_LEFT:
			fieldPrev(true);
			break;
		case SWT.ARROW_RIGHT:
			fieldNext(true);
			break;
		case SWT.ESC:
			if (contentShell != null) {
				event.doit = false;
				if (selection.length > 0 && selection[0] != cancelDate) {
					setSelection(cancelDate);
					fireSelectionChanged();
				}
				setOpen(false);
			}
			break;
		default:
			if (hasField(activeField) && activeField + 1 < separator.length
					&& String.valueOf(event.character)
							.equals(separator[activeField + 1])) {
				fieldNext();
			} else if (!hasSelection()
					&& String.valueOf(event.character).matches("[0-9]")) { //$NON-NLS-1$
				fieldAdjust(0);
				fieldFirst();
			}
		}
	}
}