use of org.eclipse.swt.events.FocusListener in project translationstudio8 by heartsome.
the class StyledTextCellEditor method createTextControl.
protected StyledText createTextControl(Composite parent) {
TagStyleManager tagStyleManager = xliffEditor.getTagStyleManager();
IStyle cellStyle = this.hsCellEditor.getCellStyle();
int styled = HorizontalAlignmentEnum.getSWTStyle(cellStyle);
styled |= SWT.MULTI | SWT.WRAP;
viewer = new SegmentViewer(parent, styled, tagStyleManager.getTagStyle());
// 添加标记样式改变监听
// addTagStyleChangeListener();
// 注册标记样式调节器
net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(viewer);
// TagStyleConfigurator.configure(viewer);
// 将原来直接创建StyledText的方式改为由TextViewer提供
final StyledText textControl = viewer.getTextWidget();
initStyle(textControl, cellStyle);
textControl.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
}
public void focusGained(FocusEvent e) {
getActionHandler().updateGlobalActionHandler();
}
});
viewer.getDocument().addDocumentListener(new IDocumentListener() {
public void documentChanged(DocumentEvent e) {
// 自动行高
autoResize();
}
public void documentAboutToBeChanged(DocumentEvent event) {
}
});
// 实现编辑模式下添加右键菜单
// dispose textControl前应去掉右键menu,因为右键menu是和nattable共享的,不能在这儿dispose,说见close()方法
final Menu menu = (Menu) xliffEditor.getTable().getData(Menu.class.getName());
textControl.setMenu(menu);
return textControl;
}
use of org.eclipse.swt.events.FocusListener in project translationstudio8 by heartsome.
the class CustomMatchConditionDialog method setGray.
/**
* 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
* @param text
* Text控件
* @param initTxt
* 灰色提醒字符串
*/
private void setGray(final Text text, final String initTxt) {
text.setForeground(gray);
text.setText(initTxt);
text.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if (text.getText().trim().equals("")) {
if (!text.getForeground().equals(gray)) {
text.setForeground(gray);
}
text.setText(initTxt);
} else {
if (!text.getForeground().equals(black)) {
text.setForeground(black);
}
}
}
public void focusGained(FocusEvent arg0) {
if (text.getText().trim().equals(initTxt)) {
text.setText("");
text.setForeground(black);
} else {
if (!text.getForeground().equals(black)) {
text.setForeground(black);
}
}
}
});
}
use of org.eclipse.swt.events.FocusListener in project translationstudio8 by heartsome.
the class Grid method initListeners.
/**
* Initialize all listeners.
*/
private void initListeners() {
disposeListener = new Listener() {
public void handleEvent(Event e) {
onDispose(e);
}
};
addListener(SWT.Dispose, disposeListener);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
onPaint(e);
}
});
addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
onResize();
}
});
if (getVerticalBar() != null) {
getVerticalBar().addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
onScrollSelection();
}
});
}
if (getHorizontalBar() != null) {
getHorizontalBar().addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
onScrollSelection();
}
});
}
addListener(SWT.KeyDown, new Listener() {
public void handleEvent(Event e) {
onKeyDown(e);
}
});
addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = true;
}
});
addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
onMouseDoubleClick(e);
}
public void mouseDown(MouseEvent e) {
onMouseDown(e);
}
public void mouseUp(MouseEvent e) {
onMouseUp(e);
}
});
addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
onMouseMove(e);
}
});
addMouseTrackListener(new MouseTrackListener() {
public void mouseEnter(MouseEvent e) {
}
public void mouseExit(MouseEvent e) {
onMouseExit(e);
}
public void mouseHover(MouseEvent e) {
}
});
addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
onFocusIn();
redraw();
}
public void focusLost(FocusEvent e) {
redraw();
}
});
// Special code to reflect mouse wheel events if using an external
// scroller
addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event e) {
onMouseWheel(e);
}
});
}
use of org.eclipse.swt.events.FocusListener in project OpenGrok by OpenGrok.
the class ResultsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
filter = new Text(parent, SWT.FILL);
filter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
TextUtils.setToDefault(filter, FILTER_DEFAULT);
filter.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if ("".equals(filter.getText())) {
TextUtils.setToDefault(filter, FILTER_DEFAULT);
}
}
@Override
public void focusGained(FocusEvent e) {
TextUtils.makeEditable(filter);
}
});
filter.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
viewer.refresh();
}
});
return parent;
}
use of org.eclipse.swt.events.FocusListener in project OpenGrok by OpenGrok.
the class ToolBarControl method createControl.
@Override
protected Control createControl(Composite parent) {
final Text searchBox = new Text(parent, SWT.FILL | SWT.BORDER);
TextUtils.setToDefault(searchBox, "{OpenGrok");
searchBox.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!disableFocusLostEvent) {
TextUtils.setToDefault(searchBox, "{OpenGrok");
}
}
@Override
public void focusGained(FocusEvent e) {
TextUtils.makeEditable(searchBox);
}
});
searchBox.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
doSearch();
} else if (e.keyCode == SWT.ARROW_UP) {
historyIndex++;
if (historyIndex > history.size()) {
historyIndex = history.size();
}
if (historyIndex >= 0 && history.size() >= historyIndex) {
searchBox.setText(history.get(historyIndex - 1));
}
} else if (e.keyCode == SWT.ARROW_DOWN) {
historyIndex--;
if (historyIndex < 0) {
historyIndex = 0;
} else if (history.size() > historyIndex) {
searchBox.setText(history.get(historyIndex));
}
} else if ((e.stateMask & SWT.CTRL) == SWT.CTRL && e.keyCode == 'v') {
searchBox.setText("");
searchBox.paste();
if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT) {
doSearch();
}
} else if (e.stateMask == SWT.CTRL && e.keyCode == 'c') {
searchBox.copy();
}
}
private void doSearch() {
String text = searchBox.getText();
if (text != null && !"".equals(text)) {
history.add(0, text);
historyIndex = 0;
Rectangle bounds = searchBox.getBounds();
Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
topLeft = searchBox.getShell().toDisplay(topLeft);
final ResultsDialog dialog = new ResultsDialog(Display.getCurrent().getActiveShell(), text, topLeft);
Query query = new Query(text);
disableFocusLostEvent = true;
query.run(dialog);
disableFocusLostEvent = false;
}
}
});
return parent;
}
Aggregations