【问题标题】:Adding bidirectional functionality to a SelectionListener向 SelectionListener 添加双向功能
【发布时间】:2012-07-22 18:25:54
【问题描述】:

我的选择侦听器遇到了一些问题,目前我已经独立尝试了从 TOP 到 BOTTOM 和 BOTTOM 到 TOP(鼠标移动)的文本选择,但是这些试验不能一起工作,即 SelectionListener 是双向的...

private void setupSelectionListener() {

    this.contentValues.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {

            StyledText text = (StyledText)event.widget;

            int x = event.x;
            int y = event.y;

            //Mouse Drag Listener here??? - Detects Right

                //FOR TOP TO BOTTOM SELECTION
                text.setSelection(event.x); 

                int beginPosition = event.x; 
                int beginByte = beginPosition / 3;

                int endPosition = event.y; 
                int endByte = endPosition / 3;

                setSelection(beginByte, endByte);

            //Mouse Drag Listener here??? - Detects Left

                //FOR BOTTOM TO TOP SELECTION
                text.setSelection(event.y);

                int beginPosition = event.y;
                int beginByte = beginPosition / 3;

                int endPosition = event.x;
                int endByte = endPosition / 3;

                setSelection(beginByte, endByte);               

        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // Does nothing...
        }
    });     

所以要么我需要一个鼠标拖动监听器,就像我在 cmets 中所说的那样,要么需要一个比较 event.x 和 event.y 的条件语句

我尝试在选择侦听器内部添加拖动检测侦听器,但这会破坏事件坐标选择的格式。

任何帮助将不胜感激。

【问题讨论】:

    标签: java eclipse-rcp selection bidirectional textselection


    【解决方案1】:

    如果发生事件的源小部件是 Styled Text 对象,则此选择将自动发生,无需任何侦听器正确,这意味着如果您按住鼠标拖动,内容将自动选择。

    【讨论】:

      猜你喜欢
      • 2010-09-07
      • 2017-12-06
      • 1970-01-01
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      相关资源
      最近更新 更多