Search in sources :

Example 21 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addKeyListenerKeyPressedAdapterLorg_eclipse_swt_events_KeyListener.

@Test
public void test_addKeyListenerKeyPressedAdapterLorg_eclipse_swt_events_KeyListener() {
    KeyListener listener = KeyListener.keyPressedAdapter(event -> eventOccurred = true);
    control.addKeyListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyDown, new Event());
    assertTrue(eventOccurred);
    control.removeKeyListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyDown, new Event());
    assertFalse(eventOccurred);
}
Also used : FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyListener(org.eclipse.swt.events.KeyListener) Test(org.junit.Test)

Example 22 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addKeyListenerLorg_eclipse_swt_events_KeyListener.

@Test
public void test_addKeyListenerLorg_eclipse_swt_events_KeyListener() {
    KeyListener listener = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            eventOccurred = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            eventOccurred = true;
        }
    };
    control.addKeyListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyDown, new Event());
    assertTrue(eventOccurred);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyUp, new Event());
    assertTrue(eventOccurred);
    control.removeKeyListener(listener);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyListener(org.eclipse.swt.events.KeyListener) Test(org.junit.Test)

Example 23 with KeyListener

use of org.eclipse.swt.events.KeyListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addKeyListenerKeyReleasedAdapterLorg_eclipse_swt_events_KeyListener.

@Test
public void test_addKeyListenerKeyReleasedAdapterLorg_eclipse_swt_events_KeyListener() {
    KeyListener listener = KeyListener.keyReleasedAdapter(event -> eventOccurred = true);
    control.addKeyListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyUp, new Event());
    assertTrue(eventOccurred);
    control.removeKeyListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.KeyUp, new Event());
    assertFalse(eventOccurred);
}
Also used : FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyListener(org.eclipse.swt.events.KeyListener) Test(org.junit.Test)

Example 24 with KeyListener

use of org.eclipse.swt.events.KeyListener in project yamcs-studio by yamcs.

the class MultilineTextEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite container = (Composite) super.createDialogArea(parent);
    // Single Text area within container.
    // Resize doesn't fully work, at least on OS X:
    // Making the Dialog bigger is fine, vertical scrollbars also work.
    // But when making the Dialog smaller, no horiz. scrollbars appear.
    final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    // gridData.widthHint = 300;
    gridData.heightHint = 150;
    text = new Text(container, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setText(contents);
    text.setSelection(0, contents.length());
    text.setLayoutData(gridData);
    text.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character == '\r') {
                // Return key
                if ((e.stateMask & SWT.CTRL) != 0) {
                    okPressed();
                }
            }
            return;
        }
    });
    return container;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener)

Example 25 with KeyListener

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

the class DateCellEditor method createControl.

/**
     * Create the chooser control.
     * 
     * @param table parent table.
     */
private void createControl(JaretTable table) {
    _table = table;
    if (_chooser == null) {
        _chooser = new DateChooser(table, SWT.NULL);
        // TODO locale dependent
        IFieldIdentifier fi = new SimpleFieldIdentifier(".", new int[] { Calendar.DAY_OF_MONTH, Calendar.MONTH, Calendar.YEAR });
        _chooser.setFieldIdentifier(fi);
        _chooser.setSelectAllOnFocusGained(false);
        _chooser.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        _chooser.addFocusListener(this);
        _chooser.addDateChooserListener(this);
        _chooser.getTextField().addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent event) {
                if (event.keyCode == SWT.TAB) {
                    _chooser.validateInput();
                    stopEditing(true);
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                    _table.focusRight();
                } else if (event.keyCode == SWT.CR) {
                    _chooser.validateInput();
                    stopEditing(true);
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                    _table.focusDown();
                } else if (event.keyCode == SWT.ESC) {
                    stopEditing(false);
                    restoreOldVal();
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                }
            }

            public void keyReleased(KeyEvent e) {
            }
        });
        // add a traverse listener so the TAB-key won't traverse the focus out of the table
        _chooser.getTextField().addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                e.doit = false;
            }
        });
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SimpleFieldIdentifier(de.jaret.util.ui.datechooser.SimpleFieldIdentifier) IFieldIdentifier(de.jaret.util.ui.datechooser.IFieldIdentifier) KeyListener(org.eclipse.swt.events.KeyListener) DateChooser(de.jaret.util.ui.datechooser.DateChooser)

Aggregations

KeyListener (org.eclipse.swt.events.KeyListener)47 KeyEvent (org.eclipse.swt.events.KeyEvent)44 MouseEvent (org.eclipse.swt.events.MouseEvent)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 Point (org.eclipse.swt.graphics.Point)14 GridData (org.eclipse.swt.layout.GridData)13 Button (org.eclipse.swt.widgets.Button)11 FocusEvent (org.eclipse.swt.events.FocusEvent)10 MouseListener (org.eclipse.swt.events.MouseListener)9 Composite (org.eclipse.swt.widgets.Composite)9 ModifyEvent (org.eclipse.swt.events.ModifyEvent)8 ModifyListener (org.eclipse.swt.events.ModifyListener)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 Event (org.eclipse.swt.widgets.Event)8 Text (org.eclipse.swt.widgets.Text)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 StyledText (org.eclipse.swt.custom.StyledText)6 ControlEvent (org.eclipse.swt.events.ControlEvent)6 Label (org.eclipse.swt.widgets.Label)6