アニメーションGIFにSWTテーブル/ツリービューア細胞
質問
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DisplayananimatedGIF.htm について説明してい表示アニメーションGIFにSWT-。ながら、コードの作品が簡単にわかりやすくい面の深刻な問題を表示しているアニメーションGIFにSWT/JFaceテーブル/ツリービューア細胞とのこと。->すべての以下のコードを
基本的に、実施自分のOwnerDrawLabelProviderしImageLoader塗料(イベントオブジェクト)開始のアニメーション。この問題のようだがこのアニメーションはスレッドが ない UIのスレッドにないわからないGC表示インスタンスを使用し、そのrun()メソッドがあります。
私の作成を別途GCインスタンスは、スレッドのコンストラクタ-からのイベントです。gc-そのスレッドに失敗した文書によりそのGCによってすぐに、デバッガ...
Sat Jan 9 22:11:57 192.168.1.6.local.home java[25387] : CGContextConcatCTM: invalid context 0x0 2010-01-09 22:12:18.356 java[25387:17b03] It does not make sense to draw an image when [NSGraphicsContext currentContext] is nil. This is a programming error. Break on _NSWarnForDrawingImageWithNoCurrentContext to debug. This will be logged only once. This may break in the future. Sat Jan 9 22:12:41 192.168.1.6.local.home java[25387] : CGContextConcatCTM: invalid context 0x0
どうかこの答えください。
以下に該当部分:
/* Called by paint(Event, Object). */ private void paintAnimated(final Event event, final ImageLoader imageLoader) { if (imageLoader == null || ArrayUtils.isEmpty(imageLoader.data)) { return; } final Thread animateThread = new AnimationThread(event, imageLoader); animateThread.setDaemon(true); animateThread.start(); } private class AnimationThread extends Thread { private Display display; private GC gc; private ImageLoader imageLoader; private Color background; public AnimationThread(final Event event, final ImageLoader imageLoader) { super("Animation"); this.display = event.display; /* * If we were to simply reference event.gc it would be reset/empty by the time it's being used * in run(). */ this.gc = new GC(event.gc.getDevice()); this.imageLoader = imageLoader; this.background = getBackground(event.item, event.index); } @Override public void run() { /* * Create an off-screen image to draw on, and fill it with the shell background. */ final Image offScreenImage = new Image(this.display, this.imageLoader.logicalScreenWidth, this.imageLoader.logicalScreenHeight); final GC offScreenImageGC = new GC(offScreenImage); offScreenImageGC.setBackground(this.background); offScreenImageGC.fillRectangle(0, 0, this.imageLoader.logicalScreenWidth, this.imageLoader.logicalScreenHeight); Image image = null; try { /* Create the first image and draw it on the off-screen image. */ int imageDataIndex = 0; ImageData imageData = this.imageLoader.data[imageDataIndex]; image = new Image(this.display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* * Now loop through the images, creating and drawing each one on the off-screen image before * drawing it on the shell. */ int repeatCount = this.imageLoader.repeatCount; while (this.imageLoader.repeatCount == 0 || repeatCount > 0) { switch (imageData.disposalMethod) { case SWT.DM_FILL_BACKGROUND: /* Fill with the background color before drawing. */ offScreenImageGC.setBackground(this.background); offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); break; case SWT.DM_FILL_PREVIOUS: // Restore the previous image before drawing. offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); break; } imageDataIndex = (imageDataIndex + 1) % this.imageLoader.data.length; imageData = this.imageLoader.data[imageDataIndex]; image.dispose(); image = new Image(this.display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); // Draw the off-screen image. this.gc.drawImage(offScreenImage, 0, 0); /* * Sleeps for the specified delay time (adding commonly-used slow-down fudge factors). */ try { int ms = imageData.delayTime * 10; if (ms
掲載し、同じ問題にォニュースグループ http://www.eclipse.org/forums/index.php?t=tree&th=160398
解決
後に多くの時間も試行錯誤をしたり、同僚た実現可能な解決策です。私が最初に考て実施され、完全に自LabelProvider失敗を誇.
その際の一つのアプローチが動作しなかったためにオーバーライドLabelProvider#update()を呼timerExec(100,新Runnable(){...ージをリニューアルしました。update()...からその方法。"Life"のリサイクルを管理利用しても多くのCPUサイクル(10%私のMacBook).
の同僚のアイデアをカスタムTableEditor:ラベルのイメージです(一つのフレームのアニメーションGIF)です。各TableEditorインスタンスが独自のスレッドが新たにラベルのイメージです。この作品のものがあるのに、別の"アニメーション"のスレッド毎にアニメのアイコンで表します。また、このキラー性能と消費の25%のCPUは、私のMacBook.
最終的にはブロックビル
- るOwnerDrawLabelProviderる塗料は静的な画像のフレームのアニメーションGIF
- アニメーションのスレッドのペースメーカーで通話を再描画の列を含むアニメーションGif、またはupdate()
- そのコンテンツプロバイダを制御するアニメーション。
詳細は私のこのブログ http://www.frightanic.com/2010/02/09/animated-gif-in-swt-tabletree-viewer-cell/.
他のヒント
あなたはLabelProviderが異なる画像を返させ、その後、あなたがアニメーション化する要素にviewer.update(...)を呼び出すことはできません。あなたが別のスレッドを持つのではなく、コールバックを取得するためにDisplay.timerExecを使用することができます。
あなたは色を変更する方法はこちらの私の答えはを参照してください。あなたは、画像と類似した何かを行うことができるはずます。