Search in sources :

Example 41 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project cubrid-manager by CUBRID.

the class AutoIncrementCellEditor method createControl.

protected Control createControl(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    {
        GridLayout gl = new GridLayout(3, false);
        gl.marginHeight = 0;
        gl.marginBottom = 0;
        gl.marginTop = 0;
        gl.marginLeft = 0;
        gl.marginRight = 0;
        gl.marginWidth = 0;
        composite.setLayout(gl);
    }
    startVal = new Text(composite, SWT.BORDER);
    startVal.setLayoutData(new GridData(50, -1));
    startVal.setToolTipText(Messages.lblAutoIncrStart);
    new Label(composite, SWT.NONE).setText(",");
    increVal = new Text(composite, SWT.BORDER);
    increVal.setLayoutData(new GridData(15, -1));
    increVal.setToolTipText(Messages.lblAutoIncrIncr);
    KeyAdapter keyAdapter = new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.character == '\r') {
                deactivateWidget();
            }
        }
    };
    startVal.addKeyListener(keyAdapter);
    increVal.addKeyListener(keyAdapter);
    ModifyListener modifyListener = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            value = getAutoIncrementValue();
            markDirty();
            valueChanged(true, true);
        }
    };
    startVal.addModifyListener(modifyListener);
    increVal.addModifyListener(modifyListener);
    FocusAdapter focusAdapter = new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            deactivateWidget();
            AutoIncrementCellEditor.this.focusLost();
        }
    };
    parent.addFocusListener(focusAdapter);
    return composite;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 42 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project cogtool by cogtool.

the class Keypad method makeEntry.

/**
     * Creates and lays out the elements for the keypad's enter/cancel box.
     *
     * @author Paul Rubritz (ptr@andrew.cmu.edu)
     */
protected void makeEntry() {
    GridLayout grid = new GridLayout();
    grid.numColumns = 3;
    GridData gridKeysOption = new GridData();
    gridKeysOption.horizontalSpan = 2;
    Composite entry = new Composite(dialog, SWT.NONE);
    entry.setLayoutData(gridKeysOption);
    entry.setLayout(grid);
    int width = (keypadType == FULL_KEYPAD) ? FULL_WIDTH : NUMPAD_WIDTH;
    /* text input box */
    enteredText = new Text(entry, SWT.NONE);
    enteredText.setFont(FontUtils.DEFAULT_FONT);
    gridKeysOption = new GridData();
    gridKeysOption.horizontalSpan = 3;
    gridKeysOption.widthHint = width;
    gridKeysOption.heightHint = 100;
    enteredText.setLayoutData(gridKeysOption);
    enteredText.setBackground(getDefaultBGColor());
    enteredText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.keyCode == SWT.ESC) {
                userResponse = null;
                dialog.close();
            }
        }
    });
    /* enter button */
    gridKeysOption = new GridData();
    gridKeysOption.verticalIndent = 10;
    gridKeysOption.horizontalSpan = 2;
    gridKeysOption.widthHint = width / 2;
    gridKeysOption.heightHint = 75;
    gridKeysOption.horizontalAlignment = SWT.RIGHT;
    SelectionListener listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            userResponse = enteredText.getText();
            dialog.close();
        }
    };
    makeButton(entry, ENTER_KEY, gridKeysOption, listener);
    /* cancel button */
    gridKeysOption = new GridData();
    gridKeysOption.verticalIndent = 10;
    gridKeysOption.horizontalSpan = 1;
    gridKeysOption.widthHint = width / 2;
    gridKeysOption.heightHint = 75;
    gridKeysOption.horizontalAlignment = SWT.RIGHT;
    listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            userResponse = null;
            dialog.close();
        }
    };
    makeButton(entry, CANCEL_KEY, gridKeysOption, listener);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 43 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project translationstudio8 by heartsome.

the class ColumnCategoriesDialog method addListenersToListViewer.

private void addListenersToListViewer() {
    listViewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            removeSelected();
        }
    });
    listViewer.getControl().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
            if (controlMask && e.keyCode == SWT.ARROW_UP) {
                moveSelectedUp();
                e.doit = false;
            } else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
                moveSelectedDown();
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                removeSelected();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 44 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project translationstudio8 by heartsome.

