- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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
我该如何处理这种情况?
以下是相关的代码部分:
/ *由paint(Event,Object)调用。 * /
private void paintAnimated(最终事件事件,最终ImageLoader imageLoader){
如果(imageLoader == null || ArrayUtils.isEmpty(imageLoader.data)){
返回;
}
最终线程animateThread = new AnimationThread(event,imageLoader);
animateThread.setDaemon(true);
animateThread.start();
}
私有类AnimationThread扩展了Thread {
私人展示架;
私人GC gc;
私有ImageLoader imageLoader;
私人色彩背景;
public AnimationThread(最终事件事件,最终ImageLoader imageLoader){
super(“ Animation”);
this.display = event.display;
/ *
*如果我们只是引用event.gc,它将在使用时重置/为空
*在run()中。
* /
this.gc =新的GC(event.gc.getDevice());
this.imageLoader = imageLoader;
this.background = getBackground(event.item,event.index);
}
@Override
公共无效run(){
/ *
*创建一个要绘制的屏幕外图像,并用外壳背景填充它。
* /
最终图片offScreenImage =
新图片(this.display,this.imageLoader.logicalScreenWidth,
this.imageLoader.logicalScreenHeight);
最终GC offScreenImageGC =新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;
while(this.imageLoader.repeatCount == 0 || repeatCount> 0){
开关(imageData.disposalMethod){
情况SWT.DM_FILL_BACKGROUND:
/ *在绘制之前填充背景色。 * /
offScreenImageGC.setBackground(this.background);
offScreenImageGC.fillRectangle(imageData.x,imageData.y,imageData.width,
imageData.height);
打破;
情况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);
/ *
*睡眠指定的延迟时间(添加常用的减速软糖因素)。
* /
尝试{
整数毫秒= imageData.delayTime * 10;
如果(毫秒
我将相同的问题发布到SWT新闻组http://www.eclipse.org/forums/index.php?t=tree&th=160398
最佳答案
经过数小时的反复试验,一个同事提出了一个可行的解决方案。我最初在完全独立的LabelProvider中实现此目标的方法失败了。
一种无效的方法是重写LabelProvider#update()并从该方法中调用timerExec(100,new Runnable(){... viewer.update()...)。很难控制,它使用了太多的CPU周期(在我的MacBook上为10%)。
同事的想法之一是实现一个自定义的TableEditor:一个带有图像的标签(动画GIF的一帧),但没有文本。每个TableEditor实例将启动其自己的线程,在其中更新标签的图像。效果很好,但是每个动画图标都有一个单独的“动画”线程。另外,这是性能的杀手,在MacBook上消耗了25%的CPU。
最终方法有三个构建基块
一个OwnerDrawLabelProvider,它绘制静态图像或动画GIF的帧
一个动画线程(起搏器),它为包含动画GIF的列调用redraw(),并且还调用update()
以及控制动画线程的查看者内容提供商。
我的博客http://www.frightanic.com/2010/02/09/animated-gif-in-swt-tabletree-viewer-cell/中的详细信息。
关于eclipse - SWT表/树查看器单元中的GIF动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2037353/
我实际上是在尝试在 Java SWT 中重现类似的东西,但到目前为止还没有成功: 我看到的问题是,据我所知,SWT.TITLE 需要显示 SWT.CLOSE、SWT.MAX 和 SWT.MIN 谁能告
以下是我的代码: Group leftGroup = new Group(parent, SWT.NONE); leftListWidget = new org.eclipse.swt.widgets
我正在尝试运行一个 hello world SWT 应用程序: public static void main(String args[]) throws IOException{ Displ
我有一个 SWT 窗口,其中有组小部件,我在其中放置了几个其他小部件,我设置了组的标题及其工作正常。组标题颜色始终为蓝色(在我的情况下我不确定)并且不会与组内的其他 child 同步。所以我想知道是否
我正在使用 SWT CTabFolder 在我的应用程序中构建选项卡。我有点不喜欢标签的视觉外观,它太像 Eclipse。有没有办法改变标签的方面?我想更改关闭按钮,例如标签的位置,它们的外观可能..
对于我在使用大型 SWT 表的 RCP 应用程序中追逐了一段时间的问题,这更多是我想分享的答案。 问题是 SWT Table.remove(int start, int end) 方法的性能。它提供了
如何在不使用鼠标监听器的情况下编辑 SWT 表值? 最佳答案 做 TableEditor以下链接中的片段有帮助吗? SWT Snippets TableEditor中的第一个例子部分使用 Select
我想要一个带有两行工具提示的控件。例如 Label: Label label = new Label( parent, SWT.NONE ); label.setText( "label text"
A 想在我的 View 上加载下拉菜单时添加默认文本。我怎样才能在 SWT 和 JFace 中做到这一点? 最佳答案 我猜您想要做的是在将某些内容添加到 View 时在组合中显示某些内容(默认情况下它
在我的登录对话框中,有一个按钮: Text pwdT = new Text(container, SWT.BORDER|SWT.PASSWORD); Button plainBtn = new Bu
如何以编程方式垂直滚动 SWT 表? 在表上实现搜索功能。当找到一个项目时,它将滚动到找到的项目。 最佳答案 您可能想尝试几种方法: Table.showItem(TableItem) Table.s
我有一个 Composite我希望能够以编程方式启用/禁用。 Control.setEnabled(boolean enabled)方法工作正常,但它没有提供任何小部件被禁用的视觉信息。 我想做的是让
有几个“高级”表格/电子表格 SWT 小部件(Nattable、Nebula Grid),但它们都不支持真正的大数据集。 Nattable 是最接近的一种,但它在使用的数据类型方面仍然存在限制,导致表
以下问题让我感到困惑:我有一个 SWT Java 应用程序,并且在以下情况下从 SWT 3 切换到 SWT 4 会导致 KeyDown 事件出现奇怪的行为: 我有一个包含浏览器小部件的外壳。我正在通过
我在 eclipse SWT 应用程序中有许多表。它们是 Table/TableViewer 表格,由一个标题、左下方一行文本和一系列图形组成。除文本列外还有 32 列,编号从 0 到 31。在经典模
原目标: 我有一个 TreeMenu 用于显示我的菜单。 在这棵树中,用户可以选择不同的项目。 我想禁用树,以便用户在选择第一个项目后无法选择新项目。 问题是,我们不能使用 setEnabled,因为
是否已经有人在 IDEA 中编写了类似于“导航栏”的 SWT 控件?对于那些不知道我的意思的人:它看起来像 path1 > path2 > path3 > 其中每个“路径”都是模拟一个按钮的完整路径的
我需要使用 SWT/JFace 实现多选组合框,最好的方法是什么?我应该更改源代码还是应该尝试扩展组合? 最佳答案 不可能扩展 Combo 可以通过重写 checkSubclass() 来扩展 Com
我想用大量行(最多 3 mio)填充 SWT 虚拟表。当我使用懒惰的内容提供者时,我不能使用过滤器,而当我使用普通的内容提供者时,更改过滤器的性能会变得非常糟糕。有没有办法在 SWT 或 JFace
除了外观之外,组控制和复合之间有什么区别?我可以将容器放入组内吗?如果是,我必须使用什么布局?我尝试将容器放置在组内,但容器内的控件未显示。 Group grp= new Group(containe
我是一名优秀的程序员,十分优秀!