<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      java swt 之 圖片控件

      swt好像加載動態gif也得需要自己讓圖片跑起來,找了很長時間找到一份源碼,改了改,讓它更原本一點。

       

      使用的話,注意gif幀速的變量,可以自己多調試調試,gif在不同的平臺上速度是不一樣的,就像那個跑瘋了的手機測試gif一樣。

       

       

      package atomQQswt.ui.core;

      import java.io.InputStream;

      import org.eclipse.swt.SWT;
      import org.eclipse.swt.graphics.Color;
      import org.eclipse.swt.graphics.GC;
      import org.eclipse.swt.graphics.Image;
      import org.eclipse.swt.graphics.ImageData;
      import org.eclipse.swt.graphics.ImageLoader;
      import org.eclipse.swt.graphics.Point;
      import org.eclipse.swt.graphics.Rectangle;
      import org.eclipse.swt.widgets.Canvas;
      import org.eclipse.swt.widgets.Composite;
      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Event;
      import org.eclipse.swt.widgets.Listener;

      public class ImageCanvas extends Canvas {
          
          
      private ImageLoader loader;

          
      protected Point origin = new Point(00);
          
      protected Image image;
          
      protected ImageData[] imageDatas;
          
      protected Image[] images;
          
      protected int current;

          
      private int repeatCount;
          
      private Runnable animationTimer;
       
          
      private Color bg;
          
      private Display display;

          
      public ImageCanvas(Composite parent) {
              
      super(parent, SWT.DOUBLE_BUFFERED | SWT.INHERIT_FORCE |SWT.INHERIT_DEFAULT);

            
              bg 
      = getBackground();
              display 
      = getDisplay();
              addListeners();
          }
          
          
      /**
           * 傳入路徑獲取圖片.
           *
           * 
      @param path the new image
           
      */
          
      public void setImage(String path){
               loader 
      = new ImageLoader();
               imageDatas 
      = loader.load(path);
               
      if(imageDatas.length == 0)
                   
      return;
               
      else if(imageDatas.length == 1){
                   checkWidget();

                   stopAnimationTimer();
                   
      this.image = new Image(display, imageDatas[0]);
                   
      this.imageDatas = null;
                   
      this.images = null;
                   redraw();
               }
      else {
                   checkWidget();

                   
      this.image = null;
                   
      this.repeatCount = loader.repeatCount;
                   convertImageDatasToImages();
                   startAnimationTimer();
                   redraw();
                   
               }
          }
          
          
      /**
           * 傳入InputStream獲取圖片.
           *
           * 
      @param isin the new image
           
      */
          
      public void setImage(InputStream isin){
               loader 
      = new ImageLoader();
               imageDatas 
      = loader.load(isin);
               
      if(imageDatas.length == 0)
                   
      return;
               
      else if(imageDatas.length == 1){
                   checkWidget();

                   stopAnimationTimer();
                   
      this.image = new Image(display, imageDatas[0]);
                   
      this.imageDatas = null;
                   
      this.images = null;
                   redraw();
               }
      else {
                   checkWidget();

                   
      this.image = null;
                   
      this.repeatCount = loader.repeatCount;
                   convertImageDatasToImages();
                   startAnimationTimer();
                   redraw();
                   
               }
              
          }

          

          @Override
          
      public Point computeSize(int wHint, int hHint, boolean changed) {
              checkWidget();

              Image image 
      = getCurrentImage();
              
      if (image != null) {
                  Rectangle rect 
      = image.getBounds();
                  Rectangle trim 
      = computeTrim(00, rect.width, rect.height);
                  
      return new Point(trim.width, trim.height);
              }

              
      return new Point(wHint, hHint);
          }

          @Override
          
      public void dispose() {
              
      if (image != null)
                  image.dispose();

              
      if (images != null)
                  
      for (int i = 0; i < images.length; i++)
                      images[i].dispose();

              
      super.dispose();
          }

          
      protected void paint(Event e) {
              Image image 
      = getCurrentImage();
              
      if (image == null)
                  
      return;

              GC gc 
      = e.gc;
              gc.drawImage(image, origin.x, origin.y);

              gc.setBackground(bg);
              Rectangle rect 
      = image.getBounds();
              Rectangle client 
      = getClientArea();
              
      int marginWidth = client.width - rect.width;
              
      if (marginWidth > 0) {
                  gc.fillRectangle(rect.width, 
      0, marginWidth, client.height);
              }
              
      int marginHeight = client.height - rect.height;
              
      if (marginHeight > 0) {
                  gc.fillRectangle(
      0, rect.height, client.width, marginHeight);
              }
              
              
             
          }

          
      void addListeners() {
              addListener(SWT.Paint, 
      new Listener() {
                  
      public void handleEvent(Event e) {
                      paint(e);
                  }
              });
          }

        

          
      void convertImageDatasToImages() {
              images 
      = new Image[imageDatas.length];

              
      // Step 1: Determine the size of the resulting images.
              int width = imageDatas[0].width;
              
      int height = imageDatas[0].height;

              
      // Step 2: Construct each image.
              int transition = SWT.DM_FILL_BACKGROUND;
              
      for (int i = 0; i < imageDatas.length; i++) {
                  ImageData id 
      = imageDatas[i];
                  images[i] 
      = new Image(display, width, height);
                  GC gc 
      = new GC(images[i]);

                  
      // Do the transition from the previous image.
                  switch (transition) {
                  
      case SWT.DM_FILL_NONE:
                  
      case SWT.DM_UNSPECIFIED:
                      
      // Start from last image.
                      gc.drawImage(images[i - 1], 00);
                      
      break;
                  
      case SWT.DM_FILL_PREVIOUS:
                      
      // Start from second last image.
                      gc.drawImage(images[i - 2], 00);
                      
      break;
                  
      default:
                      
      // DM_FILL_BACKGROUND or anything else,
                      
      // just fill with default background.
                      gc.setBackground(bg);
                      gc.fillRectangle(
      00, width, height);
                      
      break;
                  }

                  
      // Draw the current image and clean up.
                  Image img = new Image(display, id);
                  gc.drawImage(img, 
      00, id.width, id.height, id.x, id.y, id.width,
                          id.height);
                  img.dispose();
                  gc.dispose();

                  
      // Compute the next transition.
                  
      // Special case: Can't do DM_FILL_PREVIOUS on the
                  
      // second image since there is no "second last"
                  
      // image to use.
                  transition = id.disposalMethod;
                  
      if (i == 0 && transition == SWT.DM_FILL_PREVIOUS)
                      transition 
      = SWT.DM_FILL_NONE;
              }
          }

          Image getCurrentImage() {
              
      if (image != null)
                  
      return image;

              
      if (images == null)
                  
      return null;

              
      return images[current];
          }

          
      void startAnimationTimer() {
              
      if (images == null || images.length < 2)
                  
      return;

              
      int delay = imageDatas[current].delayTime*20;
              
      if (delay <5) delay = 100;
             
              
      final int ms=delay;
              display.timerExec(ms, animationTimer 
      = new Runnable() {
                  
      public void run() {
                      
      if (isDisposed())
                          
      return;

                      current 
      = (current + 1% images.length;
                      redraw();

                      
      if (current + 1 == images.length && repeatCount != 0
                              
      && --repeatCount <= 0)
                          
      return;
                      display.timerExec(ms, 
      this);
                  }
              });
          }

          
      void stopAnimationTimer() {
              
      if (animationTimer != null)
                  display.timerExec(
      -1, animationTimer);
          }
      }

       

      posted on 2011-05-04 23:18  黑暗伯爵  閱讀(4657)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 精品亚洲无人区一区二区| 18禁精品一区二区三区| 国产成人亚洲精品狼色在线| 99在线 | 亚洲| 国产AV大陆精品一区二区三区| 国产尤物精品自在拍视频首页| 黑人玩弄人妻中文在线| 国产愉拍精品手机| 汉阴县| 蜜臀在线播放一区在线播放| 人妻少妇偷人作爱av| 快好爽射给我视频| 中文人妻AV高清一区二区| 成人啪啪高潮不断观看| 4hu44四虎www在线影院麻豆| 亚洲国产精品综合久久网络| 潮喷无码正在播放| 久久道精品一区二区三区| 制服jk白丝h无内视频网站| 国内不卡一区二区三区| 狠狠综合久久综合88亚洲爱文| 日韩丝袜欧美人妻制服| 久久99亚洲网美利坚合众国| 黄又色又污又爽又高潮| 亚洲色成人一区二区三区| 精品国产粉嫩内射白浆内射双马尾| 国产一区二区视频在线看| 天天爽夜夜爱| 在线观看国产精品日韩av | 国产精品午夜福利在线观看| 亚洲av与日韩av在线| 呻吟国产av久久一区二区| 亚洲欧美人成电影在线观看| 亚洲无人区一码二码三码| 亚洲最大成人在线播放| 97色伦97色伦国产| 理论片午午伦夜理片久久| 日韩中文字幕av有码| 在线观看无码av五月花| 国产白袜脚足j棉袜在线观看| 精品亚洲国产成人av|