1 11 12 package org.eclipse.ui.internal; 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.swt.SWTException; 16 import org.eclipse.swt.graphics.Color; 17 import org.eclipse.swt.graphics.GC; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.graphics.ImageData; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.ui.internal.misc.StatusUtil; 23 import org.eclipse.ui.statushandlers.StatusManager; 24 25 31 public abstract class ImageCycleFeedbackBase extends AnimationFeedbackBase { 32 protected Image[] images; 33 protected Image stoppedImage; 34 private Image offScreenImage; 35 private GC offScreenImageGC; 36 private int imageDataIndex; 37 private Image image; 38 private ImageData imageData; 39 protected Display display; 40 protected Color background; 41 42 45 public ImageCycleFeedbackBase(Shell parentShell) { 46 super(parentShell); 47 } 49 50 56 public ImageCycleFeedbackBase(Shell parentShell, Image[] images) { 57 super(parentShell); 58 this.images = images; 59 } 60 61 66 public abstract void showImage(Image image); 67 68 72 public abstract void saveStoppedImage(); 73 74 79 public abstract void setStoppedImage(Image image); 80 81 public void dispose() { 82 if (stoppedImage == null || stoppedImage.isDisposed()) 84 return; 85 setStoppedImage(stoppedImage); 86 87 if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) 88 offScreenImageGC.dispose(); 89 90 if (offScreenImage != null && !offScreenImage.isDisposed()) 91 offScreenImage.dispose(); 92 } 93 94 public boolean jobInit(AnimationEngine engine) { 95 return super.jobInit(engine); 96 } 97 98 public void renderStep(AnimationEngine engine) { 99 if (offScreenImage == null) { 101 offScreenImage = getOffscreenImage(); 102 } 103 104 try { 105 imageDataIndex = (imageDataIndex + 1) % images.length; 106 image = images[imageDataIndex]; 107 imageData = image.getImageData(); 108 109 offScreenImageGC.drawImage(image, 0, 0, imageData.width, 110 imageData.height, imageData.x, imageData.y, 111 imageData.width, imageData.height); 112 113 final Image finalImage = image; 114 115 display.syncExec(new Runnable () { 116 121 public void run() { 122 showImage(finalImage); 123 124 } 125 }); 126 127 131 if (images == null) 136 return; 137 } catch (SWTException ex) { 138 IStatus status = StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, 139 ex); 140 StatusManager.getManager().handle(status); 141 } 142 } 143 144 private Image getOffscreenImage() { 145 saveStoppedImage(); 146 imageDataIndex = 0; 147 image = images[imageDataIndex]; 148 imageData = image.getImageData(); 149 153 offScreenImage = new Image(display, imageData.width, imageData.height); 154 155 offScreenImageGC = new GC(offScreenImage); 156 offScreenImageGC.setBackground(background); 157 offScreenImageGC.fillRectangle(0, 0, imageData.width, imageData.height); 158 159 162 163 offScreenImageGC.drawImage(image, 0, 0, imageData.width, 164 imageData.height, imageData.x, imageData.y, imageData.width, 165 imageData.height); 166 167 return offScreenImage; 168 } 169 170 } 171 | Popular Tags |