分享

模仿qq消息提示框,可以完美定位到rcp系统的右下角

 LibraryPKU 2015-03-12

代码片段(5) [全屏查看所有代码]

1. [代码][Java]代码    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
略全局对象,一一创建即可。。。
    /**
     * Create the dialog.
     *
     * @param parent
     * @param style
     */
    public demo2(Shell parent, int style) {
        super(parent, style);
        this.parent = parent;
        setText("SWT Dialog");
    }
 
    /**
     * Open the dialog.
     *
     * @return the result
     */
    public Object open() {
        createContents();
        LayoutUtil.bottomrightShell(parent.getDisplay(), shell);
        shell.setLayout(new FormLayout());
 
        Composite composite = new Composite(shell, SWT.BORDER);
        composite.setBackground(SWTResourceManager.getColor(127, 255, 212));
        FormData fd_composite = new FormData();
        fd_composite.right = new FormAttachment(0, 340);
        fd_composite.top = new FormAttachment(0);
        fd_composite.left = new FormAttachment(0);
        fd_composite.bottom = new FormAttachment(0, 27);
        composite.setLayoutData(fd_composite);
 
        text = new Text(composite, SWT.BORDER | SWT.CENTER);
        text.setEnabled(false);
        text.setText("通知栏");
        text.setBounds(5, 1, 73, 23);
 
        Button button_1 = new Button(composite, SWT.TOGGLE | SWT.CENTER);
        button_1.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                shell.close();
            }
        });
        button_1.setText("×");
        button_1.setBounds(309, 0, 27, 27);
 
        final Button button_2 = new Button(composite, SWT.ARROW | SWT.DOWN);
        button_2.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                makeList();
            }
        });
        button_2.setBounds(276, 0, 27, 27);
 
        list_1 = new List(shell, SWT.BORDER);
        list_1.setLocation(184, 27);
        list_1.setItems(new String[] { "不再通知", "实时提醒", "最小化" });
        FormData fd_list_1 = new FormData();
        fd_list_1.bottom = new FormAttachment(composite, 55, SWT.BOTTOM);
        fd_list_1.top = new FormAttachment(composite);
        fd_list_1.right = new FormAttachment(100, -38);
        fd_list_1.left = new FormAttachment(100, -157);
        list_1.setLayoutData(fd_list_1);
        list_1.setVisible(false);
        parent.getDisplay().addFilter(SWT.MouseMove,new  Listener() {
             
            @Override
            public void handleEvent(Event e) {
                // TODO Auto-generated method stub
                if(list_1!=null&&!list_1.isDisposed()){
                    int x = e.x;
                    int y = e.y;
                    Rectangle r = list_1.getBounds();
                    int xbegin = r.x;
                    int xend = r.x + r.width;
                    int ybegin = r.y;
                    int yend = r.y + r.height;
                    if ((x+xbegin) >= xbegin && (x+xbegin)<= xend && (y+ybegin) >= ybegin &&(y+ybegin) <= yend) {
                         
                    } else {
                        if (list_1.isVisible()) {
                            list_1.setVisible(false);
                        }
                    }
                }
            }
        });
        ScrolledComposite scrolledComposite = new ScrolledComposite(shell,
                SWT.BORDER | SWT.V_SCROLL);
        FormData fd_scrolledComposite = new FormData();
        fd_scrolledComposite.bottom = new FormAttachment(100, -30);
        fd_scrolledComposite.right = new FormAttachment(100);
        fd_scrolledComposite.top = new FormAttachment(composite);
        fd_scrolledComposite.left = new FormAttachment(0);
        scrolledComposite.setLayoutData(fd_scrolledComposite);
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
 
        table = new Table(scrolledComposite, SWT.BORDER | SWT.FULL_SELECTION
                | SWT.H_SCROLL);
        table.setLinesVisible(true);
        tableColumn = new TableColumn(table, SWT.NONE);
        tableColumn.setWidth(310);
        showDate();
 
        scrolledComposite.setContent(table);
        scrolledComposite.setMinSize(table
                .computeSize(SWT.DEFAULT, SWT.DEFAULT));
 
        lblNewLabel = new CLabel(shell, SWT.NONE);
        lblNewLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
        lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        FormData fd_lblNewLabel = new FormData();
        fd_lblNewLabel.bottom = new FormAttachment(100, -1);
        fd_lblNewLabel.left = new FormAttachment(composite, 0, SWT.LEFT);
        lblNewLabel.setLayoutData(fd_lblNewLabel);
        lblNewLabel.setText("查看全部");
 
        label = new CLabel(shell, SWT.NONE);
        label.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        label.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
        label.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        label.setText("忽略全部");
        FormData fd_label = new FormData();
        fd_label.top = new FormAttachment(lblNewLabel, -23);
        fd_label.left = new FormAttachment(100, -54);
        fd_label.bottom = new FormAttachment(lblNewLabel, 0, SWT.BOTTOM);
        fd_label.right = new FormAttachment(100);
        label.setLayoutData(fd_label);
        shell.open();
        shell.layout();
        Display display = getParent().getDisplay();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        return result;
    }
 
    private void showDate() {
        // TODO Auto-generated method stub
 
        tableItem = new TableItem(table, SWT.NONE);
        tableItem.setText("待处理的财务申请");
 
        tableItem_1 = new TableItem(table, SWT.NONE);
        tableItem_1.setText("待处理的未读邮件");
        for (int i = 0; i < 20; i++) {
            tableItem_1 = new TableItem(table, SWT.NONE);
            tableItem_1.setText("待处理的未读邮件");
        }
    }
 
    protected void makeList() {
        // TODO Auto-generated method stub
        if (list_1 != null && !list_1.isVisible()) {
            list_1.setVisible(true);
        } else if (list_1 != null && list_1.isVisible()) {
            list_1.setVisible(false);
        }
 
    }
 
    /**
     * Create contents of the dialog.
     */
    private void createContents() {
        shell = new Shell(getParent(), SWT.NO_TRIM | SWT.BORDER);
        shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        shell.setSize(340, 243);
        shell.setText(getText());
    }
}

2. [图片] QQ截图20141121171903.png    

3. [图片] QQ截图20141121171931.png    

4. [图片] QQ截图20141121171941.png    

5. [代码][Java]代码    

1
2
3
4
5
6
7
8
9
10
11
12
缓慢打开和关闭窗口
 
    private void createContents() {
        shell = new Shell(getParent(), SWT.NO_TRIM | SWT.BORDER);
        shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        shell.setSize(340, 243);
        shell.setText(getText());
        AnimationRunner runner = new AnimationRunner();
        runner.runEffect(new AlphaEffect(shell, 0, 255, 4000, new ExpoOut(),
                null, null));
        AlphaEffect.fadeOnClose(shell, 4000, new ExpoOut(), runner);
    }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多