Eclipse rcp 实现文本内容对比功能

  • B7_647511
    了解作者
  • 78.9KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-04 00:50
    上传日期
Eclipse rcp 实现文本内容对比功能,可自己选取对比的文件进行比较
com.jtang.compare.rar
内容介绍
package com.jtang.compare.dialog; import org.eclipse.draw2d.ColorConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * 文件比较对话框 * @author lww * */ public class FileCompareDialog extends Dialog{ public Text leftText; public Text rightText; public Text filterText; public String leftFile; public String rightFile; public FileCompareDialog(Shell parentShell) { super(parentShell); // TODO Auto-generated constructor stub } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); // 设置对话框的title newShell.setText("选择文件"); } @Override protected Control createDialogArea(Composite parent){ Composite composite = new Composite(parent, SWT.FILL); GridLayout layout = new GridLayout(); layout.verticalSpacing = 10; layout.horizontalSpacing = 10; layout.numColumns = 3; Group group=new Group(composite,SWT.NONE); group.setText("要对比的文件"); //设置分组框说明信息 group.setForeground(ColorConstants.blue); group.setLayout(layout); group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); Label leftLabel = new Label(group, SWT.NONE); leftLabel.setText("左侧(L):"); leftLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); leftText = new Text(group, SWT.BORDER); leftText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button leftButton = new Button(group, SWT.NONE); leftButton.setText("浏览(B).."); leftButton.addSelectionListener(left); Label rightLabel = new Label(group, SWT.NONE); rightLabel.setText("右侧(R):"); rightLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); rightText = new Text(group, SWT.BORDER); rightText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button rightButton = new Button(group, SWT.NONE); rightButton.setText("浏览(W).."); rightButton.addSelectionListener(right); Label filterLabel = new Label(group, SWT.NONE); filterLabel.setText("过滤器(F):"); filterLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); filterText = new Text(group, SWT.BORDER); filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout comLayout = new GridLayout(); comLayout.marginLeft = 30; comLayout.marginRight =30; comLayout.numColumns = 1; composite.setLayout(comLayout);//设置容器组件与容器边缘的水平距离 composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false)); composite.setFont(parent.getFont()); return composite; } public SelectionListener left = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog fd = new FileDialog(PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getShell(), SWT.OPEN); fd.setText("选择左边文件"); if(!filterText.getText().equals("")){ String[] filterExt = filterText.getText().split(";"); fd.setFilterExtensions(filterExt); } String leftLabel = fd.open(); if(leftLabel != null){ leftText.setText(leftLabel); leftFile = leftLabel; } else{ leftText.setText(""); leftFile = ""; } } }; public SelectionListener right = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { //选择左边的文件 FileDialog fd = new FileDialog(PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getShell(), SWT.OPEN); fd.setText("选择右边文件"); if(!filterText.getText().equals("")){ String[] filterExt = filterText.getText().split(";"); fd.setFilterExtensions(filterExt); } String rightLabel = fd.open(); if(rightLabel != null){ rightText.setText(rightLabel); rightFile = rightLabel; } else{ rightText.setText(""); rightFile = ""; } } }; /** * 重载按钮OK事件 */ @Override protected void okPressed() { if(!rightFile.equals("") && !leftFile.equals("")){ super.okPressed(); }else{ MessageDialog.openWarning(getShell(), "提示", "查看比较文件是否配置好!"); return; } } /** * 设置对话框初始大小 */ protected Point getInitialSize() { return new Point(500, 300); } public String getLeftFile() { return leftFile; } public String getRightFile() { return rightFile; } }
评论
    相关推荐
    • Eclipse
      Eclipse
    • Eclipse汉化
      此为Eclipse汉化,内有两个汉化文件和汉化方法-------
    • Eclipse
      Eclipse+SQL學習
    • eclipse安装包
      eclipse.rar 亲测有效!!!亲测有效!!!亲测有效!!!
    • eclipse
      jshint-eclipse-0.9.8.20130728都可以下载
    • eclipse bpel
      eclipse bpel hello world 案例是用eclipse bepl 实现hello+你输入的字符串的功能 环境eclipse bpel designer ode 也可以直接发布到ode中,在IE中测试 如果是初学 还有一个引用外部服务的例子
    • Eclipse快捷键
      Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-方便查找 Eclipse快捷键-...
    • eclipse资料
      包含:Eclipse RCP入门.pdf;eclipse.pdf;Eclipse插件开发指南.doc;Eclipse平台培训.ppt;RCP程序设计.pdf;一个简单的RCP入门教程.pdf
    • eclipse
      讲述eclipse关联关联架包
    • Eclipse皮肤
      [workspace]/.metadata.plugins/org.eclipse.core.runtime.settings/org.eclipse.jdt.ui.prefs [workspace]/.metadata.plugins/org.eclipse.core.runtime.settings/org.eclipse.ui.editors.prefs