http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DisplayananimatedGIF.htm描述了如何在 SWT 中显示动画 GIF - 一般。虽然代码有效且易于理解,但使用该技术在 SWT/JFace 表/树查看器单元格中显示动画 GIF 时遇到严重问题。-> 下面的所有代码
本质上,我实现了自己的 OwnerDrawLabelProvider,它在paint(Event, Object) 中创建了一个 ImageLoader 并启动了一个动画线程。问题似乎是这个动画线程不是UI 线程,我不知道在它的 run() 方法中使用哪个 GC 或 Display 实例。
我尝试在线程的构造函数中创建一个单独的 GC 实例 - 从 event.gc 派生 - 但是一旦我退出调试器,线程就无法写入该 GC ......
1 月 9 日星期六 22:11:57 192.168.1.6.local.home java[25387]:CGContextConcatCTM:无效上下文 0x0 2010-01-09 22:12:18.356 java[25387:17b03] 当 [NSGraphicsContext currentContext] 为 nil 时,绘制图像没有意义。这是一个编程错误。中断 _NSWarnForDrawingImageWithNoCurrentContext 进行调试。这将只记录一次。这可能会在未来打破。 1 月 9 日星期六 22:12:41 192.168.1.6.local.home java[25387]:CGContextConcatCTM:无效上下文 0x0
我需要如何处理这种情况?
以下是相关的代码部分:
/* 由绘画(事件,对象)调用。*/
私人无效paintAnimated(最终事件事件,最终ImageLoader imageLoader){
if (imageLoader == null || ArrayUtils.isEmpty(imageLoader.data)) {
返回;
}
最终线程 animateThread = new AnimationThread(event, imageLoader);
animateThread.setDaemon(true);
animateThread.start();
}
私有类 AnimationThread 扩展线程 {
私人展示展示;
私人 GC GC;
私有 ImageLoader imageLoader;
私人彩色背景;
public AnimationThread(final Event event, final ImageLoader imageLoader) {
超级(“动画”);
this.display = event.display;
/*
* 如果我们只是简单地引用 event.gc,它将在使用时被重置/清空
* 在运行()中。
*/
this.gc = new GC(event.gc.getDevice());
this.imageLoader = imageLoader;
this.background = getBackground(event.item, event.index);
}
@覆盖
公共无效运行(){
/*
* 创建一个要在其上绘制的离屏图像,并用外壳背景填充它。
*/
最终图像 offScreenImage =
新图像(this.display,this.imageLoader.logicalScreenWidth,
this.imageLoader.logicalScreenHeight);
最终 GC offScreenImageGC = new GC(offScreenImage);
offScreenImageGC.setBackground(this.background);
offScreenImageGC.fillRectangle(0, 0, this.imageLoader.logicalScreenWidth,
this.imageLoader.logicalScreenHeight);
图片 image = null;
尝试 {
/* 创建第一个图像并将其绘制在离屏图像上。*/
int imageDataIndex = 0;
ImageData imageData = this.imageLoader.data[imageDataIndex];
图像 = 新图像(this.display,imageData);
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x,
imageData.y, imageData.width, imageData.height);
/*
* 现在循环遍历图像,在之前的离屏图像上创建和绘制每个图像
* 在外壳上绘制它。
*/
int repeatCount = this.imageLoader.repeatCount;
而(this.imageLoader.repeatCount == 0 || repeatCount > 0){
开关(imageData.disposalMethod){
案例 SWT.DM_FILL_BACKGROUND:
/* 在绘制之前填充背景颜色。*/
offScreenImageGC.setBackground(this.background);
offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width,
图像数据.高度);
休息;
案例 SWT.DM_FILL_PREVIOUS:
// 恢复之前绘制之前的图像。
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,
imageData.x, imageData.y, imageData.width, imageData.height);
休息;
}
imageDataIndex = (imageDataIndex + 1) % this.imageLoader.data.length;
imageData = this.imageLoader.data[imageDataIndex];
image.dispose();
图像 = 新图像(this.display,imageData);
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x,
imageData.y, imageData.width, imageData.height);
// 绘制离屏图像。
this.gc.drawImage(offScreenImage, 0, 0);
/*
* 休眠指定的延迟时间(添加常用的减速软糖因素)。
*/
尝试 {
int ms = imageData.delayTime * 10;
如果(毫秒
我将同样的问题发布到 SWT 新闻组http://www.eclipse.org/forums/index.php?t=tree&th=160398