好多年不用rcp了,现在偶然用一下,发现高版本eclipse不支持jdk8,好吧用上2020-06版本整一个小程序回顾一下例程
按照向导新建了rcp4例程,右键找到rcp1.product文件运行,可以。
想着加些打印日志吧,很自然想到用log4j,但是加个库折腾了好久,最后摸索出方法:
双击plugin.xml在编辑器里选build 加库那里选libs文件夹,最后得到配置文件build.properties
source.. = src/
output.. = bin/
bin.includes = plugin.xml,
meta-INF/,
.,
icons/,
css/default.css,
Application.e4xmi,
libs
jars.compile.order = .,
org.apache.log4j_1.2.15.v201012070815.jar
jars.extra.classpath = libs/org.apache.log4j_1.2.15.v201012070815.jar
source.libs = src/
双击plugin.xml在编辑器里runtime那里的classpath里增加libs及这个库,就是说需要得到库的全路径,得不到的话手动修改配置文件manifest.mf
Bundle-ClassPath: .,
libs/org.apache.log4j_1.2.15.v201012070815.jar
后来又想到以前的splashscreen效果,发现图形化里的好像是支持rcp3的,就自己建个界面展示一张图片,继承一下线程,过一段时间自动消失就好了。下面是启动这个界面放到自己主界面初始化里:
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
//Display display = Display.getDefault();
RcpSplash spl = new RcpSplash(parent.getDisplay());
Thread th=new Thread(spl);
th.start();
但是很奇怪splash界面是黑色的没显示图片,折腾了很久发现是这个界面没激活,好吧,在初始化里增加一句激活即可
public class RcpSplash extends Shell implements Runnable{
private Integer iSleep=3000;//闪屏 时长
//public Label c;
public void fillbg(Composite obj ,InputStream c) {//parent.setBackgroundImage(new Image(parent.getDisplay(),this.getClass().getResourceAsStream("/icons/bg.png")));
final Image image=new Image(obj.getDisplay(),c);
final int imgWidth = image.getBounds().width;
final int imgHeight = image.getBounds().height;
obj.addPaintListener(new PaintListener() {
@Override //jdk1.8需要 1.7不要
public void paintControl(PaintEvent event) {
event.gc.drawImage(image, 0, 0, imgWidth, imgHeight, 0, 0, event.width, event.height);
}
});
}
public RcpSplash(Display display ) {
super(display, SWT.NO_TRIM |SWT.TOP);fillbg(this.getShell(),this.getClass().getResourceAsStream("/icons/splash.png"));
setSize(800, 600);
setCenter(this);
open();
setActive();
}
@Override
public void run() {
try {
Display.getDefault().syncExec(new Runnable() {
public void run() {
open();
//layout();
try {
Thread.sleep(iSleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
closesplash();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setCenter(Shell shl)
{
int width = shl.getMonitor().getClientArea().width;
int height = shl.getMonitor().getClientArea().height;
int x = shl.getSize().x;
int y = shl.getSize().y;
if(x > width)
{
shl.getSize().x = width;
}
if(y > height)
{
shl.getSize().y = height;
}
shl.setLocation((width - x) / 2, (height - y) / 2);
}
@Override
protected void checkSubclass () {
//这个空函数不可少 解除不被子类化
}
public Integer getiSleep() {
return iSleep;
}
public void setiSleep(Integer iSleep) {
this.iSleep = iSleep;
}
public void closesplash() {
this.dispose();
}
}



