选择显示字体大小

eclipse forms设计漂亮ui之高级组件


  eclipse forms提供了4个高级组件,这样你能够构建漂亮的ui:expandable composite,section,image hyperlink和form text.让我们依次仔细看看它们每一个。

  expandable composite

  在网页中有个普遍的功能就是让你有能力把一部分网页内容用一个按钮来伸缩它,eclipse forms提供了这样一个组件:expandablecomposite。

 expandablecomposite ec = toolkit.createexpandablecomposite(form.getbody(),       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);   }  });
  这个composite接受一些风格参数来控制它的表现行为.treenode风格会用树组件中的按钮来伸展或收缩内容,twistie风格则会创建一个方行的按钮.使用expanded,则初始状态是伸展的.如果用compact风格,组件会报告和标题宽度相合适的宽度并且呈现收缩状态.最后,client_indent会使内容与标题对齐(否则,内容是按照组件的宽度).

  expandablecomposite有责任处理按钮组件和标题.能扩展和收缩的客户组件必须是expandablecomposite直接的child. 我们需要为组件添加伸展监听器并"通知(reflow)"form在状态改变时.这是因为伸展改变了expandable composite的大小,但是在parent下一次布局前对parent没有任何影响(因此需要强行告诉它).大体上,每次你使form的layout改变时,你需要"reflow"这个form."reflowing"这个form会让所有组件按照新的尺寸布局并更新滚动条.

  我们的视图现在看起来象这样:
 

图11:一个收缩状态的expandable composite例子

  当你点击标题的"+"时,composite伸展出并展示客户:



图12:expandable composite呈伸展状态

  expandable composite用到了一个内部layout,这个layout实现了eclipse forms ilayoutextension接口.因此你能够把它加到使用tablewraplayout布局的parent上,就象我们上面例子中做的一样.

  段落(section)

  eclipse forms定制的组件中最versatile之一就是section.它继承了expandable composite并介绍了以下的概念:

  1.分隔条(separator)-一个能够在标题下创建的separator组件.

  2.描述(description)-在标题下的可选的描述.

  3.标题栏(title bar)-能在标题下的一个标题栏(注意separator和标题栏不能同时使用)

  下面的代码和expandable composite代码例子差不多:
 section section = toolkit.createsection(form.getbody(),    section.descriptionsection.title_bar   section.twistiesection.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");  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);
  这次我们用了twistie风格,添加了描述并要求有标题栏.这个视图看起来应该象这样:
 

图13:一个有标题栏和描述的可伸展的section


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons