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

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

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

    Open Java Project

    Keep it simple, Stupid, Less is more

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

    5、FromText控件

    1)概述

    l         雖然使用Label、超鏈接(或圖像鏈接)以及TableWrapLayout布局就能創(chuàng)建豐富的Form內(nèi)容,但是要接近Web外觀還是很有限的

    l         Eclipse From提供了FromText控件來創(chuàng)建Rich文本,作為上述的補(bǔ)充,有三種形式:

    n         按純文本呈現(xiàn)

    n         將文本中URL轉(zhuǎn)換為超鏈接呈現(xiàn)

    n         XML標(biāo)記解析呈現(xiàn)

    2)純文本

    l         下面是按純文本呈現(xiàn)的例子(等同于Label

                  FormText rtext = toolkit.createFormText(body, true);
                  td = new TableWrapData(TableWrapData.FILL);
                  td.colspan = 2;
                  rtext.setLayoutData(td);
                  String data = "Here is some plain text for the text to render.";
                  rtext.setText(data, false, false);

    l         FormToolkitcreateFormText()方法創(chuàng)建FromText控件

    l         FromTextsetText()方法指定要呈現(xiàn)的文本,后面兩個參數(shù)指定是否要按XML標(biāo)記進(jìn)行解析和是否要將文本中的URL轉(zhuǎn)換為超鏈接

    3URL轉(zhuǎn)換為超鏈接

    l         下面是將URL轉(zhuǎn)換為超鏈接的例子,和上面例子的唯一區(qū)別是FromTextsetText()方法的第三個參數(shù)設(shè)置為True

                  FormText rtext = toolkit.createFormText(body, true);
                  td = new TableWrapData(TableWrapData.FILL);
                  td.colspan = 2;
                  rtext.setLayoutData(td);
                  Display display = FormSamplesPlugin.getDefault().getWorkbench().getDisplay();
                  FormColors formColors = new FormColors(display);
                  Color activeLinkColor = formColors.createColor("activeLink", 175,225,200);
                  HyperlinkSettings linkSettings = new HyperlinkSettings(display);
                  linkSettings.setActiveForeground(activeLinkColor);
                  linkSettings.setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);
                  rtext.setHyperlinkSettings(linkSettings);
                  String data = "Here is some plain text for the text to render; this text is at http://www.eclipse.org/ web site.";
                  rtext.setText(data, false, true);
                  rtext.addHyperlinkListener(new HyperlinkAdapter() {
                    public void linkActivated(HyperlinkEvent e) {
                           System.out.println("Link active: "+e.getHref());
                    }
                  });

    l         既然能夠?qū)?/SPAN>URL轉(zhuǎn)換成超鏈接,FromText同樣提供addHyperlinkListener()方法來監(jiān)聽超鏈接事件

    l         FromText還提供setHyperlinkSettings()方法來設(shè)置超鏈接的屬性(注意,要在setText()方法之前設(shè)置才有效)

    l         超鏈接的屬性由HyperlinkSettings對象管理,包括顏色和下劃線模式的設(shè)置

    l         例中使用了Eclipse From提供的FormColors對象(顏色管理器)來管理顏色,createColor()方法創(chuàng)建一種新的顏色,并提供了key值,以便以后可以使用getColor(key)訪問

    l         這里是使用FormColors的一個簡單例子,通常一個插件應(yīng)該只有一個顏色管理器(FormColors),可以使用Singlton模式來訪問FormColors對象

    4解析XML標(biāo)記

    l         解析XML標(biāo)記是FormText最強(qiáng)大的用法,但是FormText不完全支持所有的標(biāo)記,下面是FormText支持的標(biāo)記,而且用法有些不同:

    n         根標(biāo)記必須是<form>

    n         <form>可以包含<p><li>標(biāo)記

    n         <p><li>可以包含普通的文本、<br>、<b>、<span>、圖像(<img>)和超鏈接(<a>

    n         標(biāo)記不允許嵌套

    n         <p>vspace屬性,表示是否要加垂直空白(缺省是true

    n         <li>有下列屬性:

    u       vspace:同<p>

    u       stylebullet缺省)、textimage值之一

    u       value:當(dāng)style=bullet時,無效;當(dāng)style=text時,指定作為bullet的文本;當(dāng)style=image時,指定作為bullet的圖像(key值)

    u       indentbullet內(nèi)容縮進(jìn)的大?。ㄏ袼貫閱挝唬?/SPAN>

    u       bindentbullet自身縮進(jìn)的大小(像素為單位)

    n         <img>顯示圖像,其屬性href指定的是一個key值,該值和FormTextsetImage()方法中key參數(shù)指定的值是對應(yīng)的

    n         <a>顯示超鏈接,其屬性href指定URL并通過FormText添加監(jiān)聽器來監(jiān)聽超鏈接的點(diǎn)擊事件,<a>還有nowarp屬性,指定是否允許超鏈接自動換行

    n         <b>:使包含的文本變粗體

    n         <br>:強(qiáng)制換行

    n         <span>:使包含的文本具有特定的顏色(color屬性)和字體(font屬性)這些屬性的值也是一個key值,和FormTextsetColor()setFont()方法中key參數(shù)指定的值是對應(yīng)的

    l         下面是一個解析XML標(biāo)記的例子:

                  StringBuffer buf = new StringBuffer();
                  buf.append("<form>");
                  buf.append("<p>");
                  buf.append("Here is some plain text for the text to render; ");
                  buf.append("this text is at <a href=\"http://www.eclipse.org\" nowrap=\"true\">http://www.eclipse.org</a> web site.");
                  buf.append("</p>");
                  buf.append("<p>");
                  buf.append("<span color=\"header\" font=\"header\">This text is in header font and color.</span>");
                  buf.append("</p>");
                  buf.append("<p>This line will contain some <b>bold</b> and some <span font=\"text\">source</span> text. ");
                  buf.append("We can also add <img href=\"image\"/> an image. ");
                  buf.append("</p>");
                  buf.append("<li>A default (bulleted) list item.</li>");
                  buf.append("<li>Another bullet list item.</li>");
                  buf.append("<li style=\"text\" value=\"1.\">A list item with text.</li>");
                  buf.append("<li style=\"text\" value=\"2.\">Another list item with text</li>");
                  buf.append("<li style=\"image\" value=\"image\">List item with an image bullet</li>");
                  buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"3.\">A list item with text.</li>");
                  buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"4.\">A list item with text.</li>");
                  buf.append("</form>");
                  FormText rtext = toolkit.createFormText(body, true);
                  td = new TableWrapData(TableWrapData.FILL);
                  td.colspan = 2;
                  rtext.setLayoutData(td);
                  rtext.setImage("image", FormSamplesPlugin.imageDescriptorFromPlugin("FormSamples","images/aspect.gif").createImage());
                  rtext.setColor("header", toolkit.getColors().getColor(FormColors.TITLE));
                  rtext.setFont("header", JFaceResources.getHeaderFont());
                  rtext.setFont("text", JFaceResources.getTextFont());
                  rtext.setText(buf.toString(), true, false);
                  rtext.addHyperlinkListener(new HyperlinkAdapter() {
                    public void linkActivated(HyperlinkEvent e) {
                           System.out.println("Link active: "+e.getHref());
                    }
                  });

    l         下面是上面例子呈現(xiàn)的內(nèi)容

     o_1.JPG

    l         就像上面提到的FormTextXML標(biāo)記的支持是有限的,例如:

    n         標(biāo)記不能嵌套

    n         只支持粗體(<b>),而不支持斜體

    n         文本內(nèi)容不能被選取,等等

    l         所以對于FormText的一些限制,需要考慮其它的替代方法:

    n         如果需要具有更為復(fù)雜的格式化能力,可以使用Browser控件

    n         如果需要具有編輯和字體、顏色風(fēng)格的能力,可以使用StyleText控件

    n         如果需要文本能夠自動換行,可以使用具有SWT.WARP風(fēng)格的SWT Label控件

    posted on 2005-07-04 18:37 nelson_tu 閱讀(2575) 評論(2)  編輯  收藏 所屬分類: Eclipse開發(fā)

    Feedback

    # re: Eclipse Form程序設(shè)計指南(4)[未登錄] 2008-03-22 18:42 新手
    有沒有master/details模式的呀?  回復(fù)  更多評論
      

    # re: Eclipse Form程序設(shè)計指南(4)[未登錄] 2008-03-24 15:57 新手
    FormPage里有兩個Master又怎么樣呢  回復(fù)  更多評論
      

    主站蜘蛛池模板: 日本亚洲色大成网站www久久| 丰满亚洲大尺度无码无码专线| 亚洲一区二区三区免费视频| 中国一级特黄的片子免费 | 最近中文字幕免费mv视频7| 99热在线精品免费播放6| 国产成人精品无码免费看| 丁香花在线视频观看免费| 东方aⅴ免费观看久久av| 国产成人AV片无码免费| 18成禁人视频免费网站| 免费观看无遮挡www的小视频| 成年网在线观看免费观看网址| 亚洲最新中文字幕| 亚洲不卡视频在线观看| 日本亚洲免费无线码| 亚洲国产精品99久久久久久| 亚洲成a人无码亚洲成av无码| 亚洲视频网站在线观看| 亚洲精品国产专区91在线| 亚洲一区电影在线观看| 亚洲中文字幕无码mv| 美女被羞羞网站免费下载| 免费一级毛片在线播放放视频 | 午夜亚洲福利在线老司机| 国产免费人成在线视频| 国产性爱在线观看亚洲黄色一级片 | 久久精品九九亚洲精品| 亚洲图片校园春色| 亚洲一线产品二线产品| 青青草国产免费国产是公开| 搡女人免费免费视频观看| 8x8x华人永久免费视频| 卡一卡二卡三在线入口免费| 亚洲一区二区高清| 91天堂素人精品系列全集亚洲| 亚洲韩国精品无码一区二区三区| 四虎免费久久影院| 精品亚洲一区二区三区在线观看| 国产一区二区三区无码免费| 亚洲人精品午夜射精日韩 |