Search in sources :

Example 1 with CursorKeyListener

use of net.sourceforge.ehep.events.CursorKeyListener in project core by jcryptool.

the class HexEditorControl method addCursorListeners.

/**
 * Adds some cursor listeners
 * @param cursor table cursor
 * @param editor table editor
 */
private void addCursorListeners(final TableCursor cursor, final ControlEditor editor) {
    // 
    // Add key listener
    // 
    cursorKeyListener = new CursorKeyListener(this, hexEditor, cursor, editor);
    cursor.addKeyListener(cursorKeyListener);
    // 
    // Add selection listener
    // 
    cursor.addSelectionListener(new SelectionAdapter() {

        // 
        // When the TableEditor is over a cell, select the corresponding row in the table
        // 
        public void widgetSelected(SelectionEvent e) {
            // 
            if (cursorKeyListener.getText() != null) {
                String str = cursorKeyListener.getText().getText().toUpperCase();
                if (Utils.isValidHexNumber(str)) {
                    cursorKeyListener.getCellEditorKeyListener().closeCellEditor(cursorKeyListener.getEventRow(), cursorKeyListener.getEventColumn(), str);
                } else {
                    cursorKeyListener.setSelection();
                    return;
                }
            }
            table.setSelection(new TableItem[] { cursor.getRow() });
            HexTablePointer p = getCursorPosition();
            table.setCellSelection(p.getRowIndex(), p.getColumnIndex(), cursorKeyListener.isShiftHold());
            updateStatusPanel();
        }

        // 
        // When the user hits "ENTER" in the TableCursor, pop up a text editor so that
        // they can change the text of the cell
        // 
        public void widgetDefaultSelected(SelectionEvent e) {
            table.setSelection(new TableItem[] { cursor.getRow() });
        }
    });
}
Also used : CursorKeyListener(net.sourceforge.ehep.events.CursorKeyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

CursorKeyListener (net.sourceforge.ehep.events.CursorKeyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 TableItem (org.eclipse.swt.widgets.TableItem)1