是JFace的類,繼承自ContributionManager,凡是繼承了IAction或IContribution接口的對象都可被加至ToolBarManager.你只要花時間為ToolBarManager添加Action,Toolbar和ToolItem實例會自動產生。
你可通過調用ApplicationWindow的createToolBarManager()來為你的應用程序添加一個toolbar。與MenuManager不同的是,createToolBarManager()需要一個style參數,這個參數用來設定ToolBar所用的按鈕的風格:flat或normal。
除了MenuManager所用的ContributionItems之外,還有一個新的ContributionItem,只能被ToolBarManager使用——ControlContribution。這個類可將任何能被用于toolbar的Control打包進去。
要使用ControlContribution類,必須要實現抽象方法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;
}
});
如果你希望有任何的事件發生,必須在你的controls上實現SelectionListeners
-
Creating toolbars by hand
如果你不想ToolBarManager來創建toolbar的話,可以手動創建,需要用到ToolBar和ToolItem類.
Toolbar
是一個composite control,包含多個ToolItems.Toolbar由多個小圖標按鈕組成,一般是16-by-16bitmap圖片。每個按鈕都對應一個ToolItem。Toolbar可以是水平的也可以是垂直的,默認為水平
ToolItem
每一個ToolItem都有一個圖片,如果沒有,默認為紅色方塊。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)
評論(0) 編輯 收藏 所屬分類:
SWT & JFace IN ACTION