문제

http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DisplayananimatedGIF.htm 를 표시하는 방법에 대해 설명합니다 GIF 애니메이션에서 SWT-에서 일반적입니다.는 동안 코드를 작동하고 쉽게 이해할 수 있는 내가 직면한 심각한 문제를 표시하는 애니메이션에 GIF SWT/JFace 이블/트리 뷰어 휴와 함께하는 기술이다.->아래 모든 코드

기본적으로 구현했는 내 자신의 OwnerDrawLabelProvider 를 만들어하여 imageloader 에서 페인트(행사,Object)및 애니메이션을 시작합니다 thread.문제는 것 같이 애니메이션 스레드 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 

게시 동일한 문제를 SWT 뉴스 http://www.eclipse.org/forums/index.php?t=tree&th=160398

도움이 되었습니까?

해결책

후의 많은 시간 좌절하고 오류가 공동 작업자가 실현 가능한 솔루션입니다.내 초기 방식을 이 구현에서 완전히 자 LabelProvider 게 실패했습니다.

는 하나의 방법이 없었을 재정의 LabelProvider#업데이트()를 호출하 timerExec(100,새로운 Runnable(){...뷰어입니다.update()...에서는 방법입니다.생명""주의하 제어 사용이 너무 많은 CPU 사이클(10%맥북).

중 하나 동료의 아이디어를 구현하는 것이었 사용자 지정 TableEditor:레이블과 이미지(하나의 프레임에 애니메이션 GIF)지 텍스트입니다.각 TableEditor 인스턴스가 시작할 것이라 그것의 자신의 스레드에서 업데이트 레이의 이미지입니다.이 작품을 아주 잘하지만,거기에 별도의"애니메이션"스레드를 위해 각각의 애니메이션 아이콘이다.또한,이 성과 살인자,소비 25%CPU 내 MacBook.

최종 접근 방식은 세 가지 빌딩 블록

  • 는 OwnerDrawLabelProvider 는 페인트 중 하나는 정적인 이미지하거나의 프레임에 애니메이션 GIF
  • 애니메이션 스레드(속도 메이커),그것은 다시 그리기()위해 열을 포함하는 애니메이션 Gif 그것은 또한 업데이트()
  • 고 시청자의 콘텐츠 제공자를 제어하는 애니메이션이다.

상세정보에서 나 블로그 http://www.frightanic.com/2010/02/09/animated-gif-in-swt-tabletree-viewer-cell/.

다른 팁

LabelProvider가 다른 이미지를 반환 한 다음 애니메이션을 원하는 요소에서 Viewer.Update (...)를 호출하게 할 수 없습니다. display.timerexec을 사용하여 별도의 스레드가있는 대신 콜백을 얻을 수 있습니다.

내 대답을 참조하십시오 여기 색상을 바꿀 수있는 방법. 이미지와 비슷한 일을 할 수 있어야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top