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);
}
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);
}
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);
}
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;
}
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;
}
});
}
}
Aggregations