processtask.java

来自「替换jsp中的中文为sturts中的bundle」· Java 代码 · 共 79 行

JAVA
79
字号
package com.pengjj.app;


import org.eclipse.swt.widgets.Display;

public class ProcessTask {
	private GetAllFileToResource replace;
	private ReplaceByInputWindow inputWindow;
	private String text;
	private String sFinish;
	public ProcessTask(GetAllFileToResource getAllFile){
		this.replace = getAllFile;
	}
	public ProcessTask(ReplaceByInputWindow inputWindow){
		this.inputWindow = inputWindow;
	}
	/**
     * 开始执行
     */
    public void start() {
		// 一但发现执行状态为停止,则退出此循环
    	while(sFinish==null||!sFinish.equals("end")){
			// 每隔0.1秒一次循环,用于模拟表示一个需时较长的任务
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			getText();
			getFinish();
			setText(text);
		}
	}
    /**
     * 设置进度信息
     */
    private void setText(final String str) {
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
            	if(replace!=null){
                	replace.setText(str);
            	} else if(inputWindow!=null){
            		inputWindow.setText(str);
            	}
            }
        });
    }
    /**
     * 得到正在操作的文件
     */
    private void getText() {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				if (replace != null) {
					text = replace.getResourceProcess();
				} else if (inputWindow != null) {
					text = inputWindow.getResourceProcess();
				}
			}
		});
	}
    /**
	 * 是否已经全部完成
	 * 
	 */
    private void getFinish() {
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
            	if (replace != null) {
            		sFinish=replace.getFinish();
				} else if (inputWindow != null) {
					sFinish=inputWindow.getFinish();
				}
            	
            }
        });
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?