Open Java Project

          Keep it simple, Stupid, Less is more

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            20 Posts :: 0 Stories :: 12 Comments :: 0 Trackbacks

          4、復(fù)雜控件

          (1)       ExpandableComposite

          l         Web頁面中一個(gè)通用的主題是具有收縮一部分頁面內(nèi)容的能力

          l         Eclipse Form也提供了這樣一個(gè)控件:ExpandableComposite

          l         下面的代碼片斷是使用ExpandableComposite的一個(gè)例子:

                        ExpandableComposite ec = toolkit.createExpandableComposite(body,

                          ExpandableComposite.TREE_NODE

                                 | ExpandableComposite.CLIENT_INDENT);

                        ec.setText("Expandable Composite title");

                        String ctext = "We will now create a somewhat long text so that "

                          + "we can use it as content for the expandable composite. "

                          + "Expandable composite is used to hide or show the text using the "

                          + "toggle control";

                        Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);

                        ec.setClient(client);

                        td = new TableWrapData();

                        td.colspan = 2;

                        ec.setLayoutData(td);

                        ec.addExpansionListener(new ExpansionAdapter() {

                          public void expansionStateChanged(ExpansionEvent e) {

                                 form.reflow(true);

                          }

                        });

          l         這個(gè)控件有很多風(fēng)格,TREE_NODE使得該控件具有樹型節(jié)點(diǎn)的展開、收縮功能;而TWISTIE使得控件具有三角箭頭風(fēng)格

          l         EXPANDED使得初始展開顯示

          l         CLIENT_INDENT使得Client內(nèi)容縮進(jìn)對(duì)齊

          l         ExpandableComposite呈現(xiàn)為激活控件和標(biāo)題,而可以展開、收縮的內(nèi)容稱為Client

          l         Client必須是可展開的composite(上例是Label控件)

          l         最后需要添加Expansion監(jiān)聽器在狀態(tài)變化時(shí),reflow Form(即根據(jù)控件的新的大小重新定位和更新滾動(dòng)條)

          l         下面是上例的運(yùn)行結(jié)果:

          o_ExpandableComposite.jpg


          2)Section

          l         Eclipse Form中最常用的定制控件就是Section(在PDE中到處可見)

          l         Section擴(kuò)展ExpandableComposite,但具有下面的新特性:

          n         在標(biāo)題下面有一個(gè)分隔控件

          n         在分隔控件下面可以有一個(gè)描述文本

          l         下面的代碼片斷是使用Section的一個(gè)例子,代碼和ExpandableComposite沒有太大差別,這里是用了TWISTIE風(fēng)格:

                        Section section = toolkit.createSection(body, Section.DESCRIPTION

                                 | Section.TWISTIE | Section.EXPANDED);

                        td = new TableWrapData(TableWrapData.FILL);

                        td.colspan = 2;

                        section.setLayoutData(td);

                        section.addExpansionListener(new ExpansionAdapter() {

                          public void expansionStateChanged(ExpansionEvent e) {

                                 form.reflow(true);

                          }

                        });

                        section.setText("Section title");

                        toolkit.createCompositeSeparator(section);

                        section

                                 .setDescription("This is the description that goes below the title");

                        Composite sectionClient = toolkit.createComposite(section);

                        sectionClient.setLayout(new GridLayout());

                        button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);

                        button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);

                        section.setClient(sectionClient);

          l         下面是上例的運(yùn)行結(jié)果:

          r_Section.jpg

          posted on 2005-04-10 23:19 nelson_tu 閱讀(1797) 評(píng)論(0)  編輯  收藏 所屬分類: Eclipse開發(fā)
          主站蜘蛛池模板: 旅游| 定远县| 蕲春县| 修水县| 刚察县| 禹城市| 通江县| 称多县| 满洲里市| 玉山县| 泰和县| 梧州市| 长垣县| 嘉祥县| 长汀县| 宁武县| 麻城市| 呼伦贝尔市| 屯门区| 监利县| 东乌| 瑞金市| 昭通市| 锡林浩特市| 涿州市| 上杭县| 大英县| 峨边| 新绛县| 登封市| 岳阳市| 万源市| 镇坪县| 灯塔市| 临安市| 乌审旗| 岳西县| 吴桥县| 彩票| 昌都县| 三门峡市|