gembin

OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

HBase, Hadoop, ZooKeeper, Cassandra

Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

About Me

 

SWT 给工具栏关联弹出菜单的工具类

SWT Snippets 里提取出来的, 虽然 JFace 里有更好的 MenuManager 之类的, 但是这个对 SWT 就可以用了.

 

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolItem;


public class SWTUtil {
/**
* Assign a popup menu to a widget.
* Whenever the widget is selected, the popup menu will displayed.
* @param parent
* @param popupMenu
*/
public static void assignPopupMenuToWidget(final ToolItem parent, final Menu popupMenu) {
parent.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent evt) {
// if (evt.detail == SWT.ARROW) {
Rectangle b = parent.getBounds();
Point pt = new Point(b.x, b.y + b.height);
pt = parent.getParent().toDisplay(pt);
popupMenu.setLocation(pt.x, pt.y);
popupMenu.setVisible(true);
// }
}
});
}
}

posted on 2007-10-10 13:47 gembin 阅读(471) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(6)

随笔分类(440)

随笔档案(378)

文章档案(6)

新闻档案(1)

相册

收藏夹(9)

Adobe

Android

AS3

Blog-Links

Build

Design Pattern

Eclipse

Favorite Links

Flickr

Game Dev

HBase

Identity Management

IT resources

JEE

Language

OpenID

OSGi

SOA

Version Control

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

free counters