package free;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.ListSelectionModel;
import javax.swing.event.MouseInputAdapter;
import javax.swing.event.MouseInputListener;
import twaver.Element;
import twaver.Group;
import twaver.list.TList;

public class FreeList extends TList {

    public FreeList() {
        init();
    }

    private void init() {
        this.setFont(FreeUtil.FONT_12_BOLD);
        this.setForeground(FreeUtil.DEFAULT_TEXT_COLOR);
        this.setBackground(FreeUtil.LIST_BACKGROUND);
        this.setCellRenderer(new FreeListRenderer(this));
        this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        //move mouse, select over item.
        MouseInputListener mouseListener = new MouseInputAdapter() {

            @Override
            public void mouseMoved(MouseEvent e) {
                Element element = getElementByPoint(e.getPoint());
                getDataBox().getSelectionModel().clearSelection();
                if (element != null) {
                    //ignore group.
                    if (!(element instanceof Group)) {
                        element.setSelected(true);
                    }
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                getDataBox().getSelectionModel().clearSelection();
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                Element element = getDataBox().getSelectionModel().lastElement();
                if (element != null) {
                    if (!(element instanceof Group)) {
                        ActionListener action = (ActionListener) element.getUserObject();
                        String command = (String) element.getBusinessObject();

                        if (action != null) {
                            ActionEvent event = new ActionEvent(element, 0, command);
                            action.actionPerformed(event);
                        }
                    }
                }
            }
        };
        this.addMouseMotionListener(mouseListener);
        this.addMouseListener(mouseListener);
    }
}
最近下载更多
励志12345  LV3 2024年5月8日
329512801  LV28 2022年1月18日
cd201481  LV1 2020年2月5日
yongzheng132  LV17 2019年6月24日
通天晓  LV10 2019年4月15日
mixiansheng  LV6 2018年12月27日
mengfanyun  LV9 2018年11月16日
QueenLuxuMissRy  LV1 2018年7月31日
applepaihs1  LV1 2018年7月20日
蓝色鸢尾  LV2 2018年7月20日
最近浏览更多
interface  LV22 2024年7月13日
一磕小橙子  LV3 2024年6月20日
励志12345  LV3 2024年5月8日
Sutnuf 2023年11月27日
暂无贡献等级
1112WHQ  LV7 2023年11月3日
yangxb2  LV10 2023年10月20日
ezra77934  LV2 2023年9月16日
另类清晨  LV8 2023年5月15日
漫步的海星  LV4 2023年3月24日
小小虎牙妹  LV4 2023年3月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友