Java Code Examples for org.eclipse.swt.SWT#KEYPAD_4
The following examples show how to use
org.eclipse.swt.SWT#KEYPAD_4 .
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 |
/** * 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: TexCellListener.java From texlipse with Eclipse Public License 1.0 | 4 votes |
/** * KeyListener method from KeyListener Interface * * Determines the actions to be taken, when a key is pressed. That means * either moving the editing controls to neigboring cell, if a) * CTRL+ArrowKey was pressed b) neighboring cell in that direction exists or * calculating a sum of cells in given direction (and copying it to * clipboard) c) CTRL+KEYPAD_8,_2,_4 or _6 (up, down, left, right) is * pressed * * @param e key event that occured */ public void keyPressed(KeyEvent e) { if ((e.stateMask & (SWT.CTRL | SWT.ALT | SWT.SHIFT)) != SWT.CTRL) return; int row = viewer.getTable().getSelectionIndex(); int columns = viewer.getTable().getColumnCount(); int rows = viewer.getTable().getItemCount(); // FIXME redundant test if ((e.stateMask & (SWT.CTRL | SWT.ALT | SWT.SHIFT)) == SWT.CTRL) { //TexRow texRow = (TexRow) texRowList.getRows().get(row); double sum = 0.0; switch (e.keyCode) { case SWT.ARROW_UP: if (row > 0) viewer.editElement(viewer.getElementAt(row - 1), column); break; case SWT.ARROW_DOWN: /* if (row < rows - 1) // TODO else { add one row to the model } viewer.editElement(viewer.getElementAt(row + 1), column); */ if (row >= rows - 1) texRowList.addRow(); viewer.editElement(viewer.getElementAt(row + 1), column); break; case SWT.ARROW_LEFT: if (column > 0) viewer.editElement(viewer.getElementAt(row), column - 1); break; case SWT.ARROW_RIGHT: if (column < columns - 1) viewer.editElement(viewer.getElementAt(row), column + 1); break; case SWT.KEYPAD_8: sum = texRowList.sum(column, row, TexRowList.SUM_UP); if(row>0) { viewer.editElement(viewer.getElementAt(row - 1), column); ((TexRow)texRowList.getRows().get(row)).setCol(column, ((int)sum==sum)?Integer.toString((int)sum):Double.toString(sum)); viewer.editElement(viewer.getElementAt(row), column); } break; case SWT.KEYPAD_2: sum = texRowList.sum(column, row, TexRowList.SUM_DOWN); if(row<texRowList.getRows().size()-1) { viewer.editElement(viewer.getElementAt(row + 1), column); ((TexRow)texRowList.getRows().get(row)).setCol(column, ((int)sum==sum)?Integer.toString((int)sum):Double.toString(sum)); viewer.editElement(viewer.getElementAt(row), column); } break; case SWT.KEYPAD_4: sum = texRowList.sum(column, row, TexRowList.SUM_LEFT); if(column>0) { viewer.editElement(viewer.getElementAt(row), column-1); ((TexRow)texRowList.getRows().get(row)).setCol(column, ((int)sum==sum)?Integer.toString((int)sum):Double.toString(sum)); viewer.editElement(viewer.getElementAt(row), column); } break; case SWT.KEYPAD_6: sum = texRowList.sum(column, row, TexRowList.SUM_RIGHT); if(column<TexRow.COLUMNS-1) { viewer.editElement(viewer.getElementAt(row), column+1); ((TexRow)texRowList.getRows().get(row)).setCol(column, ((int)sum==sum)?Integer.toString((int)sum):Double.toString(sum)); viewer.editElement(viewer.getElementAt(row), column); } break; } } }