use of org.eclipse.swt.events.MouseMoveListener in project uiautomatorviewer by yangzaiCN.
the class UiAutomatorViewer method createContents.
/**
* Create contents of the application window.
*
* @param parent
*/
@Override
protected Control createContents(Composite parent) {
UiAutomatorModel.createInstance(this);
Composite basePane = new Composite(parent, SWT.NONE);
basePane.setLayout(new GridLayout(2, false));
mScreenshotCanvas = new Canvas(basePane, SWT.NONE);
mScreenshotCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
UiAutomatorModel.getModel().toggleExploreMode();
}
});
mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
mScreenshotCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
mScreenshotCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (mCachedScaleImage != null) {
// shifting the image here, so that there's a border around screen shot
// this makes highlighting red rectangles on the screen shot edges more visible
e.gc.drawImage(mCachedScaleImage, IMG_BORDER, IMG_BORDER);
Rectangle rect = UiAutomatorModel.getModel().getCurrentDrawingRect();
if (rect != null) {
e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
if (UiAutomatorModel.getModel().isExploreMode()) {
// when we highlight nodes dynamically on mouse move,
// use dashed borders
e.gc.setLineStyle(SWT.LINE_DASH);
e.gc.setLineWidth(1);
} else {
// when highlighting nodes on tree node selection,
// use solid borders
e.gc.setLineStyle(SWT.LINE_SOLID);
e.gc.setLineWidth(2);
}
e.gc.drawRectangle(IMG_BORDER + getScaledSize(rect.x), IMG_BORDER + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height));
}
}
}
});
mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (UiAutomatorModel.getModel().isExploreMode()) {
UiAutomatorModel.getModel().updateSelectionForCoordinates(getInverseScaledSize(e.x - IMG_BORDER), getInverseScaledSize(e.y - IMG_BORDER));
}
}
});
mScreenshotCanvas.setBackgroundImage(ImageHelper.loadImageDescriptorFromResource("images/logo.png").createImage());
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.add(mOpenFilesAction);
toolBarManager.add(mExpandAllAction);
toolBarManager.add(mScreenshotAction);
toolBarManager.createControl(basePane);
mTreeViewer = new TreeViewer(basePane, SWT.BORDER);
Tree tree = mTreeViewer.getTree();
GridData gd_Tree = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
gd_Tree.widthHint = 350;
tree.setLayoutData(gd_Tree);
mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
// default LabelProvider uses toString() to generate text to display
mTreeViewer.setLabelProvider(new LabelProvider());
mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection().isEmpty()) {
UiAutomatorModel.getModel().setSelectedNode(null);
} else if (event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object o = selection.toArray()[0];
if (o instanceof BasicTreeNode) {
UiAutomatorModel.getModel().setSelectedNode((BasicTreeNode) o);
}
}
}
});
// move focus so that it's not on tool bar (looks weird)
tree.setFocus();
Group grpNodeDetail = new Group(basePane, SWT.NONE);
grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
GridData gd_grpNodeDetail = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_grpNodeDetail.heightHint = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.minimumHeight = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.widthHint = FIXED_RHS_WIDTH;
gd_grpNodeDetail.minimumWidth = FIXED_RHS_WIDTH;
grpNodeDetail.setLayoutData(gd_grpNodeDetail);
grpNodeDetail.setText("Node Detail");
Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableColumnLayout columnLayout = new TableColumnLayout();
tableContainer.setLayout(columnLayout);
mTableViewer = new TableViewer(tableContainer, SWT.BORDER | SWT.FULL_SELECTION);
Table table = mTableViewer.getTable();
table.setLinesVisible(true);
// use ArrayContentProvider here, it assumes the input to the TableViewer
// is an array, where each element represents a row in the table
mTableViewer.setContentProvider(new ArrayContentProvider());
TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// first column, shows the attribute name
return ((AttributePair) element).key;
}
return super.getText(element);
}
});
columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// second column, shows the attribute value
return ((AttributePair) element).value;
}
return super.getText(element);
}
});
return basePane;
}
use of org.eclipse.swt.events.MouseMoveListener 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.MouseMoveListener in project translationstudio8 by heartsome.
the class SegmentViewer method initListeners.
private void initListeners() {
StyledText styledText = getTextWidget();
// 去掉默认的复制、粘贴键绑定,以实现在复制、粘贴前对标记的处理
styledText.setKeyBinding('V' | SWT.MOD1, SWT.NULL);
styledText.setKeyBinding(SWT.INSERT | SWT.MOD2, SWT.NULL);
styledText.setKeyBinding('C' | SWT.MOD1, SWT.NULL);
styledText.setKeyBinding(SWT.INSERT | SWT.MOD1, SWT.NULL);
getDocument().addDocumentListener(new IDocumentListener() {
public void documentChanged(DocumentEvent e) {
}
public void documentAboutToBeChanged(DocumentEvent event) {
String method = belongToUndoOrRedo();
if (event.getLength() > 0 && method != null) {
try {
String text = event.getDocument().get(event.getOffset(), event.getLength());
Matcher matcher = PATTERN.matcher(text);
List<InnerTag> cache = new ArrayList<InnerTag>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag innerTag = InnerTagUtil.getInnerTag(getInnerTagCacheList(), placeHolder);
if (innerTag != null && innerTag.isVisible()) {
innerTag.setVisible(false);
if ("undo".equals(method) && innerTag.getInnerTagBean().isWrongTag()) {
cache.add(innerTag);
}
}
}
for (InnerTag t : cache) {
innerTagCacheList.remove(t);
t.dispose();
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
/**
* 是否属于撤销或者重做的操作。
* @return ;
*/
private String belongToUndoOrRedo() {
IUndoManager undoManager = getUndoManager();
if (undoManager != null) {
StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
for (StackTraceElement stackTraceElement : stackTraceElements) {
if (undoManager.getClass().getName().equals(stackTraceElement.getClassName())) {
String methodName = stackTraceElement.getMethodName();
if ("undo".equals(methodName) || "redo".equals(methodName)) {
return methodName;
}
}
}
}
return null;
}
});
/**
* 处理在显示非打印隐藏字符的情况光标移动问题。兼容非打印字符替换符号
*/
styledText.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
if (e.stateMask == SWT.NONE && (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
styledText.setCaretOffset(offset - 1);
}
}
}
public void keyPressed(KeyEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
if (e.stateMask == SWT.NONE && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.setCaretOffset(offset - 1);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.setCaretOffset(offset + 1);
}
}
} else if (e.stateMask == SWT.CTRL && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
// 单独对 ctrl + right ,ctrl + left 换行的处理
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.setCaretOffset(offset - 1);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.setCaretOffset(offset + 1);
}
}
} else if ((e.stateMask == SWT.SHIFT || e.stateMask == (SWT.SHIFT | SWT.CTRL)) && (e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
if (e.keyCode == SWT.ARROW_LEFT) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
} else if ((e.stateMask == SWT.SHIFT) && (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN)) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
char c = styledText.getText().charAt(offset);
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char _c = styledText.getText().charAt(offset - 1);
if (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER)) {
if (e.keyCode == SWT.ARROW_UP) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (e.keyCode == SWT.ARROW_DOWN) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
}
}
});
/**
* 处理在显示非打印隐藏字符的情况光标移动问题。兼容非打印字符替换符号
*/
styledText.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
// hidden character
char c = styledText.getText().charAt(offset);
// display character
char _c = styledText.getText().charAt(offset - 1);
if ((_c == Constants.LINE_SEPARATOR_CHARACTER || _c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER) && (c == '\n' || c == '')) {
styledText.setCaretOffset(offset + 1);
}
}
public void mouseDoubleClick(MouseEvent e) {
}
});
/**
* 选择内容时对非打印字符的处理
*/
styledText.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
StyledText styledText = (StyledText) e.widget;
int offset = styledText.getCaretOffset();
if (offset < 1 || offset >= styledText.getCharCount()) {
return;
}
char c = styledText.getText().charAt(offset);
char _c = styledText.getText().charAt(offset - 1);
if ((c == '' && (_c == Constants.TAB_CHARACTER || _c == Constants.SPACE_CHARACTER)) || (c == '\n' && (_c == Constants.LINE_SEPARATOR_CHARACTER))) {
int caretOffset = styledText.getCaretOffset();
Point p = styledText.getSelection();
if (caretOffset == p.x) {
styledText.invokeAction(ST.SELECT_COLUMN_PREVIOUS);
} else if (caretOffset == p.y) {
styledText.invokeAction(ST.SELECT_COLUMN_NEXT);
}
}
}
});
styledText.addVerifyListener(new VerifyListener() {
public void verifyText(final VerifyEvent e) {
String t = e.text;
if ((e.start == e.end) || (e.start != e.end && !e.text.equals(""))) {
// 添加内容时
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
t = t.replace("\t", Constants.TAB_CHARACTER + "").replace(" ", Constants.SPACE_CHARACTER + "");
t = t.replace(System.getProperty("line.separator"), "\n");
StringBuffer bf = new StringBuffer(t);
int i = bf.indexOf("\n");
if (i != -1) {
if (i == 0) {
bf.insert(i, Constants.LINE_SEPARATOR_CHARACTER);
} else if (i != 0 && bf.charAt(i - 1) != Constants.LINE_SEPARATOR_CHARACTER) {
bf.insert(i, Constants.LINE_SEPARATOR_CHARACTER);
}
i = bf.indexOf("\n", i + 1);
}
e.text = bf.toString();
}
return;
}
final StyledText styledText = (StyledText) e.widget;
final String text = styledText.getText(e.start, e.end - 1);
final Matcher matcher = PATTERN.matcher(text);
if (matcher.find()) {
// 被删除的部分中存在标记的的情况,进行特殊处理。
if (isSource()) {
e.doit = false;
setToolTipMessage(Messages.getString("innertag.SegmentViewer.msg1"));
return;
}
matcher.reset();
styledText.getDisplay().syncExec(new Runnable() {
public void run() {
deleteInnerTagInPairs(e, matcher);
}
});
}
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
if (text.length() == 1 && (text.equals("\n") || text.indexOf('') != -1)) {
char c = styledText.getText().charAt(e.start - 1);
if (c == Constants.LINE_SEPARATOR_CHARACTER || c == Constants.SPACE_CHARACTER || c == Constants.TAB_CHARACTER) {
styledText.replaceTextRange(e.start - 1, 2, "");
e.doit = false;
}
} else if (text.length() == 1 && (text.indexOf(Constants.LINE_SEPARATOR_CHARACTER) != -1 || text.indexOf(Constants.TAB_CHARACTER) != -1 || text.indexOf(Constants.TAB_CHARACTER) != -1)) {
char c = styledText.getText().charAt(e.start + 1);
if (c == '\n' || c == '') {
styledText.replaceTextRange(e.start, 2, "");
e.doit = false;
}
}
}
}
/**
* 成对删除内部标记
*/
private void deleteInnerTagInPairs(final VerifyEvent e, Matcher matcher) {
StyledText styledText = (StyledText) e.widget;
// 记录被删除的标记的索引。
ArrayList<Integer> tagIndexes = new ArrayList<Integer>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag innerTag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), placeHolder);
if (innerTag != null && innerTag.isVisible()) {
innerTag.setVisible(false);
// 保存成对标记中未完全删除的标记索引
TagType tagType = innerTag.getInnerTagBean().getType();
if (tagType == TagType.START || tagType == TagType.END) {
// 处理成对标记的成对删除
// 标记索引
Integer tagIndex = Integer.valueOf(innerTag.getInnerTagBean().getIndex());
if (tagIndexes.contains(tagIndex)) {
// 如果已经包含此索引,说明成对标记的2个部分都已经删除。
tagIndexes.remove(tagIndex);
} else {
// 如果未包含此索引,则说明只删除了一个部分(开始或结束)的标记。
tagIndexes.add(tagIndex);
}
}
}
}
if (!tagIndexes.isEmpty()) {
// 存在未删除的情况。
getUndoManager().beginCompoundChange();
// 上一步已经修改,取消修改操作。
e.doit = false;
// 替换改动内容
styledText.getContent().replaceTextRange(e.start, e.end - e.start, e.text);
for (int i = 0; i < errorTagStart; i++) {
// 删除成对标记中未被删除的部分。
InnerTag innerTag = innerTagCacheList.get(i);
if (innerTag != null && innerTag.isVisible()) {
if (tagIndexes.contains(innerTag.getInnerTagBean().getIndex())) {
innerTag.setVisible(false);
String placeHolder = placeHolderBuilder.getPlaceHolder(null, i);
int start = -1;
if ((start = styledText.getText().indexOf(placeHolder)) != -1) {
styledText.getContent().replaceTextRange(start, placeHolder.length(), "");
}
tagIndexes.remove(Integer.valueOf(innerTag.getInnerTagBean().getIndex()));
if (tagIndexes.isEmpty()) {
break;
}
}
}
}
getUndoManager().endCompoundChange();
/**
* 通知更新主菜单(actionBar)中“撤销重做”等菜单项的状态,参见
* net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorActionHandler
*/
styledText.notifyListeners(SWT.Selection, null);
}
}
});
/**
* 重绘时,将当前文本段中存在的内部标记对应的控件显示出来
*/
styledText.addPaintObjectListener(new PaintObjectListener() {
public void paintObject(PaintObjectEvent event) {
StyleRange styleRange = event.style;
if (styleRange != null) {
String text = ((StyledText) event.widget).getText();
int end = styleRange.start + styleRange.length;
if (text.length() < end) {
return;
}
String styledString = text.substring(styleRange.start, end);
Matcher matcher = PATTERN.matcher(styledString);
if (matcher.matches()) {
InnerTag tag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), styledString);
if (tag != null) {
if (!tag.isVisible()) {
tag.setVisible(true);
}
// int y = event.y + event.ascent - styleRange.metrics.ascent;
int lineHeight = getTextWidget().getLineHeight();
// innerTag.setLocation(event.x + SEGMENT_LINE_SPACING / 2, event.y + SEGMENT_LINE_SPACING /
// 2 /* 行距的一半 */);
int y = event.y + lineHeight / 2 - tag.getBounds().height / 2;
tag.setLocation(event.x + SEGMENT_LINE_SPACING, y);
}
}
}
}
});
/**
* 鼠标移动时,清除错误消息。
*/
styledText.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if (getTextWidget().getToolTipText() != null && getTextWidget().getToolTipText().length() > 0) {
setToolTipMessage("");
}
}
});
// 处理修改内容时,需要非打印字符添加样式。
styledText.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
if (!XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
return;
}
String s = event.text;
Matcher matcher = Constants.NONPRINTING_PATTERN.matcher(s);
TextStyle style = new TextStyle(null, GUIHelper.getColor(new RGB(100, 100, 100)), null);
List<StyleRange> ranges = new ArrayList<StyleRange>();
while (matcher.find()) {
int start = event.start + matcher.start();
StyleRange range = new StyleRange(style);
range.start = start;
range.length = 1;
ranges.add(range);
}
for (StyleRange range : ranges) {
getTextWidget().setStyleRange(range);
}
}
});
styledText.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (InnerTag tag : innerTagCacheList) {
if (tag.isSelected()) {
tag.setSelected(false);
tag.redraw();
}
}
String styledString = getTextWidget().getSelectionText();
Matcher matcher = PATTERN.matcher(styledString);
while (matcher.find()) {
String s = matcher.group();
InnerTag tag = InnerTagUtil.getInnerTag(SegmentViewer.this.getInnerTagCacheList(), s);
if (tag != null) {
tag.setSelected(true);
tag.redraw();
}
}
}
});
}
use of org.eclipse.swt.events.MouseMoveListener in project translationstudio8 by heartsome.
the class GridCopyEnable method initListener.
private void initListener() {
gridTable.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
if ((e.button != 1) || (IS_MAC && (e.stateMask & SWT.MOD4) != 0)) {
return;
}
clickCount = e.count;
doMouseLocationChange(e.x, e.y, false);
}
});
gridTable.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event e) {
clickCount = 0;
}
});
gridTable.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if (clickCount > 0) {
gridTable.update();
doMouseLocationChange(e.x, e.y, true);
}
}
});
gridTable.addListener(SWT.KeyDown, new Listener() {
public void handleEvent(Event event) {
int t = event.keyCode | event.stateMask;
if (t == ('C' | SWT.MOD1) || t == ('c' | SWT.MOD1)) {
// copy event
doAction(ST.COPY);
}
}
});
gridTable.getVerticalBar().addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
handleVerticalScroll(event);
}
});
gridTable.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (clipboard != null) {
clipboard.dispose();
}
if (defaultCaret != null) {
defaultCaret.dispose();
}
}
});
}
use of org.eclipse.swt.events.MouseMoveListener in project cubrid-manager by CUBRID.
the class ProductInfoDialog method addListeners.
/**
* Adds listeners to the given styled text
*
* @param styledText the StyledText object
*/
protected void addListeners(StyledText styledText) {
styledText.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
if (event.button != 1) {
return;
}
mouseDown = true;
}
public void mouseUp(MouseEvent event) {
mouseDown = false;
StyledText text = (StyledText) event.widget;
int offset = text.getCaretOffset();
if (dragEvent) {
// don't activate a link during a drag/mouse up operation
dragEvent = false;
if (item != null && item.isLinkAt(offset)) {
text.setCursor(handCursor);
}
} else if (item != null && item.isLinkAt(offset)) {
text.setCursor(busyCursor);
String url = item.getLinkAt(offset);
if (StringUtil.isEmpty(url)) {
LOGGER.warn("The url is a null or empty string : {}.", url);
} else {
openLink(url);
}
StyleRange selectionRange = getCurrentRange(text);
if (selectionRange == null) {
LOGGER.warn("The selectionRange is a null.");
} else {
text.setSelectionRange(selectionRange.start, selectionRange.length);
text.setCursor(null);
}
}
}
});
styledText.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
if (mouseDown) {
if (!dragEvent) {
StyledText text = (StyledText) event.widget;
text.setCursor(null);
}
dragEvent = true;
return;
}
StyledText text = (StyledText) event.widget;
int offset = -1;
try {
offset = text.getOffsetAtLocation(new Point(event.x, event.y));
} catch (IllegalArgumentException ex) {
offset = -1;
}
if (offset == -1) {
text.setCursor(null);
} else if (item != null && item.isLinkAt(offset)) {
text.setCursor(handCursor);
} else {
text.setCursor(null);
}
}
});
styledText.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
StyledText text = (StyledText) event.widget;
switch(event.detail) {
case SWT.TRAVERSE_ESCAPE:
event.doit = true;
break;
case SWT.TRAVERSE_TAB_NEXT:
// Previously traverse out in the backward direction?
Point nextSelection = text.getSelection();
int charCount = text.getCharCount();
if ((nextSelection.x == charCount) && (nextSelection.y == charCount)) {
text.setSelection(0);
}
StyleRange nextRange = findNextRange(text);
if (nextRange == null) {
// Next time in start at beginning, also used by
// TRAVERSE_TAB_PREVIOUS to indicate we traversed out
// in the forward direction
text.setSelection(0);
event.doit = true;
} else {
text.setSelectionRange(nextRange.start, nextRange.length);
event.doit = true;
event.detail = SWT.TRAVERSE_NONE;
}
break;
case SWT.TRAVERSE_TAB_PREVIOUS:
// Previously traverse out in the forward direction?
Point previousSelection = text.getSelection();
if ((previousSelection.x == 0) && (previousSelection.y == 0)) {
text.setSelection(text.getCharCount());
}
StyleRange previousRange = findPreviousRange(text);
if (previousRange == null) {
// Next time in start at the end, also used by
// TRAVERSE_TAB_NEXT to indicate we traversed out
// in the backward direction
text.setSelection(text.getCharCount());
event.doit = true;
} else {
text.setSelectionRange(previousRange.start, previousRange.length);
event.doit = true;
event.detail = SWT.TRAVERSE_NONE;
}
break;
default:
break;
}
}
});
// Listen for Tab and Space to allow keyboard navigation
styledText.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
StyledText text = (StyledText) event.widget;
if (event.character == ' ' || event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
if (item == null) {
LOGGER.warn("AboutItem is a null.");
return;
}
// Be sure we are in the selection
int offset = text.getSelection().x + 1;
if (item.isLinkAt(offset)) {
text.setCursor(busyCursor);
String url = item.getLinkAt(offset);
if (StringUtil.isEmpty(url)) {
LOGGER.warn("The url is a null or empty string : {}.", url);
} else {
openLink(url);
}
StyleRange selectionRange = getCurrentRange(text);
if (selectionRange == null) {
LOGGER.warn("The selectionRange is a null.");
} else {
text.setSelectionRange(selectionRange.start, selectionRange.length);
text.setCursor(null);
}
}
}
}
});
}
Aggregations