<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    The Goal
    Keep walking……
    posts - 23,  comments - 1,  trackbacks - 0

    ActionContributionItem--combines the function of a GUI widget and its attached listener class.
    Action--處理事件
    與SWT的listener/event模式很類似,但是其class更抽象,更易于使用,scope更窄。

    • actions and contributions

    Action--可以簡單的理解成一個(gè)命令,可以關(guān)聯(lián)到菜單,工具條,以及按鈕
    Contribution--在JFace里面,一個(gè)Action可以對應(yīng)多個(gè)GUI對象,這些對象就是所謂的Contribution Item. 有兩個(gè)主要的Contribution類:ContributionItem和ContributionManager,它們都是抽象類,靠其子類來實(shí)現(xiàn)事件的處理。繼承關(guān)系見下圖
    ContributionItem--引發(fā)事件的單獨(dú)GUI組件
    ContributionManager--產(chǎn)生包含ContributionItems的對象

    ActionContributionItem--最重要,在ApplicationWindow中創(chuàng)建和實(shí)施,來將一個(gè)action連接至此GUI,它雖沒有設(shè)定好的外觀,但是依賴于你使用的fill()方法,卻可以幫助一個(gè)按鈕、菜單欄和工具欄的成形

    另一個(gè)與Contribution協(xié)作的方法是通過ContributionManager,它的子類類似于ContributionItem的container。其中MenuManager將ContributionItems組合在窗口最高層菜單, ToolBarManager則將這些對象放在僅在菜單之下的toolbar中。

    • 創(chuàng)建Action類

    Action是抽象類。

    package com.swtjface.Ch4;
    import org.eclipse.jface.action.*;
    import org.eclipse.jface.resource.*;
    public class Ch4_StatusAction extends Action
    {
    StatusLineManager statman;
    short triggercount = 0;
    public Ch4_StatusAction(StatusLineManager sm)
    {
    super("&Trigger@Ctrl+T",
    AS_PUSH_BUTTON);//在T字母之前的&符號意味著這個(gè)字母將作為該動作的快捷鍵。而在TEXT領(lǐng)域內(nèi)的“Ctrl+T”確保了當(dāng)用戶在同時(shí)按下Ctrl鍵和T鍵時(shí)該動作就會被激發(fā)。
    statman = sm;
    setToolTipText("Trigger the Action");
    setImageDescriptor(ImageDescriptor.createFromFile
    (this.getClass(),"eclipse.gif"));
    }
    public void run() //每次當(dāng)Ch4_StatusAction被生成,run()方法就被調(diào)用
    {
    triggercount++;
    statman.setMessage("The status action has fired. Count: " +
    triggercount);
    }

    • Implementing contributions in an ApplicationWindow

    package com.swtjface.Ch4;

    import org.eclipse.swt.*;

    import org.eclipse.swt.widgets.*;

    import org.eclipse.jface.window.*;

    import org.eclipse.jface.action.*;

    public class Ch4_Contributions extends ApplicationWindow {

    StatusLineManager slm = new StatusLineManager();

    Ch4_StatusAction status_action = new Ch4_StatusAction(slm); //StatusLineManager的對象作參數(shù),創(chuàng)建了一個(gè)Ch4_StatusAction的實(shí)例

    ActionContributionItem aci = new ActionContributionItem(status_action); //用Ch4_StatusAction的對象作參數(shù),創(chuàng)建了ActionContributionItem對象

    public Ch4_Contributions() {

    super(null); // 創(chuàng)建了 ApplicationWindow對象

    addStatusLine();

    addMenuBar();

    addToolBar(SWT.FLAT | SWT.WRAP); //在窗口上添加了status line, menu, toolbar

    }

    protected Control createContents(Composite parent) {

    getShell().setText("Action/Contribution Example");

    parent.setSize(290,150); //設(shè)置了窗口的title和size

    aci.fill(parent); // 將ActionContributionItem放在GUI中。因?yàn)檫@里的參數(shù)是Composite對象,所以根據(jù)Action的STYLE屬性來確定。此處是Button,因?yàn)?font color="#0000ff">Ch4_StatusAction 的STYLE屬性是AS_PUSH_BUTTON;

    return parent;

    }

    public static void main(String[] args) {

    Ch4_Contributions swin = new Ch4_Contributions();

    swin.setBlockOnOpen(true);

    swin.open();

    Display.getCurrent().dispose();

    }

    protected MenuManager createMenuManager() {

    MenuManager main_menu = new MenuManager(null);

    MenuManager action_menu = new MenuManager("Menu");

    main_menu.add(action_menu);

    action_menu.add(status_action); //關(guān)聯(lián)status_action.created and added to the menu in the form of a menu item

    return main_menu;

    }

    protected ToolBarManager createToolBarManager(int style) {

    ToolBarManager tool_bar_manager = new ToolBarManager(style);

    tool_bar_manager.add(status_action); //關(guān)聯(lián)status_action。created and added to the toolbar as a toolbar item.

    return tool_bar_manager;

    }

    protected StatusLineManager createStatusLineManager() {

    return slm;

    }

    }

    • Interfacing with contributions

    兩個(gè)途徑來將ActionContributionItem添加到GUI:
    1. 通過ContributionManager子類的add()方法。
    (1)可接受Action對象的參數(shù),從而間接的將ContributionItem和ContributionManager關(guān)聯(lián)。可多次執(zhí)行
    (2)可直接接受ActionContributionItem對象的參數(shù)。只可執(zhí)行一次
    2.通過ActionContributionItem類的fill()方法。根據(jù)其參數(shù)的不同,所先是的組件也不同,具體見下表:

    • Exploring the Action class

    Important methods of the Action class


    Property methods for the Action class

    DESCRIPTION--written to a status line to provide additional help.

    Style methods for the Action class

    如果ENABLED是FALSE,則變灰。CHECKED主要用于radio和checkbox

    Accelerator key / keyboard methods for the Action class

    Accelerator keys--鼠標(biāo)點(diǎn)擊的鍵盤塊捷方式


    Listener methods for the Action class

    雖然JFace使用action代替了SWT的listener/event機(jī)制,但是Actiono類仍然可以和listener協(xié)作來處理特定需求的事件。
    IPropertyChangeListener接口關(guān)注客戶自定義的PropertyChangeEvents,當(dāng)所給的對象按照你所給的方式變成另一個(gè)對象時(shí),此事件被觸發(fā)。

    Miscellaneous methods of the Action class

    posted on 2006-03-24 17:02 JOO 閱讀(797) 評論(1)  編輯  收藏 所屬分類: SWT & JFace IN ACTION

    FeedBack:
    # re: 4.2 Event processing in JFace
    2007-01-25 09:45 | cai niao
    great  回復(fù)  更多評論
      
    Hit the target!

    <2007年1月>
    31123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    常用鏈接

    留言簿(2)

    隨筆分類(23)

    隨筆檔案(22)

    文章檔案(1)

    相冊

    Neighbor

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲AV无码成人精品区狼人影院| 亚洲av无码乱码国产精品| 精品免费国产一区二区三区| 巨胸喷奶水视频www网免费| 亚洲精品A在线观看| 亚洲VA中文字幕无码一二三区 | 啦啦啦高清视频在线观看免费| 久久久久久99av无码免费网站| 亚洲国产福利精品一区二区| 美女又黄又免费的视频| 黄色网址在线免费| 在线观看无码AV网站永久免费 | 99久久99久久免费精品小说| 成人毛片免费观看视频在线| 亚洲日韩av无码| 中国china体内裑精亚洲日本| 一级做a爰黑人又硬又粗免费看51社区国产精品视 | 牛牛在线精品免费视频观看| 国产成人精品久久亚洲| 亚洲资源最新版在线观看| 免费无码又爽又刺激高潮软件| 国产精品麻豆免费版| 亚洲国产精品免费视频| 一级做a免费视频观看网站| A在线观看免费网站大全| 亚洲av无码有乱码在线观看| 国产成人精品亚洲精品| 久久久免费的精品| 在线A亚洲老鸭窝天堂| 国产成人综合久久精品亚洲| 扒开双腿猛进入爽爽免费视频| 国产精品成人亚洲| 国产aⅴ无码专区亚洲av| 国产激情久久久久影院老熟女免费| 国内免费高清在线观看| 天堂亚洲免费视频| 久久亚洲精品成人无码网站| 东方aⅴ免费观看久久av| 亚洲人成在线播放| 国产精品亚洲精品日韩已方| 1000部无遮挡拍拍拍免费视频观看 |