posts - 3,  comments - 5,  trackbacks - 0
  2007年12月18日
之前有同事问到IFile与File之间的互换问题,当时自己也不清楚,今天在阅读代码的时候发现了他们之间的互换是非常方便的。

IProject fsProject = ResourceModelUtils.getProject(project);
IFolder tmpFolder = ResourceUtils.getFolder(fsProject, RepositoryConstants.TEMP_DIRECTORY, true);
String tmpFilename = "DOC" + documentationItem.getProperty().getId();

IFile fileTmp = tmpFolder.getFile(tmpFilename);//Get IFile reference by file name;
File file = fileTmp.getLocation().toFile(); //Get File reference by IFile reference.
File newFile = new File(fileTmp.getLocation().toOSString()); //Convert IFile to File.

IFile的功能比File强大且方便多了。

爱生活,爱Eclipse!
posted @ 2007-12-18 14:24 jackgogogo(Dengues Studio) 阅读(305) | 评论 (1)编辑 收藏
  2007年10月30日

    工作中一个任务是为一个已经有的Composite添加滚动条,原以为可以这样实现:
    Composite scrollabledComposite = new Composite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
     再设置一下其它的参数就可以了,谁知这样是可以添加滚动条,但是滚动条里的Composite根本不会跟着动;于是,查API,发现有ScrolledComposite这个类,好家伙,这个类里的注释连main () 方法都提供了,正点!

于是,我的代码如下:

       parentComposite.setLayout(new FillLayout());
        ScrolledComposite scrolledComposite = new ScrolledComposite(parentComposite,  SWT.H_SCROLL|SWT.V_SCROLL);
       
        Composite mainComposite = new Composite(scrolledComposite,SWT.NONE);
        scrolledComposite.setContent(mainComposite);
        mainComposite.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WHITE));// White color
        mainComposite.setLayout(new GridLayout(1,true));
        GridData data = new GridData(GridData.FILL_BOTH);
        mainComposite.setLayoutData(data);
      

        Composite topComposite = new Composite(mainComposite, SWT.BORDER);
        topComposite.setLayout(new GridLayout(2, false));
        topComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));// White color

        reloadBtn = new Button(topComposite, SWT.PUSH);
        reloadBtn.setText("&Reload from preferences");
        reloadBtn.setToolTipText("Reload values from preference page(Shift+R)");

        saveBtn = new Button(topComposite, SWT.PUSH);
        saveBtn.setText("&Save to preferences");
        saveBtn.setToolTipText("save values to preference page(Shift+S)");
       
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
        scrolledComposite.setMinWidth(800);
        scrolledComposite.setMinHeight(400);


 总结:
 1)在为Composite添加滚动条时,最上面的Composite的布局需设为FillLayout();
 2) 不要直接往scrolledComposite上面添加控件;
 3) 在创建完ScrolledComposite后不要忘记使用setContent()方法去设置滚动条所控制的Composite;
 4) 最重要的是,Scrolledcomposite的以下四个参数必须设置才能出现滚动条:
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setMinWidth(800);
    scrolledComposite.setMinHeight(400);
    只有前两项设为true之后,后面的两项才起作用。
5) 对于setMinWidth()和setMinHeight()方法,API的注释中是说用来设置滚动条出现的最小宽度和高度,但是我试了一下,有时出现滚动条了,
    但是拖动滚动条还是不能显示Composite里面的全部内容,于是把setMinWidth()和setMinHeight()设大一些就可以了,个人感觉滚动条出现的
    宽度和高度检测Scrolledcomposite自己已经实现了,这里的宽度和高度是指拖动滚动条里可以看到的Composite的最大宽度和最大高度。

 

posted @ 2007-10-30 09:20 jackgogogo(Dengues Studio) 阅读(974) | 评论 (3)编辑 收藏
  2007年10月23日
可喜可贺,Dengues studio的BLOG正式开通了!http://dengues.blogjava.net.
posted @ 2007-10-23 18:08 jackgogogo(Dengues Studio) 阅读(113) | 评论 (1)编辑 收藏
仅列出标题