📄 loopimagedialog.java
字号:
package cn.com.chengang.jface.dialog.loopprogressdialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import cn.com.chengang.swt.SWTUtils;
public class LoopImageDialog {
private Shell parentShell;
public BooleanFlag stopFlag = new BooleanFlag();
protected LoopImageDialog(Shell parentShell) {
this.parentShell = parentShell;
}
public void run(boolean cancelable, final IProgressDialogRunnable runnable) {
new Thread() {
public void run() {
runnable.run(stopFlag);
}
}.start();
showDialog();
}
private void showDialog() {
final Display display = Display.getDefault();
Shell shell = new Shell(parentShell);
shell.setSize(250, 180);
SWTUtils.setCenter(shell); // 使用shell居中
shell.setLayout(new FillLayout());
// 在Shell窗口显示一个动画GIF
final ImageLoader imageLoader = new ImageLoader();
imageLoader.load("icons/animation2.gif");
new AnimationGIF(shell, SWT.BORDER, imageLoader);
// 弹出窗口。Shell和Dialog不同,它在open弹出界面之后会继承执行下面的语句
shell.open();
while (!shell.isDisposed()) {
if (stopFlag.getFlag())
shell.dispose();
if (!display.readAndDispatch())
display.sleep();
}
stopFlag.setFlag(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -