是JFace的類(lèi),繼承自ContributionManager,凡是繼承了IAction或IContribution接口的對(duì)象都可被加至ToolBarManager.你只要花時(shí)間為T(mén)oolBarManager添加Action,Toolbar和ToolItem實(shí)例會(huì)自動(dòng)產(chǎn)生。
你可通過(guò)調(diào)用ApplicationWindow的createToolBarManager()來(lái)為你的應(yīng)用程序添加一個(gè)toolbar。與MenuManager不同的是,createToolBarManager()需要一個(gè)style參數(shù),這個(gè)參數(shù)用來(lái)設(shè)定ToolBar所用的按鈕的風(fēng)格:flat或normal。
除了MenuManager所用的ContributionItems之外,還有一個(gè)新的ContributionItem,只能被ToolBarManager使用——ControlContribution。這個(gè)類(lèi)可將任何能被用于toolbar的Control打包進(jìn)去。
要使用ControlContribution類(lèi),必須要實(shí)現(xiàn)抽象方法createControl().
toolBarManager.add(new ControlContribution("Custom") {
protected Control createControl(Composite parent) {
SashForm sf = new SashForm(parent, SWT.NONE);
Button b1 = new Button(sf, SWT.PUSH);
b1.setText("Hello");
Button b2 = new Button(sf, SWT.PUSH);
b2.setText("World");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Selected:" + e);
}
});
return sf;
}
});
如果你希望有任何的事件發(fā)生,必須在你的controls上實(shí)現(xiàn)SelectionListeners
-
Creating toolbars by hand
如果你不想ToolBarManager來(lái)創(chuàng)建toolbar的話(huà),可以手動(dòng)創(chuàng)建,需要用到ToolBar和ToolItem類(lèi).
Toolbar
是一個(gè)composite control,包含多個(gè)ToolItems.Toolbar由多個(gè)小圖標(biāo)按鈕組成,一般是16-by-16bitmap圖片。每個(gè)按鈕都對(duì)應(yīng)一個(gè)ToolItem。Toolbar可以是水平的也可以是垂直的,默認(rèn)為水平
ToolItem
每一個(gè)ToolItem都有一個(gè)圖片,如果沒(méi)有,默認(rèn)為紅色方塊。When the user selects a ToolItem from the menu, it broadcasts the event to any registered SelectionListeners.Your application should register a listener with each ToolItem and use that listener to perform whatever logic corresponds to the menu item.
posted on 2006-04-07 16:32
JOO 閱讀(669)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
SWT & JFace IN ACTION