the class ColumnChooserDialog method populateDialogArea.

@Override
public void populateDialogArea(Composite parent) {
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
    parent.setLayout(new GridLayout(4, false));
    createLabels(parent, availableLabel, selectedLabel);
    availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    availableTree.setLayoutData(gridData);
    availableTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            addSelected();
        }
    });
    availableTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                addSelected();
        }
    });
    Composite buttonComposite = new Composite(parent, SWT.NONE);
    buttonComposite.setLayout(new GridLayout(1, true));
    Button addButton = new Button(buttonComposite, SWT.PUSH);
    addButton.setImage(GUIHelper.getImage("arrow_right"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    addButton.setLayoutData(gridData);
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            addSelected();
        }
    });
    Button removeButton = new Button(buttonComposite, SWT.PUSH);
    removeButton.setImage(GUIHelper.getImage("arrow_left"));
    gridData = GridDataFactory.copyData(gridData);
    removeButton.setLayoutData(gridData);
    removeButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            removeSelected();
        }
    });
    selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    selectedTree.setLayoutData(gridData);
    selectedTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            removeSelected();
        }
    });
    selectedTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
            if (controlMask && e.keyCode == SWT.ARROW_UP) {
                moveSelectedUp();
                e.doit = false;
            } else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
                moveSelectedDown();
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                removeSelected();
        }
    });
    selectedTree.addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent event) {
            selectedTreeCollapsed(event);
        }

        public void treeExpanded(TreeEvent event) {
            selectedTreeExpanded(event);
        }
    });
    selectedTree.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            toggleColumnGroupSelection((TreeItem) event.item);
        }
    });
    Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
    upDownbuttonComposite.setLayout(new GridLayout(1, true));
    Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
    upButton.setImage(GUIHelper.getImage("arrow_up"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    upButton.setLayoutData(gridData);
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedUp();
        }
    });
    Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
    downButton.setImage(GUIHelper.getImage("arrow_down"));
    gridData = GridDataFactory.copyData(gridData);
    downButton.setLayoutData(gridData);
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedDown();
        }
    });
}
Also used : ISelectionTreeListener(net.sourceforge.nattable.columnChooser.ISelectionTreeListener) TreeListener(org.eclipse.swt.events.TreeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 45 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project translationstudio8 by heartsome.

the class ComboBoxCellEditor method activateCell.

@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
    this.originalCanonicalValue = originalCanonicalValue;
    combo = new NatCombo(parent, getCellStyle(), maxVisibleItems);
    combo.setItems(getDisplayValues());
    if (originalCanonicalValue != null) {
        combo.setSelection(new String[] { getDisplayValue() });
    }
    combo.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if ((event.keyCode == SWT.CR && event.stateMask == 0) || (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
                commit(MoveDirectionEnum.NONE);
            } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
                close();
            }
        }
    });
    combo.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            if (event.keyCode == SWT.TAB && event.stateMask == SWT.SHIFT) {
                commit(MoveDirectionEnum.LEFT);
            } else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
                commit(MoveDirectionEnum.RIGHT);
            }
        }
    });
    combo.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            commit(MoveDirectionEnum.NONE);
        }
    });
    return combo;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) NatCombo(net.sourceforge.nattable.widget.NatCombo) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Aggregations

KeyAdapter (org.eclipse.swt.events.KeyAdapter)80 KeyEvent (org.eclipse.swt.events.KeyEvent)80 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)40 Composite (org.eclipse.swt.widgets.Composite)39 SelectionEvent (org.eclipse.swt.events.SelectionEvent)33 Text (org.eclipse.swt.widgets.Text)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)28 Label (org.eclipse.swt.widgets.Label)24 Button (org.eclipse.swt.widgets.Button)20 TableViewer (org.eclipse.jface.viewers.TableViewer)18 ModifyEvent (org.eclipse.swt.events.ModifyEvent)17 ModifyListener (org.eclipse.swt.events.ModifyListener)16 FocusEvent (org.eclipse.swt.events.FocusEvent)15 Point (org.eclipse.swt.graphics.Point)15 Table (org.eclipse.swt.widgets.Table)14 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12 FocusAdapter (org.eclipse.swt.events.FocusAdapter)11