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;
}
});
}
}
use of org.eclipse.swt.events.KeyListener in project translationstudio8 by heartsome.
the class EnumComboEditor method getEditorControl.
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
_items = new Object[] {};
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
}
Class<?> clazz = column.getContentClass(row);
if (clazz != null && Enum.class.isAssignableFrom(clazz)) {
_items = clazz.getEnumConstants();
} else {
_items = new Object[] {};
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
String[] stringItems = new String[_items.length];
for (int i = 0; i < _items.length; i++) {
stringItems[i] = _items[i].toString();
if (value != null && value.equals(_items[i])) {
selIdx = i;
}
}
_combo.setItems(stringItems);
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
use of org.eclipse.swt.events.KeyListener in project eclipse.platform.swt by eclipse.
the class Bug528549_browser_MouseFocusEventListeners method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
final Browser browser = new Browser(shell, SWT.NONE);
browser.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("Browser Focus lost " + e.toString());
}
@Override
public void focusGained(FocusEvent e) {
System.out.println("Browser Focus gained " + e.toString());
}
});
browser.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("Browser Mouse Up " + e.toString());
}
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Browser Mouse Down " + e.toString());
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("Browse Mouse Double click " + e.toString());
}
});
// Below listeners already worked before bug. But good to have around.
browser.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println("Browser key released " + e.toString());
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Browser key pressed " + e.toString());
}
});
browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
// Generates a lot of events...
browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
Button jsOnButton = new Button(shell, SWT.PUSH);
jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOnButton.setText("JS Off");
jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
Button jsOffButton = new Button(shell, SWT.PUSH);
jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOffButton.setText("JS On");
jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
Button loadNextPage = new Button(shell, SWT.PUSH);
loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
loadNextPage.setText("Load next page");
loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
browser.setText(getNewText());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.events.KeyListener in project vorto by eclipse.
the class AbstractModelRepositoryViewPart method createPartControl.
public void createPartControl(Composite parent) {
parent.setLayout(new FormLayout());
Button btnSearch = createSearchButton(parent);
btnSearch.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String filter = searchField.getText();
try {
viewer.setInput(getModelRepo().search(filter));
} catch (Exception ex) {
ExceptionHandlerFactory.getHandler().handle(ex);
}
}
});
searchField = createSearchField(parent, btnSearch);
searchField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR) {
String filter = searchField.getText();
try {
viewer.setInput(getModelRepo().search(filter));
} catch (Exception ex) {
ExceptionHandlerFactory.getHandler().handle(ex);
}
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
viewer = createTableViewer(parent, btnSearch);
initContextMenu();
}
use of org.eclipse.swt.events.KeyListener in project eclipse.platform.releng by eclipse.
the class CopyrightPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
// The main composite
fComposite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
fComposite.setLayout(layout);
fComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
// copyright template editor
fEditor = createEditor(fComposite);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
data.horizontalIndent = 0;
fInstructions = new Text(fComposite, SWT.READ_ONLY);
// $NON-NLS-1$
fInstructions.setText(Messages.getString("CopyrightPreferencePage.0"));
fInstructions.setLayoutData(data);
// default creation year
fCreationYearLabel = new Label(fComposite, SWT.NONE);
// $NON-NLS-1$
fCreationYearLabel.setText(Messages.getString("CopyrightPreferencePage.1"));
fCreationYear = new Text(fComposite, SWT.BORDER);
fCreationYear.setTextLimit(4);
// default revision year
fRevisionYearLabel = new Label(fComposite, SWT.NONE);
// $NON-NLS-1$
fRevisionYearLabel.setText(Messages.getString("CopyrightPreferencePage.7"));
fRevisionYear = new Text(fComposite, SWT.BORDER);
fRevisionYear.setTextLimit(4);
// always use default revision year instead of cvs lookup
fUseDefaultRevisionYear = new Button(fComposite, SWT.CHECK);
// $NON-NLS-1$
fUseDefaultRevisionYear.setText(Messages.getString("CopyrightPreferencePage.8"));
data = new GridData();
data.horizontalSpan = 2;
fUseDefaultRevisionYear.setLayoutData(data);
// replace all existing copyright statement
fReplaceAllExisting = new Button(fComposite, SWT.CHECK);
// $NON-NLS-1$
fReplaceAllExisting.setText(Messages.getString("CopyrightPreferencePage.2"));
data = new GridData();
data.horizontalSpan = 2;
fReplaceAllExisting.setLayoutData(data);
// disable fix up existing copyright till it works better
// // fix up existing copyright statement
// fFixExisting = new Button(fComposite, SWT.CHECK);
// fFixExisting.setText(Messages.getString("CopyrightPreferencePage.3")); //$NON-NLS-1$
// data = new GridData();
// data.horizontalSpan = 2;
// fFixExisting.setLayoutData(data);
// ignore properties files
fIgnoreProperties = new Button(fComposite, SWT.CHECK);
// $NON-NLS-1$
fIgnoreProperties.setText(Messages.getString("CopyrightPreferencePage.4"));
data = new GridData();
data.horizontalSpan = 2;
fIgnoreProperties.setLayoutData(data);
// [276257] re-enabling xml files
fIgnoreXml = new Button(fComposite, SWT.CHECK);
// $NON-NLS-1$
fIgnoreXml.setText(Messages.getString("CopyrightPreferencePage.9"));
data = new GridData();
data.horizontalSpan = 2;
fIgnoreXml.setLayoutData(data);
KeyListener listener1 = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
validateValues();
}
};
fCreationYear.addKeyListener(listener1);
fRevisionYear.addKeyListener(listener1);
initializeValues();
applyDialogFont(fComposite);
return fComposite;
}
Aggregations