/**
* 生成自动提示
*
* @param textObj
* 要自动提示的文本控件
*/
private void createAutoTip(Text textObj, String[] proposals) {
textContentAdapter = new TextContentAdapter() {
/**
* 在控件中添加该关键字
*
* @param control
* @param text
* @param cursorPosition
*/
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
Point selection = ((Text) control).getSelection();
((Text) control).insert(text);
if (cursorPosition < text.length()) {
((Text) control).setSelection(selection.x + cursorPosition, selection.x + cursorPosition);
}
}
/**
* 设置关键字
*
* @param control
* @param text
* @param cursorPosition
*/
@Override
public void setControlContents(Control control, String text, int cursorPosition) {
int len = textObj.getText().lastIndexOf(" ");
String temp = textObj.getText();
if (len == -1) {
super.setControlContents(control, text, cursorPosition);
} else {
temp = temp.substring(0, temp.lastIndexOf(" "));
temp = temp.concat(" ").concat(text);
super.setControlContents(control, temp, cursorPosition);
}
}
/**
* 处理搜索关键字
*
* @param control
* @return
*/
@Override
public String getControlContents(Control control) {
String temp = ((Text) control).getText();
temp = temp.substring(temp.lastIndexOf(" ") + 1);
return temp;
}
public Point getSelection(Control control) {
return super.getSelection(textObj);
}
@Override
public Rectangle getInsertionBounds(Control control) {
return super.getInsertionBounds(control);
}
@Override
public void setSelection(Control control, Point range) {
super.setSelection(control, range);
}
};
autoCompleteField = new AutoCompleteField(textObj, textContentAdapter, proposals);
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/17875.html