1 11 12 package org.eclipse.ui.internal; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.jface.util.Geometry; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.events.PaintEvent; 21 import org.eclipse.swt.events.PaintListener; 22 import org.eclipse.swt.graphics.GC; 23 import org.eclipse.swt.graphics.Image; 24 import org.eclipse.swt.graphics.Rectangle; 25 import org.eclipse.swt.widgets.Canvas; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Display; 28 import org.eclipse.swt.widgets.Shell; 29 30 34 public class ImageAnimationFeedback extends DefaultAnimationFeedback { 35 private class ImageCanvas extends Canvas { 36 private Image image; 37 41 public ImageCanvas(Composite parent, int style, Image image) { 42 super(parent, style); 43 this.image = image; 44 45 addPaintListener(new PaintListener() { 46 public void paintControl(PaintEvent e) { 47 paintImage(e.gc); 48 } 49 }); 50 } 51 54 protected void paintImage(GC gc) { 55 gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, getBounds().width, getBounds().height); 56 } 57 58 61 public void dispose() { 62 super.dispose(); 63 image.dispose(); 64 } 65 } 66 67 private Display display; 68 private Shell theShell; 69 70 private List startRects = new ArrayList (); 71 private List endRects = new ArrayList (); 72 private List controls = new ArrayList (); 73 74 private Image backingStore; 75 76 81 public ImageAnimationFeedback() {} 82 83 86 public void initialize(Shell parentShell, Rectangle startRect, Rectangle endRect) { 87 display = parentShell.getDisplay(); 88 89 Rectangle psRect = parentShell.getBounds(); 90 theShell = new Shell(parentShell, SWT.NO_TRIM | SWT.ON_TOP); 91 theShell.setBounds(parentShell.getBounds()); 92 93 addStartRect(startRect); 94 addEndRect(endRect); 95 96 backingStore = new Image(theShell.getDisplay(), psRect); 98 GC gc = new GC(display); 99 gc.copyArea(backingStore, psRect.x, psRect.y); 100 gc.dispose(); 101 102 theShell.setBackgroundImage(backingStore); 103 theShell.setVisible(true); 104 display.update(); 105 } 106 107 public void addStartRect(Rectangle rect) { 108 if (rect != null) { 109 Rectangle start = Geometry.toControl(theShell, rect); 110 startRects.add(start); 111 112 Image image = new Image(display, rect.width, rect.height); 113 GC gc = new GC(display); 114 gc.copyArea(image, rect.x, rect.y); 115 gc.dispose(); 116 117 ImageCanvas canvas = new ImageCanvas(theShell, SWT.BORDER | SWT.NO_BACKGROUND, image); 118 controls.add(canvas); 119 } 120 } 121 122 public void addEndRect(Rectangle rect) { 123 if (rect != null) { 124 Rectangle end = Geometry.toControl(theShell, rect); 125 endRects.add(end); 126 } 127 } 128 129 public void renderStep(double amount) { 130 Iterator startIter = startRects.iterator(); 132 Iterator endIter = endRects.iterator(); 133 Iterator ctrlIter = controls.iterator(); 134 while (startIter.hasNext()) { 135 Rectangle start = (Rectangle) startIter.next(); 136 Rectangle end = (Rectangle) endIter.next(); 137 ImageCanvas canvas = (ImageCanvas) ctrlIter.next(); 138 139 Rectangle curRect = RectangleAnimation.interpolate(start, end, amount); 141 canvas.setBounds(curRect); 142 } 143 144 display.update(); 145 } 146 147 public void jobInit() { 148 } 149 150 153 public void dispose() { 154 backingStore.dispose(); 155 for (Iterator ctrlIter = controls.iterator(); ctrlIter.hasNext();) { 156 ImageCanvas canvas = (ImageCanvas) ctrlIter.next(); 157 canvas.dispose(); 158 } 159 160 theShell.setVisible(false); 161 theShell.dispose(); 162 } 163 } 164 | Popular Tags |