首页 技术 正文
技术 2022年11月15日
0 收藏 643 点赞 4,760 浏览 5136 个字

选择事件

选择事件是在选择块发生变化后发出。
table.addKDTSelectListener(new KDTSelectListener()
{
    public void tableSelectChanged(KDTSelectEvent e){
    // 获取上一个选择块
    KDTSelectBlock sbPrev = e.getPrevSelectBlock();
    // 获取当前选择块
    KDTSelectBlock sbCurr = e.getSelectBlock();
    // …do something
    }
});

鼠标单击双击事件

单击事件是在鼠标单击某个单元格后发出。
双击事件是在鼠标双击某个单元格后发出。
table.addKDTMouseListener(new KDTMouseListener()
{
    public void tableClicked(KDTMouseEvent e)
{
    // 单击
        if (e.getClickCount() == 1)
{
            // …do something
        }
        // 双击
        else if (e.getClickCount() == 2)
        {
            // …do something
}
    }
});

激活单元即指当前处于准备进入编辑状态的单元。
激活单元变化事件是在激活单元发生变化后发出。
添加激活单元变化事件侦听者
table.addKDTActiveCellListener(new KDTActiveCellListener()
{
    public void activeCellChanged(KDTActiveCellEvent e)
{
    // 获取上一个激活单元的行列索引
        int prevRow = e.getPrevRowIndex();
        int prevCol = e.getPrevColumnIndex();
        // 获取当前激活单元的行列索引
        int currRow = e.getRowIndex();
        int currCol = e.getColumnIndex();
        // …do something
    }
});

编辑事件

编辑事件KDTEditListener包括以下几个方法:
editStarting 编辑器启动中,在编辑器启动之前发出,通过设置返回值可以取消启动编辑器。
editStarted 编辑启动后,在编辑启动之后发出。
editValueChanged 编辑器值变化,在编辑器的值发生变化后发出。
editStopping 编辑器结束中,在编辑器结束之前发出,通过设置返回值可以取消结束编辑器。
editStopped 编辑器结束后,在编辑器结束之后发出。
KDTEditListener提供了适配器KDTEditAdapter
// 示例
table.addKDTEditListener(new KDTEditAdapter()
{
    // 编辑器启动前
    public void editStarting(KDTEditEvent e)
  {
        System.out.println(“editStarting”);
        // 如果当前行是第三行,将取消编辑
        if (e.getRowIndex() == 3)
            e.setCancel(true);
    }
    
    // 编辑启动后
    public void editStarted(KDTEditEvent e)
  {
        System.out.println(“editStarted”);
    // 如果当前单元处于第4行第0列,并且单元值为字符串,则在字符串前加上$符
    if ((e.getRowIndex() == 4) && (e.getColIndex() == 0))
    {
            KDTable tbl = (KDTable)e.getSource();
            Object value =tbl.getEditManager().getEditor().getValue();
            if (value instanceof String)
tbl.getEditManager().getEditor().setValue(“$” + value.toString());
        }
    }
    
    // 编辑器值变化(注意:此时编辑器还未结束,KDTable实际上是转发编辑器的
   // change事件)
    public void editValueChanged(KDTEditEvent e){
        System.out.println(“editValueChanged”);
    }
    
    // 编辑器结束前
    public void editStopping(KDTEditEvent e)
{
        System.out.println(“editStopping”);
        //如果当前单元处于第4行第0列,则在退出前将$符去掉
        if ((e.getRowIndex() == 4) && (e.getColIndex() == 0))
{
            KDTable tbl = (KDTable)e.getSource();
            String value = (String)tbl.getEditManager().getEditor().getValue();
            // 如果单元格的值长度小于5,则不允许退出编辑状态
            if (value.length() < 5)
                e.setCancel(true);
            // 否则,取得$符并退出编辑
else
    tbl.getEditManager().getEditor().setValue(value.substring(1, value.length()));
        }
    }
    
    // 编辑结束后
    public void editStopped(KDTEditEvent e) {
        System.out.println(“editStopped”);
    }
});

BeforeActionListener事件

这个事件在table增删行列以及copy、paste、cut时触发,通过设置事件参数的返回值可以取消相应的动作。
// 给table设置action
table.setBeforeAction(new TableBeforeAction());
// action的实现
    class TableBeforeAction implements BeforeActionListener
    {       
        /**
         *@see com.kingdee.bos.ctrl.kdf.table.event.BeforeActionListener#beforeAction(com.kingdee.bos.ctrl.kdf.table.event.BeforeActionEvent)
         */
        public void beforeAction(BeforeActionEvent e)
        {
            // 添加行
            if (e.getType() == BeforeActionEvent.ACTION_ADD_ROW)
            {
                // 获取插入行的位置
                int rowIndex = ((Integer)e.getParameter()).intValue();
                
                if (rowIndex > 5)
                {
                    WindowUtil.msgboxInfo(“不能添加行”, “title”, table);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // 添加列
            else if (e.getType() == BeforeActionEvent.ACTION_ADD_COLUMN)
            {
                int colIndex = ((Integer)e.getParameter()).intValue();
                
                if (colIndex > 3)
                {
                    WindowUtil.msgboxInfo(“不能添加列”, “title”, table);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // paste
            else if (e.getType() == BeforeActionEvent.ACTION_PASTE)
            {
                // 获取paste的项
                int mark = ((Integer)e.getParameter()).intValue();
                
                // 如果paste项中包含userObject,则
                if (KDTEditHelper.isUserObject(mark))
                {
                    WindowUtil.msgboxInfo(“paste”, “title”, table);
                    
                    // paste除userObject外的内容
                    table.getEditHelper().paste(KDTEditHelper.STYLE | KDTEditHelper.VALUE | KDTEditHelper.FORMULA);
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // cut
            else if (e.getType() == BeforeActionEvent.ACTION_CUT)
            {
                // 获取cut的项
                int mark = ((Integer)e.getParameter()).intValue();
                
                // 如果cut项中包含userObject,则
                if (KDTEditHelper.isUserObject(mark))
                {
                    WindowUtil.msgboxInfo(“cut”, “title”, table);
                    
                    // cut除userObject外的内容
                    table.getEditHelper().paste(KDTEditHelper.STYLE | KDTEditHelper.VALUE | KDTEditHelper.FORMULA);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
        }
       }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844